You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Swift Express has a Future based asynchronous APIs. You can return Future from your route callback, and then complete it at any time.
Something like this
importBrightFuturesapp.get("/home"){(request:Request<AnyContent>)->Future<Action<AnyContent>,AnyError>in
// Creating promise
letp=Promise<Action<AnyContent>,AnyError>()HomeController().fetchData{postsin
//Completing promise with some result
p.success(Action<AnyContent>.render("home",context:["posts":posts])}
//Returning future
returnp.future}
There are a couple of things that actually usually work:
At the moment of writing this tutorial building application from Xcode will not work, so you have to do it manually through terminal
Which Xcode have you used and how were you making it work? It works for me...
One thing that you should take into consideration is that building and running Swift Express application after you’ve already built it on the same port will not trigger the update, because the port was in use. To solve this problem, you can chain terminal commands in the following order: kill all processes on the given port, build changes if any, run applicaiton on the same port. The terminal command will look like this:
Usually it works just by quitting swift-express run with Ctrl+C (or with stop if running from Xcode). Could you let me know more details?
Also I'm going to make a PR to your article's code. Just to make it better using async capabilities along with Futures.
Activity
ypopovych commentedon Jul 20, 2016
Hi @newPrimitives, thanks for your question.
Swift Express has a Future based asynchronous APIs. You can return Future from your route callback, and then complete it at any time.
Something like this
dileping commentedon Jul 21, 2016
@newPrimitives @ypopovych
I can suggest a simpler and a more generic way of converting your callbacks based API to Futures.
Assuming you have something like this (correct me if I'm wrong):
add somewhere in your code following function that will convert it to a Future:
With all above you can handle it as easy as:
Let me know if this worked for you, please.
newPrimitives commentedon Jul 22, 2016
@dileping @ypopovych it works. I've implemented this in one of my tutorials which you can check here: http://nermin.tech/swift-on-servers-101-swift-express/
Also there's a gihtub repo with the code from the tutorial on my profile: https://github.com/newPrimitives/swift-express-demo
Feel free to suggest improvements.
dileping commentedon Jul 22, 2016
@newPrimitives Hey, great article! Thanks ;)
There are a couple of things that actually usually work:
Which Xcode have you used and how were you making it work? It works for me...
Usually it works just by quitting
swift-express runwith Ctrl+C (or with stop if running from Xcode). Could you let me know more details?Also I'm going to make a PR to your article's code. Just to make it better using async capabilities along with Futures.
Best,
Daniel