From 53bd6e1642d73168283df7e704b2f43264b825a6 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Mon, 2 Nov 2015 09:58:42 -0800 Subject: [PATCH] feat(facade): add ObservableWrapper.fromPromise --- modules/angular2/src/core/facade/async.dart | 4 ++++ modules/angular2/src/core/facade/async.ts | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/angular2/src/core/facade/async.dart b/modules/angular2/src/core/facade/async.dart index 7d95e89110..c454330e35 100644 --- a/modules/angular2/src/core/facade/async.dart +++ b/modules/angular2/src/core/facade/async.dart @@ -57,6 +57,10 @@ class ObservableWrapper { static void callComplete(EventEmitter emitter) { emitter.close(); } + + static Stream fromPromise(Future f) { + return new Stream.fromFuture(f); + } } class EventEmitter extends Stream { diff --git a/modules/angular2/src/core/facade/async.ts b/modules/angular2/src/core/facade/async.ts index a82776094e..33f039dfb3 100644 --- a/modules/angular2/src/core/facade/async.ts +++ b/modules/angular2/src/core/facade/async.ts @@ -26,7 +26,7 @@ export class TimerWrapper { export class ObservableWrapper { // TODO(vsavkin): when we use rxnext, try inferring the generic type from the first arg static subscribe(emitter: any, onNext: (value: T) => void, onError?: (exception: any) => void, - onComplete?: () => void): Object { + onComplete: () => void = () => {}): Object { return emitter.subscribe({next: onNext, error: onError, complete: onComplete}); } @@ -44,6 +44,10 @@ export class ObservableWrapper { static callError(emitter: EventEmitter, error: any) { emitter.error(error); } static callComplete(emitter: EventEmitter) { emitter.complete(); } + + static fromPromise(promise: Promise): Observable { + return RxObservable.fromPromise(promise); + } } /**