ရိုးရိုးလေး ရှင်းပြမယ်
Async/Await, Tasks & Actors ကို ရိုးရိုးလေးနားလည်မယ်
Swift structured concurrency တွင်task lifetime, cancellation, actor isolation နဲ့Sendable data boundaries ကိုရှင်းရပါတယ်။ `async let`/task groups ကိုchild work အတွက်သုံးပြီးshared mutable state ကိုactor ဖြင့်ကာကွယ်ပါ။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
Sample output တစ်ခုမှန်ရုံဖြင့်nil, ownership, actor isolation နဲ့error paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
ဖြစ်လေ့ရှိတဲ့အမှား
Force unwrap သို့unchecked shared mutable state ဖြင့်compiler safety ကိုကျော်ခြင်း။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Swift structured concurrency တွင်task lifetime, cancellation, actor isolation နဲ့Sendable data boundaries ကိုရှင်းရပါတယ်။ `async let`/task groups ကိုchild work အတွက်သုံးပြီးshared mutable state ကိုactor ဖြင့်ကာကွယ်ပါ။
- Concurrent work
- Task + actor isolation
- Value / cancellation / error
Async/Await, Tasks & Actors ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
actor Counter {
private var value = 0
func increment() { value += 1 }
func current() -> Int { value }
}
let counter = Counter()
await counter.increment()
print(await counter.current())Swift structured concurrency တွင်task lifetime, cancellation, actor isolation နဲ့Sendable data boundaries ကိုရှင်းရပါတယ်။ `async let`/task groups ကိုchild work အတွက်သုံးပြီးshared mutable state ကိုactor ဖြင့်ကာကွယ်ပါ။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Concurrent work
actor Counter {Swift structured concurrency တွင်task lifetime, cancellation, actor isolation နဲ့Sendable data boundaries ကိုရှင်းရပါတယ်။ `async let`/task groups ကိုchild work အတွက်သုံးပြီးshared mutable state ကိုactor ဖြင့်ကာကွယ်ပါ။
- Task + actor isolation
}Swift structured concurrency တွင်task lifetime, cancellation, actor isolation နဲ့Sendable data boundaries ကိုရှင်းရပါတယ်။ `async let`/task groups ကိုchild work အတွက်သုံးပြီးshared mutable state ကိုactor ဖြင့်ကာကွယ်ပါ။
- Value / cancellation / error
print(await counter.current())Async/Await, Tasks & Actors example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
- Concurrent work
- Task + actor isolation
- Value / cancellation / error
Success
Async/Await, Tasks & Actors ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
Failure
Sample output တစ်ခုမှန်ရုံဖြင့်nil, ownership, actor isolation နဲ့error paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
Swift structured concurrency တွင်task lifetime, cancellation, actor isolation နဲ့Sendable data boundaries ကိုရှင်းရပါတယ်။ `async let`/task groups ကိုchild work အတွက်သုံးပြီးshared mutable state ကိုactor ဖြင့်ကာကွယ်ပါ။
actor Counter {
private var value = 0
func increment() { value += 1 }
func current() -> Int { value }
}
let counter = Counter()
await counter.increment()
print(await counter.current())1Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Async/Await, Tasks & Actors example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Async/Await, Tasks & Actors example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
actor Counter {
private var value = 0
func increment() { value += 1 }
func current() -> Int { value }
}
let counter = Counter()
await counter.increment()
print(await counter.current())ရလဒ်: Async/Await, Tasks & Actors ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Async/Await, Tasks & Actors example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Concurrent work → Task + actor isolation → Value / cancellation / error
- Swift structured concurrency တွင်task lifetime, cancellation, actor isolation နဲ့Sendable data boundaries ကိုရှင်းရပါတယ်။ `async let`/task groups ကိုchild work အတွက်သုံးပြီးshared mutable state ကိုactor ဖြင့်ကာကွယ်ပါ။
- Sample output တစ်ခုမှန်ရုံဖြင့်nil, ownership, actor isolation နဲ့error paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
- Async/Await, Tasks & Actors example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
The Swift Programming Language: Concurrency — Swift.org