-
Notifications
You must be signed in to change notification settings - Fork 656
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add flatScheduledTask() methods to EventLoop #1497
Conversation
…EventLoop. Motivation: Currently the best, or at least simplest, way to schedule a delayed asynchronous task and wait on its complete result is something like `eventLoop.scheduleTask(in: ...) { return somethingAsync(...) }.futureResult.flatMap { $0 }`. This is not only unobvious but also a bit ugly. Modifications: I have added methods which correspond to scheduleTask() in the same way flatSubmit() does to submit(). The returned Scheduled<T> object allows cancellation of the asynchronous task's execution in the same way that is possible for synchronous scheduled tasks, and the futureResult does not complete until the entire asynchronous task does. Callers wishing to wait only for submission of the delayed task, rather than its overall completion, may continue to use the existing scheduleTask() APIs to do so. Tests have been added to verify that the behavior of the new methods is as expected. These changes are purely additive.
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.
Thanks very much! This looks good to me (modulo a few nits) :)
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.
Thanks; this is helpful! I also have a few nit picks but looks good otherwise.
…they can actually be used, too!
…y to precisely control time. For good measure, retrofit the existing tests that were copy/pasted to create the new ones.
… XCTest features.
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.
Looks good to me!
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.
This looks really good, I only have a few tiny nits! I appreciate that the comment ones aren't introduced by you, but you changed the lines so we may as well clear them up while we're here.
Co-Authored-By: Cory Benfield <lukasa@apple.com>
…seconds(0))`, thus redundant. Fix new tests, original tests, and the bad example in the repeated async task test.
…t-scheduling tasks.
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.
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.
awesome, thank you!
Motivation: Currently the best, or at least simplest, way to schedule a delayed asynchronous task and wait on its complete result is something like `eventLoop.scheduleTask(in: ...) { return somethingAsync(...) }.futureResult.flatMap { $0 }`. This is not only unobvious but also a bit ugly. Modifications: I have added methods which correspond to scheduleTask() in the same way flatSubmit() does to submit(). The returned Scheduled<T> object allows cancellation of the asynchronous task's execution in the same way that is possible for synchronous scheduled tasks, and the futureResult does not complete until the entire asynchronous task does. Callers wishing to wait only for submission of the delayed task, rather than its overall completion, may continue to use the existing scheduleTask() APIs to do so. Tests have been added to verify that the behavior of the new methods is as expected. These changes are purely additive. Co-authored-by: Cory Benfield <lukasa@apple.com> Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
Add
flatScheduleTask(deadline:)
andflatScheduleTask(in:)
methods toEventLoop
.Motivation:
Currently the best, or at least simplest, way to schedule a delayed asynchronous task and wait on its complete result is something like
eventLoop.scheduleTask(in: ...) { return somethingAsync(...) }.futureResult.flatMap { $0 }
. This is not only unobvious but also a bit ugly.Modifications:
I have added methods which correspond to scheduleTask() in the same way flatSubmit() does to submit(). The returned Scheduled object allows cancellation of the asynchronous task's execution in the same way that is possible for synchronous scheduled tasks, and the futureResult does not complete until the entire asynchronous task does. Callers wishing to wait only for submission of the delayed task, rather than its overall completion, may continue to use the existing scheduleTask() APIs to do so. Tests have been added to verify that the behavior of the new methods is as expected.
I also made a few very minor corrections to a couple of documentation comments which suffered from copy-pasta.
Result:
These changes are purely additive.