FutureImpl<T> Class
Implements
Constructors
Code new FutureImpl() #
FutureImpl() : _successListeners = [], _exceptionHandlers = [], _completionListeners = [];
Code factory FutureImpl.immediate(T value) #
factory FutureImpl.immediate(T value) { final res = new FutureImpl(); res._setValue(value); return res; }
Methods
Code Future chain(Function transformation) #
Future chain(Function transformation) { final completer = new Completer(); handleException((e) { completer.completeException(e, this.stackTrace); return true; }); then((v) { var future = null; try { future = transformation(v); } catch (final ex, final stackTrace) { completer.completeException(ex, stackTrace); return; } future.handleException((e) { completer.completeException(e, future.stackTrace); return true; }); future.then((b) => completer.complete(b)); }); return completer.future; }
Code Object get exception() #
Object get exception() { if (!isComplete) { throw new FutureNotCompleteException(); } return _exception; }
Code void handleException(bool onException(Object exception)) #
void handleException(bool onException(Object exception)) { if (_exceptionHandled) return; if (_isComplete) { if (_exception != null) { _exceptionHandled = onException(_exception); } } else { _exceptionHandlers.add(onException); } }
Code void onComplete(void complete(Future<T> future)) #
void onComplete(void complete(Future<T> future)) { if (_isComplete) { try { complete(this); } catch (final e) {} } else { _completionListeners.add(complete); } }
Code Object get stackTrace() #
Object get stackTrace() { if (!isComplete) { throw new FutureNotCompleteException(); } return _stackTrace; }
Code void then(void onSuccess(T value)) #
void then(void onSuccess(T value)) { if (hasValue) { onSuccess(value); } else if (!isComplete) { _successListeners.add(onSuccess); } else if (!_exceptionHandled) { throw _exception; } }
Code Future transform(Function transformation) #
Future transform(Function transformation) { final completer = new Completer(); handleException((e) { completer.completeException(e, this.stackTrace); return true; }); then((v) { var transformed = null; try { transformed = transformation(v); } catch (final ex, final stackTrace) { completer.completeException(ex, stackTrace); return; } completer.complete(transformed); }); return completer.future; }