Last active
November 27, 2019 22:08
-
-
Save NeuralGlue/5958c1815239ecc323f2ef109b948f0e to your computer and use it in GitHub Desktop.
AntiPatterns in Vapor 3
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
// assuming a route such as /parents/Parent.parameter/children/ | |
func addChildtoParent(_ req: Request) throws -> Future<Child> { | |
return try req.parameters.next(Parent.self).flatMap(to: Child.self) { parent in | |
return try req.content.decode(Child.self).flatMap{ child in | |
child.parentId = try parent.requireId() | |
return try child.save(on:req) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is an anti-pattern. Use instead Async's own flatmap(to: Result.type, FutureA, FutureB).