See how Dispatch can let you run regularly scheduled work in only a few lines of code.
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.
SPONSORED Join a FREE crash course for iOS devs who want to become complete senior developers — from October 18th to 24th. Learn how to apply iOS app architecture patterns through a series of lectures and practical coding sessions.
Paul Hudson is the creator of Hacking with Swift, the most comprehensive series of Swift books in the world. He's also the editor of Swift Developer News, the maintainer of the Swift Knowledge Base, and a speaker at Swift events around the world. If you're curious you can learn more here.
Link copied to your pasteboard.