-
-
Notifications
You must be signed in to change notification settings - Fork 16
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 waitFor function to enable waiting for async functions #131
Add waitFor function to enable waiting for async functions #131
Conversation
4eb8608
to
674a7f2
Compare
674a7f2
to
deacb7a
Compare
@bendemboski - @rwjblue and I revived this one. Thanks so much for taking it as far as you did! We've made a few changes, namely kept the Let me know if you have any thoughts/suggestions. |
LGTM. I think the two additional items in the original PR that are probably mostly ready (I'll have to revive them from my repo's branches) are:
Any changes on those fronts, or continue with the original plans? |
I think the idea is that we layer on generator support into As for the stripping, is that so we can reduce the size of the bundle? |
Oh, gotcha, that makes sense from an API standpoint. And I think I can maybe picture how to implement it? We'd need to make the wrapper function look at the return value, and if it looks like an iterator, then wrap it in our own iterator instrumented with test waiter calls, instead of wrapping it in
Yeah, this was originally something requested by @rwjblue and my cut at it was here. |
@bendemboski yes that's exactly what we were thinking WRT the generator - essentially inspecting the shape of the return value to determine if it's an iterator, and wrapping it as you said. As for stripping, I think we can wait on that. I think the idea we had was to still ship these things in the prod bundle, as we ultimately want to be able to run tests against a prod bundle, but still have it wait for async. If we strip, we can't do that. This is predicated on us moving away from using the |
Ya, this just means we need another flag ( |
Gotcha. Okay, once this is finalized/merged I'll make some time to port the |
if (isThenable(result)) { | ||
return waitForPromise(result, label); | ||
} else { | ||
return result; | ||
} |
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.
Note: @bendemboski I think we would add the check for iterator here just like the isThenable
thing (iterator being something with a typeof result.next === 'function'
I believe)
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.
Ya maybe add an isIterable
?
Extracted from #81
A couple of notes:
waitForPromise
tests reasonably DRY -- I'm definitely open to other ideas if anyone has any