-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'observable' into new-rms-adapter
- Loading branch information
Showing
5 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
declare class ObservablePromise<T> { | ||
private _status; | ||
private _promise; | ||
constructor(promise: Promise<T>); | ||
get promise(): Promise<T>; | ||
get status(): 'pending' | 'fulfilled' | 'rejected'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class ObservablePromise { | ||
constructor(promise) { | ||
this._status = 'pending'; | ||
this._promise = promise | ||
.then((value) => { | ||
this._status = 'fulfilled'; | ||
return value; | ||
}, (error) => { | ||
this._status = 'rejected'; | ||
throw error; | ||
}); | ||
} | ||
get promise() { | ||
return this._promise; | ||
} | ||
get status() { | ||
return this._status; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export class ObservablePromise<T> { | ||
private _status: 'pending' | 'fulfilled' | 'rejected' = 'pending'; | ||
private _promise: Promise<T>; | ||
|
||
constructor(promise: Promise<T>) { | ||
this._promise = promise | ||
.then( | ||
(value: T) => { | ||
this._status = 'fulfilled'; | ||
return value; | ||
}, | ||
(error) => { | ||
this._status = 'rejected'; | ||
throw error; | ||
} | ||
); | ||
} | ||
|
||
get promise(): Promise<T> { | ||
return this._promise; | ||
} | ||
|
||
get status(): 'pending' | 'fulfilled' | 'rejected' { | ||
return this._status; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters