To make that happen, you need to be able to write strong copy and call to action phrases that make your audience want to do what you’re asking them to do. What’s equally important is getting people to click on your links, submit inquiries and ultimately become customers. While that’s still important to up your social media engagement, there’s more to it than that when it comes to getting your potential customers to take action. Let emailFuture: EventLoopFuture = eventLoop.Creating social media content is much more than simply writing clever captions to accompany your photos and blog posts. In Vapor, assuming you have access to an EventLoop, you can simply do the following: Let email: String = try await getUserEmailAsync() Imagine you want to convert the async/await code below to something that returns an EventLoopFuture: That’s when the second tool comes in handy. At the same time, you still need it to work with other parts of your code that are using async/await. What if you need the exact opposite of what the get() function does? Sometimes, you don’t have control over a piece of your existing code, or you might want to postpone its migration until another time. Converting async/await to EventLoopFuture Let username: String = try await usernameFuture.get()Īs you can see, get() easily converts your EventLoopFuture to a simple String. You can asynchronously retrieve this function’s value using the new async/await syntax. Let usernameFuture: EventLoopFuture = getUsernameFromDatabase() The first tool is a useful get() function on top of EventLoopFuture, which enables retrieving the inner value of any EventLoopFuture using the async/await syntax. Converting EventLoopFuture to async/await These enable developers to migrate their code to async/await without much trouble, but you’ll learn that you have even better options most of the time. Bridging Between async/await and EventLoopFutureĮverything you’ll learn in the following sections is implemented using two simple but powerful tools. That’s it for now! Time to learn about the foundation of Vapor’s async/await support. If you’d like to resolve that warning anyway, read this section of Vapor’s official documentation. Note: You can ignore the warning about no custom working directory, as it has no impact on this tutorial. You’ll see a NOTICE indicating Trader’s successful run on address : Build and run Trader using the shortcut Command-R or the top-left Play button. This creates a PostgreSQL database running in Docker called `traderdb`. Copy and paste the following into your Terminal window to get your PostgreSQL database going with the help of Docker:ĭocker run -name traderdb -e POSTGRES_DB=vapor_database \ ![]() While you’re waiting for Xcode to resolve Trader’s dependencies, open Terminal. This is required for executable targets in Swift 5.5. executableTarget(name: "Run", dependencies: ), In the Package declaration, change Trader’s macOS platform to version 12:įinally, in targets, declare the Run target as an executableTarget instead of a normal target: ![]() The very first line declares the Swift version that your app uses. Since you’re using async/await, you need to change a few lines. You’ll see it contains a variety of files and folders.įirst things first! Open Package.swift. ![]() The starter project is a simple API that tracks “crates” being traded between different owners. If you’re unfamiliar with Fluent and running a database on Docker, check out Using Fluent and Persisting Models in Vapor.ĭownload the sample project by clicking Download Materials at the top or bottom of this tutorial. You’ll also use Fluent to interact with a PostgreSQL database. If you’re new to Vapor, check out Getting Started with Server-Side Swift with Vapor 4. This tutorial assumes you’re comfortable building simple Vapor 4 apps. Note: Full use of async/await requires Swift 5.5, Xcode 13.1 and macOS Monterey or greater.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |