44 lines
941 B
Dart
Raw Normal View History

library angular.core.facade.async;
import 'dart:async';
export 'dart:async' show Future;
2014-10-10 15:44:56 -04:00
class PromiseWrapper {
2015-01-29 09:50:49 -08:00
static Future resolve(obj) => new Future.value(obj);
2015-01-29 09:50:49 -08:00
static Future reject(obj) => new Future.error(obj);
2015-01-29 09:50:49 -08:00
static Future<List> all(List<Future> promises) => Future.wait(promises);
2015-01-29 09:50:49 -08:00
static Future then(Future promise, success(value), Function onError) {
2014-12-01 20:06:21 +01:00
if (success == null) return promise.catchError(onError);
2014-10-10 15:44:56 -04:00
return promise.then(success, onError: onError);
}
2015-01-29 09:50:49 -08:00
static _Completer completer() => new _Completer(new Completer());
2015-01-29 09:50:49 -08:00
static void setTimeout(fn(), int millis) {
new Timer(new Duration(milliseconds: millis), fn);
}
static bool isPromise(maybePromise) {
return maybePromise is Future;
}
}
class _Completer {
2015-01-29 09:50:49 -08:00
final Completer c;
_Completer(this.c);
2015-01-29 09:50:49 -08:00
Future get promise => c.future;
2015-01-29 09:50:49 -08:00
void complete(v) {
c.complete(v);
}
2015-01-29 09:50:49 -08:00
void reject(v) {
c.completeError(v);
}
}