Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

docs(operators): add documentation for toPromise #228

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

niklas-wortmann
Copy link
Member

@niklas-wortmann
Copy link
Member Author

Oh.... I will fix the commit message this afternoon. Also I have to change the relatedOperators, which were just copy pasted (hups :D)

@codecov-io
Copy link

codecov-io commented Jan 4, 2018

Codecov Report

Merging #228 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           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
Impacted Files Coverage Δ
src/operator-docs/utility/toPromise.ts 100% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3dc2401...f37338b. Read the comment docs.

'operatorType': 'utility'
name: 'toPromise',
operatorType: 'utility',
signature: 'public toPromise(PromiseCtor: *): Promise<T>',
Copy link
Collaborator

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,
Copy link
Collaborator

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?

Copy link
Member Author

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
Copy link
Collaborator

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

@niklas-wortmann
Copy link
Member Author

niklas-wortmann commented Feb 12, 2018

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
`,
Copy link
Contributor

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);
});

Copy link
Member Author

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

@ashwin-sureshkumar
Copy link
Collaborator

@btroncone @sumitarora - Can you please review this ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants