2016-09-18 15:55:08 -07:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2019-11-27 13:00:59 -08:00
|
|
|
import {Observable} from 'rxjs';
|
|
|
|
|
2017-01-19 12:06:28 -08:00
|
|
|
/**
|
|
|
|
* Determine if the argument is shaped like a Promise
|
|
|
|
*/
|
2020-03-18 15:28:25 +08:00
|
|
|
export function isPromise<T = any>(obj: any): obj is Promise<T> {
|
2016-09-18 15:55:08 -07:00
|
|
|
// allow any Promise/A+ compliant thenable.
|
|
|
|
// It's up to the caller to ensure that obj.then conforms to the spec
|
|
|
|
return !!obj && typeof obj.then === 'function';
|
|
|
|
}
|
2019-11-27 13:00:59 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if the argument is an Observable
|
|
|
|
*/
|
|
|
|
export function isObservable(obj: any | Observable<any>): obj is Observable<any> {
|
|
|
|
// TODO: use isObservable once we update pass rxjs 6.1
|
|
|
|
// https://github.com/ReactiveX/rxjs/blob/master/CHANGELOG.md#610-2018-05-03
|
|
|
|
return !!obj && typeof obj.subscribe === 'function';
|
|
|
|
}
|