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

Feature Request: whenAsync #66

Closed
daedalus28 opened this issue Jul 27, 2017 · 4 comments · Fixed by #68
Closed

Feature Request: whenAsync #66

daedalus28 opened this issue Jul 27, 2017 · 4 comments · Fixed by #68

Comments

@daedalus28
Copy link
Collaborator

I have a few use cases where I'd like a promise for when an observable is set with a certain value. when is awesome, but it effectively takes a callback for when the predicate returns true instead of resolving a promise.

I've implemented this as whenAsync like so:

let whenAsync = fn => new Promise(resolve => when(fn, resolve))

And I use it like this:

await whenAsync(() => !state.someBoolean)

It's especially useful for detecting when boolean values change, e.g. getting a promise for when a modal closes, something finishes loading, etc. It's also useful for testing. We have utils here to convert from a promise to an observable, but not the other way around.

Would something like this be useful as a pull request?

@mweststrate
Copy link
Member

mweststrate commented Jul 28, 2017 via email

@daedalus28
Copy link
Collaborator Author

Awesome, I'll add a PR for it!

@daedalus28 daedalus28 mentioned this issue Aug 2, 2017
@daedalus28
Copy link
Collaborator Author

Hi there! I've taken a quick stab at a PR adding whenAsync. I tried to follow conventions used by the project already but I'm sure I'm missing things. Feedback is greatly appreciated 😄

@daedalus28
Copy link
Collaborator Author

@mweststrate Any update on this? I've had a PR open for a while

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

Successfully merging a pull request may close this issue.

2 participants