Last active
February 21, 2021 21:39
-
-
Save cweinberger/93d4b214d4eebf6ec01f173d242f8075 to your computer and use it in GitHub Desktop.
Vapor 4 Utilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import NIO | |
/// Author: vzsg (Discord) - https://twitter.com/vzsg_dev | |
/// Source: https://discordapp.com/channels/431917998102675485/684159753189982218/684537099378098272 | |
extension EventLoopFuture { | |
func tryFlatMap<NewValue>( | |
file: StaticString = #file, | |
line: UInt = #line, | |
_ callback: @escaping (Value) throws -> EventLoopFuture<NewValue> | |
) -> EventLoopFuture<NewValue> { | |
return flatMap(file: file, line: line) { result in | |
do { | |
return try callback(result) | |
} catch { | |
return self.eventLoop.makeFailedFuture(error, file: file, line: line) | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vapor | |
extension ViewRenderer { | |
public func render<E>(_ name: String, _ context: EventLoopFuture<E>) -> EventLoopFuture<View> | |
where E: Encodable | |
{ | |
context.flatMap { context in | |
self.render(name, context) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment