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

Allow gathering a specific amount of values instead of all of them #5

Open
Richienb opened this issue Aug 31, 2020 · 6 comments
Open

Comments

@Richienb
Copy link
Contributor

Richienb commented Aug 31, 2020

It would be useful if this module could only take a specific amount of values from an observable to achieve a similar purpose as p-event:

const observableToPromise = require('observable-to-promise');

(async () => {
	console.log(await observableToPromise.one(Observable.of(1, 2, 3, 4, 5)));
	//=> 1

	console.log(await observableToPromise(Observable.of(1, 2, 3, 4, 5), {maximumValues: 3}));
	//=> [1, 2, 3]
})();

// @sindresorhus

@sindresorhus
Copy link
Owner

Sure, but should be called count as the suggested naming is misleading as it can never be below max, so it's not really a max.

@Richienb
Copy link
Contributor Author

Richienb commented Aug 31, 2020

@sindresorhus

it can never be below max, so it's not really a max.

const observableToPromise = require('observable-to-promise');

(async () => {
	console.log(await observableToPromise(Observable.of(1, 2, 3, 4), {maximumValues: 5}));
	//=> [1, 2, 3, 4]
})();

@sindresorhus
Copy link
Owner

achieve a similar purpose as p-event:

Then it's not the same purpose as p-event though. p-event waits until it has count elements, not less, not more.

What's your use-case for needing max?

@Richienb
Copy link
Contributor Author

Richienb commented Aug 31, 2020

@sindresorhus

What's your use-case for needing max?

I have an observable that emits newly received data but I only want the very next chunk of data emitted and nothing else.

p-event waits until it has count elements, not less, not more.

An observable could complete() before the specified amount of values has been emitted so it's best to call it maxCount.

@sindresorhus
Copy link
Owner

Alright 👍🏻

@JounQin
Copy link

JounQin commented Jun 8, 2022

firstValueFrom and lastValueFrom like rxjs would be great.

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

No branches or pull requests

3 participants