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

Add method to EventLoop that is to EventLoop.submit as Future.then is to Future.map. #426

Closed
Lukasa opened this issue May 22, 2018 · 4 comments
Labels
good first issue Good for newcomers kind/enhancement Improvements to existing feature.

Comments

@Lukasa
Copy link
Contributor

Lukasa commented May 22, 2018

Currently EventLoop.submit is defined like this: func submit<T>(_ task: @escaping () throws -> T) -> EventLoopFuture<T>.

The problem here is that T may be EventLoopFuture<U>. In this instance, you end up with EventLoopFuture<EventLoopFuture<U>> as the return type of submit, and double futures are annoying to work with.

It would be very helpful to have a method that can deal with this. To add this in a backward-compatible way, we could add the method to the EventLoop protocol, and also provide an extension with a default implementation that just does .then { $0 } on the returned double-future from the default method.

@Lukasa Lukasa added kind/enhancement Improvements to existing feature. help wanted good first issue Good for newcomers labels May 22, 2018
@Lukasa
Copy link
Contributor Author

Lukasa commented May 22, 2018

Whoever does this should also clean up the workarounds from #424.

@karim-elngr
Copy link
Contributor

Any name suggestions for the new function?

@weissi
Copy link
Member

weissi commented Jan 21, 2019

@karim-elngr really sorry for the huge delay, this just slipped through. We just talked about it and flatSubmit (similar to flatMap and map) sounds like the best name to us.

Lukasa pushed a commit that referenced this issue Oct 22, 2019
Motivation:

Calling EventLoop's submit method with a task that returns an EventLoopFuture results in a double future. flatSubmit provides an alternative which does not return a double future.

Modifications:

Added flatSubmit() to the EventLoop protocol and provided a default implementation that returns the result of calling flatMap { $0 } on the EventLoopFuture returned from task.

Result:

Additive change only. flatSubmit method on EventLoop will be available for use.
@weissi
Copy link
Member

weissi commented Oct 23, 2019

fixed in #1174

@weissi weissi closed this as completed Oct 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers kind/enhancement Improvements to existing feature.
Projects
None yet
Development

No branches or pull requests

3 participants