Async/await has arrived in Vapor

Today we released Vapor 4.50.0 (and an APT version tag!) which adds async APIs to the most popular Vapor APIs and allows you to write async route handlers! :tada:

Alongside this we also released updates to FluentKit, Fluent and a number of other packages to make using async/await in Vapor easy.

The docs have been updated (Vapor Docs) so check them out. We've also added a short migration guide to help you migrate an existing project. We strongly encourage you to try the new APIs out and migrate your code to async/await over the coming months as this will provide a better development experience and make upgrading to Vapor 5 much easier. You can run async route handlers alongside EventLoopFuture handlers, though we encourage you to try and not mix and match too much inside an individual route handler.

Note: you must be running macOS Monterey and Xcode 13.1 on macOS or Swift 5.5 on Linux to be able to use the new APIs.

If you run into any issues or find missing APIs either post here in the forums, on GitHub or on Discord.

The Vapor Core Team

95 Likes

This is fantastic news! Thank you to @0xTim, SSWG, NIO team, and all the contributors. Congratulations!

4 Likes

This is really awesome, looking forward to trying it out!!! :tada:

1 Like

Thanks for the work guys! This is great! I am curious, what was your approach for supporting this on older OSs? Using the @available syntax or does the new version just only support Swift 5.5 and the new OSs?

All the new APIs are wrapped with compiler and availability checks so we still support Swift 5.2 and older OS versions. See vapor/Sources/Vapor/Concurrency at main ยท vapor/vapor ยท GitHub

2 Likes

I find this interesting. I know there's been discussion of providing async/await compatibility for older macOS and iOS versions, seems like Swift must already support providing the necessary runtime on Linux.

Edit: Oh! Swift concurrency back deployment - #9 by Jon_Shier

Linux ships with concurrency in the runtime instead of it being part of the OS so there's no restriction there.

In terms of Vapor supporting concurrency on older OSes we're dependent on NIO. Their future/async bridge is marked with a macOS 12 availability (because it had to be) so until NIO makes their Concurrency stuff available we can't. As soon as they do we can copy their availabilities

2 Likes

Good to know. Fortunately, for now I can control the platform I need to run Vapor on.

It doesn't look like the update has reached the Docker containers (Docker Hub) yet. Will this be coming?

Those Docker images are long deprecated, you should use the official Swift images instead. See the template for a production-ready example

1 Like

Thanks, Tim.

Nice I shall have a try. :flying_disc:

Terms of Service

Privacy Policy

Cookie Policy