'Why Widget SwiftUI doesn't after sending a request to the network?

After asynchronously sending a request to the network in the method:

getTimeline(in context: Context, completion: @escaping (Timeline<WidgetEntry>) -> Void)

Widget loads endlessly. Note that I am passing completion(timeline) in the body of the asynchronous request. Could this be causing the problem and how can it be resolved?

func getTimeline(in context: Context, completion: @escaping (Timeline<WidgetEntry>) -> Void) {
        let interactor = WidgetInteractor()
        interactor.request { result in
            var entries: [WidgetEntry] = []
            switch result {
            case .success(let someEntries):
                    entries += someEntries
                    let timeline = Timeline(entries: entries, policy: .atEnd)
                    completion(timeline)
            case .failure:
                    let timeline = Timeline(entries: entries, policy: .atEnd)
                    completion(timeline)
            }
        }
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source