IEnumerator _loadCoroutine(string key, Completer completer, Isolate isolate) { var url = new Uri(key); using (var www = UnityWebRequest.Get(url)) { if (headers != null) { foreach (var header in headers) { www.SetRequestHeader(header.Key, header.Value); } } yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { completer.completeError(new Exception($"Failed to load from url \"{url}\": {www.error}")); yield break; } var data = www.downloadHandler.data; using (Isolate.getScope(isolate)) { completer.complete(data); } } }
IEnumerator _loadCoroutine(string key, Completer completer, Isolate isolate) { var url = _urlFromKey(key); using (var www = UnityWebRequest.Get(url)) { if (headers != null) { foreach (var header in headers) { www.SetRequestHeader(header.Key, header.Value); } } yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { completer.completeError(new UIWidgetsError(new List <DiagnosticsNode>() { new ErrorSummary($"Unable to load asset: {key}"), new StringProperty("HTTP status code", www.error) })); yield break; } var data = www.downloadHandler.data; using (Isolate.getScope(isolate)) { completer.complete(data); } } }
public override void dispose() { D.assert(!_transitionCompleter.isCompleted, () => $"Cannot dispose a {GetType()} twice."); _controller?.dispose(); _transitionCompleter.complete(FutureOr.value(_result)); base.dispose(); }
void _show() { D.assert(_mode != _RefreshIndicatorMode.refresh); D.assert(_mode != _RefreshIndicatorMode.snap); Completer completer = Completer.create(); _pendingRefreshFuture = completer.future; _mode = _RefreshIndicatorMode.snap; _positionController .animateTo(1.0f / RefreshIndicatorUtils._kDragSizeFactorLimit, duration: RefreshIndicatorUtils._kIndicatorSnapDuration) .then((value) => { if (mounted && _mode == _RefreshIndicatorMode.snap) { D.assert(widget.onRefresh != null); setState(() => { _mode = _RefreshIndicatorMode.refresh; }); Future refreshResult = widget.onRefresh(); D.assert(() => { if (refreshResult == null) { UIWidgetsError.reportError(new UIWidgetsErrorDetails( exception: new UIWidgetsError( "The onRefresh callback returned null.\n" + "The RefreshIndicator onRefresh callback must return a Promise." ), context: new ErrorDescription("when calling onRefresh"), library: "material library" )); } return(true); }); if (refreshResult == null) { return; } refreshResult.whenComplete(() => { if (mounted && _mode == _RefreshIndicatorMode.refresh) { completer.complete(); _dismiss(_RefreshIndicatorMode.done); } }); } }); }
private Future _handleRefresh() { Completer completer = Completer.create(); Timer.create(new TimeSpan(0, 0, 0, 3), () => { completer.complete(); }); return(completer.future.then((_) => { _scaffoldKey.currentState?.showSnackBar(new SnackBar( content: new Text("Refresh complete"), action: new SnackBarAction( label: "RETRY", onPressed: () => { _refreshIndicatorKey.currentState.show(); } ) )); })); }
Future <byte[]> _sendPlatformMessage(string channel, byte[] message) { Completer completer = Completer.create(); Window.instance.sendPlatformMessage(channel, message, (reply) => { try { completer.complete(FutureOr.value(reply)); } catch (Exception exception) { UIWidgetsError.reportError(new UIWidgetsErrorDetails( exception: exception, library: "services library", context: new ErrorDescription("during a platform message response callback") )); } }); return(completer.future.to <byte[]>()); }
public override Future <T> loadStructuredData <T>(string key, Func <string, Future <T> > parser) { D.assert(key != null); D.assert(parser != null); if (_structuredDataCache.ContainsKey(key)) { return(_structuredDataCache[key].to <T>()); } Completer completer = null; Future <T> result = null; loadString(key, cache: false).then_ <T>(value => parser(value)).then_ <object>((T value) => { result = new SynchronousFuture <T>(value); _structuredDataCache[key] = result; if (completer != null) { // We already returned from the loadStructuredData function, which means // we are in the asynchronous mode. Pass the value to the completer. The // completer's future is what we returned. completer.complete(FutureOr.value(value)); } return(FutureOr.nil); }); if (result != null) { // The code above ran synchronously, and came up with an answer. // Return the SynchronousFuture that we created above. return(result); } // The code above hasn't yet run its "then" handler yet. Let's prepare a // completer for it to use when it does run. completer = Completer.create(); _structuredDataCache[key] = result = completer.future.to <T>(); return(result); }
public override Future <_SizeAwareCacheKey> obtainKey(ImageConfiguration configuration) { Completer completer = null; SynchronousFuture <_SizeAwareCacheKey> result = null; imageProvider.obtainKey(configuration).then((object key) => { // TODO: completer is always null? if (completer == null) { result = new SynchronousFuture <_SizeAwareCacheKey>(new _SizeAwareCacheKey(key, width, height)); } else { completer.complete(FutureOr.value(new _SizeAwareCacheKey(key, width, height))); } }); if (result != null) { return(result); } completer = Completer.create(); return(completer.future.to <_SizeAwareCacheKey>()); }
public override void dispose() { _completer.complete(); _controller.dispose(); base.dispose(); }