GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

How to use Grand Central Dispatch on your Swift server

See how Dispatch can let you run regularly scheduled work in only a few lines of code.

Paul Hudson       @twostraws

Soroush Khanlou has published a new article giving some helpful tips for using Grand Central Dispatch (GCD) in server-side Swift apps.

After explaining why it’s needed (“The main queue is blocked, constantly spinning, in order to prevent the program from ending”), Soroush goes on to provide examples of dispatch semaphores and timers that are simple enough you can start using them straight away.

While there’s a broader discussion to be had about actors in Swift in the future, spurred by Chris Lattner’s concurrency manifesto, and perhaps in the future, and some of the patterns for asynchronous workers will change, for now, Dispatch is the best tool that we have.

Link: Dispatch On The Server.

Hacking with Swift is sponsored by Essential Developer.

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until February 9th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

BUY OUR BOOKS
Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Interview Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let us know!

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.