-
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
futures should have an always
or something
#665
Comments
Why does |
because it's too early in the morning 😂. fixing it :P |
@weissi so this is something that will be executed no matter if the future is completed because of a failure or success ? |
@weissi Is this any different to: public func whenComplete(_ callback: @escaping () -> Void) Because we already have that. |
Oh, I see, it chains. Sure, why not. |
If we do this then we should most likely just mark |
@normanmaurer need both chaining and non-chaining variants |
@weissi why ? |
@normanmaurer because otherwise you can't write this: func runDatabaseQuery(_ query: String, database: DB) -> EventLoopFuture<[Row]> {
return database.openConnetion { conn in
conn.runQuery(query).always {
conn.close()
}
}
} You want to always close the DB connection. Currently you need to spell this func runDatabaseQuery(_ query: String, database: DB) -> EventLoopFuture<[Row]> {
return database.openConnetion { conn in
let f = conn.runQuery(query)
f.whenComplete {
conn.close()
}
return f
}
} which is super ugly |
@weissi I may need more coffee but I still dont get why we could not only have |
Yeah, I think @normanmaurer is right, we can just have |
@Lukasa we'll still allocate an extra, unnecessary future. We also have |
@weissi why ? Couldn't it just return |
@normanmaurer true |
Bear in mind that the semantics of that are slightly different than the semantics of returning a new future, though only slightly. |
@Lukasa but does it matter at all ? |
Depends if you're trying to be really certain about future execution. Probably not though. |
@normanmaurer @Lukasa @weissi Is that something we'd still want to add? 🤓 |
I'm still very much in favour of having this, every time I use NIO as a user I want to have it :). Sure, it's pretty straightforward to work around but I often have something I need to close, a connection, a file, whatever and of course I want to do it always if there's an error or not. |
Motivation: apple#665 Modifications: * Add `always` in EventLoopFuture.swift * Add tests Result: NIO Users will be able to use `.always` to, well, always run an action wether the future succeed or not.
Motivation: apple#665 Modifications: * Add `always` in EventLoopFuture.swift * Add tests Result: NIO Users will be able to use `.always` to, well, always run an action wether the future succeed or not.
Motivation: apple#665 Modifications: * Add `always` in EventLoopFuture.swift * Add tests Result: NIO Users will be able to use `.always` to, well, always run an action wether the future succeed or not.
Motivation: apple#665 Modifications: * Add `always` in EventLoopFuture.swift * Add tests Result: NIO Users will be able to use `.always` to, well, always run an action wether the future succeed or not.
Motivation: apple#665 Modifications: * Add `always` in EventLoopFuture.swift * Add tests Result: NIO Users will be able to use `.always` to, well, always run an action wether the future succeed or not.
Motivation: apple#665 Modifications: * Add `always` in EventLoopFuture.swift * Add tests Result: NIO Users will be able to use `.always` to, well, always run an action wether the future succeed or not.
Motivation: apple#665 Modifications: * Add `always` in EventLoopFuture.swift * Add tests Result: NIO Users will be able to use `.always` to, well, always run an action wether the future succeed or not.
Fixed by #981 |
often you need to do some cleanup that needs to always happen, why not
that always runs?
The text was updated successfully, but these errors were encountered: