This repository was archived by the owner on Oct 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathtoPromise.ts
51 lines (48 loc) · 1.53 KB
/
toPromise.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { OperatorDoc } from '../operator.model';
export const toPromise: OperatorDoc = {
name: 'toPromise',
operatorType: 'utility',
signature: 'public toPromise(PromiseCtor: *): Promise',
parameters: [
{
name: 'PromiseCtor',
type: '*',
attribute: 'optional',
description: `The constructor of the promise. If not provided,
it will look for a constructor first in Rx.config.Promise then fall back to the native Promise constructor if available.`
}
],
shortDescription: {
description:
'Converts an Observable sequence to a ES2015 compliant promise.'
},
walkthrough: {
description: `An ES2015 compliant promise which contains the last value from the Observable sequence.
If the Observable sequence is in error, then the Promise will be in the rejected stage.
If the sequence is empty, the Promise will not resolve.`,
extras: [
{
type: 'Tip',
text:
'This operator makes reactive programming easy to use for developers who are not used to it.'
}
]
},
examples: [
{
name: 'Just return the emitted value of the observable as a promise',
code: `
import {of} from 'rxjs/observable/of';
const source = of(42)
.toPromise();
source.then((value) => console.log('Value: %s', value));
// => Value: 42
`,
externalLink: {
platform: 'JSBin',
url: 'http://jsbin.com/fanivejahe/embed?js,console,output'
}
}
],
relatedOperators: ['fromPromise']
};