Understanding Nonisolated Async Code in Swift 6.2

https://hackernoon.imgix.net/images/Ceus9O6pRZR4c9unqLNaigv0uzF3-0j83qbg.jpeg

Introduction

Ever since Swift Concurrency was introduced, its main mission has been clear: keep memory safe without making us write callback hell. But if we’re being honest, context switching-specifically thread hopping-has always been a bit of a head-scratcher.

How many times have you marked an async function as nonisolated on a @MainActor class, only to watch it instantly jump off to the cooperative global pool for no obvious reason?

Swift 6.2 addresses this head-on with Approachable Concurrency and its underlying flag, NonisolatedNonsendingByDefault.

Let’s break down what actually changes under the hood, how @concurrent fits into the picture, and what this all looks like when stepping through real code.

What Changes with NonisolatedNonsendingByDefault

Before Swift 6.2 (or with Approachable Concurrency turned off), any nonisolated async function would immediately yield its execution to Swift’s global cooperative executor whenever you called await. That meant constant, often unnecessary thread switching.

With Approachable Concurrency enabled...

Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE