mirror of https://github.com/vapor/docs.git
1.0 KiB
1.0 KiB
Getting Started with Async
Vapor is powered by Apple's SwiftNIO, a powerful non-blocking networking framework. If you are using the fully-powered Vapor framework to create a website, then you will likely not need to use this directly. However, if you are using a lower-level library (like a Database framework) then you will need to understand a little about how it works.
Workers
Vapor's async abstraction is built on a few pieces, including the async Worker. This protocol has an eventLoop, which fits nicely with SwiftNIO's constructs.
Example
You need to create a SwiftNIO EventGroup that can power the connection:
let database = MySQLDatabase(config: config)
let worker = MultiThreadedEventLoopGroup(numThreads: System.coreCount)
let futureConnection = database.makeConnection(on: worker)