Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to use Observables with async/await #83

Merged
merged 1 commit into from Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Observable.js
Expand Up @@ -314,6 +314,12 @@ export class Observable {
}));
}

async all() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can all just be this?

async all() {
  let values = [];
  await this.forEach(value => values.push(value));
  return values;
}

let values = [];
await this.forEach(value => values.push(value));
return values;
}

concat(...sources) {
let C = getSpecies(this);

Expand Down
10 changes: 10 additions & 0 deletions test/all.js
@@ -0,0 +1,10 @@
import assert from 'assert';

describe('all', ()=> {
it('should receive all the observed values in order as an array', async () => {
let observable = Observable.of(1,2,3,4);
let values = await observable.all();

assert.deepEqual(values, [1,2,3,4]);
});
});