refactor(async): extract timer related functions into a TimerWrapper
This commit is contained in:
@ -29,7 +29,12 @@ class PromiseWrapper {
|
||||
|
||||
static CompleterWrapper completer() => new CompleterWrapper(new Completer());
|
||||
|
||||
// TODO(vic): create a TimerWrapper
|
||||
static bool isPromise(maybePromise) {
|
||||
return maybePromise is Future;
|
||||
}
|
||||
}
|
||||
|
||||
class TimerWrapper {
|
||||
static Timer setTimeout(fn(), int millis)
|
||||
=> new Timer(new Duration(milliseconds: millis), fn);
|
||||
static void clearTimeout(Timer timer) {
|
||||
@ -43,10 +48,6 @@ class PromiseWrapper {
|
||||
static void clearInterval(Timer timer) {
|
||||
timer.cancel();
|
||||
}
|
||||
|
||||
static bool isPromise(maybePromise) {
|
||||
return maybePromise is Future;
|
||||
}
|
||||
}
|
||||
|
||||
class ObservableWrapper {
|
||||
|
@ -39,18 +39,17 @@ export class PromiseWrapper {
|
||||
|
||||
return {promise: p, resolve: resolve, reject: reject};
|
||||
}
|
||||
static isPromise(maybePromise): boolean { return maybePromise instanceof Promise; }
|
||||
}
|
||||
|
||||
// TODO(vicb): create a TimerWrapper
|
||||
export class TimerWrapper {
|
||||
static setTimeout(fn: Function, millis: int): int { return global.setTimeout(fn, millis); }
|
||||
static clearTimeout(id: int): void { global.clearTimeout(id); }
|
||||
|
||||
static setInterval(fn: Function, millis: int): int { return global.setInterval(fn, millis); }
|
||||
static clearInterval(id: int): void { global.clearInterval(id); }
|
||||
|
||||
static isPromise(maybePromise): boolean { return maybePromise instanceof Promise; }
|
||||
}
|
||||
|
||||
|
||||
export class ObservableWrapper {
|
||||
static subscribe(emitter: Observable, onNext, onThrow = null, onReturn = null): Object {
|
||||
return emitter.observer({next: onNext, throw: onThrow, return: onReturn});
|
||||
|
Reference in New Issue
Block a user