-
Notifications
You must be signed in to change notification settings - Fork 62
docs(operators): add documentation for toPromise #228
base: master
Are you sure you want to change the base?
docs(operators): add documentation for toPromise #228
Conversation
Oh.... I will fix the commit message this afternoon. Also I have to change the relatedOperators, which were just copy pasted (hups :D) |
5342b0d
to
412c024
Compare
Codecov Report
@@ Coverage Diff @@
## master #228 +/- ##
=======================================
Coverage 90.49% 90.49%
=======================================
Files 115 115
Lines 442 442
Branches 10 10
=======================================
Hits 400 400
Misses 40 40
Partials 2 2
Continue to review full report at Codecov.
|
'operatorType': 'utility' | ||
name: 'toPromise', | ||
operatorType: 'utility', | ||
signature: 'public toPromise(PromiseCtor: *): Promise<T>', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave out generics in signature for now.
name: 'PromiseCtor', | ||
type: '*', | ||
attribute: 'optional', | ||
description: `promise The constructor of the promise. If not provided, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to have promise
at the start of this sentence?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no I think it was a copy paste mistake :)
{ | ||
name: 'Just return the emitted value of the observable as a promise', | ||
code: ` | ||
const source = Rx.Observable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please change these to use es6 imports
…into add-docs-for-toPromise
Please don't merge, I would like to add a tip for making use of asnyc await (regarding to #556) |
|
||
source.then((value) => console.log('Value: %s', value)); | ||
// => Value: 42 | ||
`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this example.
it is based on https://www.learnrxjs.io/operators/utility/topromise.html
//return basic observable
const sample = val => Rx.Observable.of(val).delay(5000);
/*
convert each to promise and use Promise.all
to wait for all to resolve.
Maybe is a little too fancy (await and destructuring assignment).
*/
const [promise1, promise2] = await Promise.all([
sample('Promise 1').toPromise(),
sample('Promise 2').toPromise()
]);
//output: "Promise 1", "Promise 2"
promise1().then(val => {
console.log('Promise.all Result:', val);
});
promise2().then(val => {
console.log('Promise.all Result:', val);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now I would just add a hint. If we use stackblitz one could add a proper example with async await
@btroncone @sumitarora - Can you please review this ? |
#133