@@ -917,28 +917,38 @@ class URLSession extends _ObjectHolder<ncb.NSURLSession> {
917
917
///
918
918
/// See [sessionWithConfiguration:delegate:delegateQueue:] (https://developer.apple.com/documentation/foundation/nsurlsession/1411597-sessionwithconfiguration)
919
919
factory URLSession .sessionWithConfiguration (URLSessionConfiguration config,
920
- {URLRequest ? Function (URLSession session, URLSessionTask task,
921
- HTTPURLResponse response, URLRequest newRequest)?
922
- onRedirect,
923
- URLSessionResponseDisposition Function (URLSession session,
924
- URLSessionTask task, URLResponse response)?
925
- onResponse,
926
- void Function (URLSession session, URLSessionTask task, Data error)?
927
- onData,
928
- void Function (
929
- URLSession session, URLSessionDownloadTask task, Uri uri)?
930
- onFinishedDownloading,
931
- void Function (URLSession session, URLSessionTask task, Error ? error)?
932
- onComplete}) =>
933
- URLSession ._(
934
- ncb.NSURLSession .sessionWithConfiguration_delegate_delegateQueue_ (
935
- linkedLibs, config._nsObject, _delegate, null ),
936
- onRedirect: onRedirect,
937
- onResponse: onResponse,
938
- onData: onData,
939
- onFinishedDownloading: onFinishedDownloading,
940
- onComplete: onComplete);
941
-
920
+ {URLRequest ? Function (URLSession session, URLSessionTask task,
921
+ HTTPURLResponse response, URLRequest newRequest)?
922
+ onRedirect,
923
+ URLSessionResponseDisposition Function (
924
+ URLSession session, URLSessionTask task, URLResponse response)?
925
+ onResponse,
926
+ void Function (URLSession session, URLSessionTask task, Data error)?
927
+ onData,
928
+ void Function (URLSession session, URLSessionDownloadTask task, Uri uri)?
929
+ onFinishedDownloading,
930
+ void Function (URLSession session, URLSessionTask task, Error ? error)?
931
+ onComplete}) {
932
+ // Avoid the complexity of simultaenous or out-of-order delegate callbacks
933
+ // by only allowing callbacks to execute sequentially.
934
+ // See https://developer.apple.com/forums/thread/47252
935
+ // NOTE: this is likely to reduce throughput when there are multiple
936
+ // requests in flight because each call to a delegate waits on a lock
937
+ // that is unlocked by Dart code.
938
+ final queue = ncb.NSOperationQueue .new1 (linkedLibs)
939
+ ..maxConcurrentOperationCount = 1
940
+ ..name =
941
+ 'cupertino_http.NSURLSessionDelegateQueue' .toNSString (linkedLibs);
942
+
943
+ return URLSession ._(
944
+ ncb.NSURLSession .sessionWithConfiguration_delegate_delegateQueue_ (
945
+ linkedLibs, config._nsObject, _delegate, queue),
946
+ onRedirect: onRedirect,
947
+ onResponse: onResponse,
948
+ onData: onData,
949
+ onFinishedDownloading: onFinishedDownloading,
950
+ onComplete: onComplete);
951
+ }
942
952
// A **copy** of the configuration for this sesion.
943
953
//
944
954
// See [NSURLSession.configuration](https://developer.apple.com/documentation/foundation/nsurlsession/1411477-configuration)
0 commit comments