Add optional timeout parameter to await*() methods - #2
Conversation
clue
commented
May 4, 2015
Thanks for your PR and the great suggestion 👍 Some remarks about the current implementation which should be addressed first.
Looking forward to getting this in :) |
joshdifabio
commented
May 4, 2015
This just occurred to me after pushing :). I've fixed this now and added tests to cover it. I went for a different approach to invoking |
joshdifabio
commented
May 4, 2015
This is indeed an interesting and debatable issue. I do feel that it's a little restrictive to
Agreed. I'll take a look at that at some point. |
joshdifabio
commented
May 9, 2015
@clue I've updated the PR to implement each of the recommendations you made in the OP but I haven't yet added tests to prove that promises are cancelled when a timeout occurs. I've also re-factored a bit to shorten each of the public methods and reduce code duplication. I seem to have broken the HHVM build on Travis; I'll take a look at that now. |
joshdifabio
commented
May 18, 2015
Any thoughts on this @clue? I'm currently depending on my fork for another project so it'd be great to get this merged. If there are any remaining issues then I can look at them this evening. |
clue
commented
Jun 6, 2015
This is an interesting idea… Let's move this to a dedicated ticket (#4), okay? :-)
Thanks for poking me :-) I'll review this again shortly in detail (and would appreciate if anybody else happens to have some thoughts on this!). At first sight, I'm not quite sure I like the code layout. The original code was rather clean, but did contain quite a bit of duplicate code. The new code avoids this duplication, at the cost of readability (all IMHO). Either way, thanks for your PR and the discussion! |
joshdifabio
commented
Jun 8, 2015
Thanks :)
The trouble is, there's a lot of duplication and code complexity otherwise. Maybe the approach (naming, at least) can be improved, but I think it'd be a shame to essentially copy & paste 50 loc into all three methods. |
clue
commented
Jul 2, 2015
Thanks for the update @joshdifabio! Unfortunately I haven't had the time to review this more thoroughly so far :( I'll keep an eye on this and will come back to this as time permits! In the meantime, have you checked out my (alpha quality) clue/promise-timeout project? This might be an alternative approach that could remove quite a bit of the code duplication. |
joshdifabio
commented
Jul 2, 2015
Thanks for the update. I've had a look at the Keep up the good work! |
clue
commented
Jul 2, 2015
Awesome, please let me know how it works out! 👍 I still think that adding a timeout to blocking functions is a common feature that should be exposed in a way that is easy to use. Though I'm curious as to how this is best achieved. Thanks for your patience and much appreciated work so far! |
clue
commented
Jul 11, 2015
@joshdifabio Thanks for all the effort you've put into this ticket! 🎉 I very much appreciate your work and I'd love to get this functionality in! 👍 Given that the new functional API landed the other day, I currently don't see how we could resolve the resulting merge conflict. Instead, I'd like to close this ticket for now, so that it serves as an archive for the history of the original implementation idea. If you (or anybody else for that matter) happens to want to rewrite this on top of the functional API, please feel invited to file a new PR and I'd be happy to help push this forward 👍 I've just opened #14 for the reference so this doesn't get lost. Thanks! |
Calling
await*()with no timeout is scary. I think that in almost all cases, when we wait for something we don't want to potentially wait forever. While clients of this library could handle this themselves, it's much easier to add it to this library directly.Regarding the implementation: it might make sense to have a
TimeoutExceptionclass to make it easier for clients to differentiate between rejected promises and timeouts.It's totally cool if you don't want to merge this!