@MyActor func method() {
ᶃ
Task { @MyActor in
ᶄ
}
Task { @MyActor in
ᶅ
}
ᶆ
}
w ·ͣᶃɺᶆ͕࣮ߦ͞ΕΔ
w ᶄɺᶅ
ฒྻʹ࣮ߦ͞Εͳ͍͕
ͲͪΒ͔Β
࣮ߦ͞ΕΔ͔Θ͔Βͳ͍
࣮ߦ͞ΕΔॱ൪
ಉ͡"DUPSͷ߹
εϨου ᶃ ᶆ
ᶄ ᶅ
ᶄ
ᶅ
ʁ
Slide 11
Slide 11 text
ͷ͋ΔίʔυΛվળ͢Δ
Slide 12
Slide 12 text
ͷ͋Δίʔυྫ
λοϓͨ͠ͷϩάΛૹΔ
w λοϓ͢ΔͨͼʹϩʔΧϧʹอ͍࣋ͯ͠ΔΛ૿͢
w ఆظతʹΛαʔόʔʹૹ৴͢Δ
w ૹ৴ͨ͠ΒϩʔΧϧͷΛϦηοτ͢Δ
Slide 13
Slide 13 text
ͷ͋Δίʔυྫ
actor Counter {
var count: Int = 0
func increment() {
count += 1
}
func reset() {
count = 0
}
}
class CountLogger {
private let counter = Counter()
func increment() async {
await counter.increment()
}
// ఆظతʹؒΛ͓͍ͯݺΕΔఆ
func post() async {
let count = await counter.count
await postCountLog(count)
await counter.reset()
}
}
Slide 14
Slide 14 text
class CountLogger {
func increment() async { ... }
...
func post() async {
let count = await counter.count
await postCountLog(count)
await counter.reset()
}
}
w DPVOUऔಘ͔ͯ͠ΒSFTFU͢Δ·ͰͷؒʹJODSFNFOU
͕ݺΕΔͱ
ͦͷ૿ՃQPTU͞ΕͣʹSFTFU͞ΕΔ
Slide 15
Slide 15 text
class CountLogger {
func increment() async { ... }
...
func post() async {
let count = await counter.count
await counter.reset()
await postCountLog(count)
}
}
w DPVOUऔಘޙʹ͙͢SFTFUͯ͠ɺ
4VTQFOUJPO1PJOUͰJODSFNFOU͕ݺΕΔՄೳੑ͕͋Δ
Slide 16
Slide 16 text
actor CountLogger {
func increment() async { ... }
...
func post() async {
let count = await counter.count
await counter.reset()
await postCountLog(count)
}
}
w BDUPSʹͯ͠4VTQFOUJPO1PJOU͕ೖΔ͜ͱมΘΒͳ͍
Slide 17
Slide 17 text
վળͨ͠ίʔυ
actor Counter {
private var count: Int = 0
func increment() {
count += 1
}
func pull() -> Int {
let count = self.count
self.count = 0
return count
}
}
actor CountLogger {
private let counter = Counter()
func increment() async {
await counter.increment()
}
// ఆظతʹؒΛ͓͍ͯݺΕΔఆ
func post() async {
let count = await counter.pull()
await postCountLog(count)
}
}
Slide 18
Slide 18 text
actor Counter {
private var count: Int = 0
...
func pull() -> Int {
let count = self.count
self.count = 0
return count
}
}
w DPVOUͷऔಘͱϦηοτΛBDUPSͷϝιουͭͰߦ͏͜ͱͰ
4VTQFOUJPO1PJOU͕ೖΔ͜ͱͳ͘ͳΔ
Slide 19
Slide 19 text
αϯϓϧͷ༷มߋ
λοϓͨ͠ͷϩάΛૹΓ߹ܭΛදࣔ
w λοϓ͢ΔͨͼʹϩʔΧϧʹอ͍࣋ͯ͠ΔΛ૿͢
w ఆظతʹΛαʔόʔʹૹ৴͢Δ
w ૹ৴ͨ͠ΒϩʔΧϧͷΛϦηοτ͢Δ
w ૹ৴࣌ʹαʔόʔ͔Β߹ܭΛฦ͠දࣔ͢Δ /FX
Slide 20
Slide 20 text
func post() async -> Int {
let count = await counter.pull()
let total = await postCountLog(count)
return total
}
w ಉ࣌ʹݺΕΔͱɺޙ͔ΒݺΜͩํ͕ઌʹऴΘΔՄೳੑ͕͋Δ
w BDUPS͕ಉ͡Ͱؔͳ͍
func post() async -> Int {
let count = await counter.pull()
let total = await postCountLog(count)
return total
}
ઌʹݺΜͩॲཧ
ޙ͔ΒݺΜͩॲཧ
Slide 21
Slide 21 text
w ݺͼग़͢λΠϛϯά͕ॏෳ͢Δͱ͕ى͖ΔՄೳੑ͕͋Δ
Task {
let total = await logger.post()
print("total : \(total)")
}
ͱΓ͋͑ͣ5BTL ❓
Slide 22
Slide 22 text
5JNFSͰ5BTLΛ܁Γฦ࣮͠ߦ
w QPTUͷॲཧ͕5JNFSͷJOUFSWBMΛ͑Δͱɺ
QPTUͷॲཧ͕ॏෳ͢ΔՄೳੑ͕͋Δ
Timer.scheduledTimer(withTimeInterval: 10, repeats: true) { _ in
Task {
let total = await logger.post()
print("total : \(total)")
}
}
❌
Slide 23
Slide 23 text
w 5BTLͷதͰϧʔϓ͢ΕɺQPTUͷॲཧॏෳ͠ͳ͍
Task {
while true {
await logger.post()
print("total : \(total)")
try await Task.sleep(for: .seconds(10))
}
}
5BTLͰ܁Γฦ࣮͠ߦ
Slide 24
Slide 24 text
αϯϓϧͷ༷มߋ
λοϓͨ͠ͷϩάΛૹΓ߹ܭΛදࣔ
w λοϓ͢ΔͨͼʹϩʔΧϧʹอ͍࣋ͯ͠ΔΛ૿͢
w ఆظతʹΛαʔόʔʹૹ৴͢Δ
w ૹ৴ͨ͠ΒϩʔΧϧͷΛϦηοτ͢Δ
w ૹ৴࣌ʹαʔόʔ͔Β߹ܭΛฦ͠දࣔ͢Δ
w ࣗ༝ͳλΠϛϯάͰΛαʔόʔʹૹ৴͢Δ /FX
w ࣮ߦͤͣɺผ5BTLͰඇಉظॲཧ͕ྻʹ࣮ߦ͞ΕΔΑ͏ʹ͢Δ
w ͨͩ͠ɺݺͼग़͠ଆ͕࣮ࡍͷඇಉظॲཧͷྃΛͭ͜ͱͰ͖ͳ͍
let channel: AsyncChannel
Task {
for await _ in channel {
let total = await logger.post()
print("total : \(total)")
}
}
Task {
await channel.send(())
}
"TZOD$IBOOFMΛ͏
Slide 27
Slide 27 text
·ͱΊ
4XJGU$PODVSSFODZͱϨʔείϯσΟγϣϯ
w 4XJGU$PODVSSFOUZϨʔείϯσΟγϣϯΛ͍Ͱ͘ΕΔͷͰͳ͍
w Ή͠ΖޮΛ༏ઌͯ͠Λى͍͜͢͠Έʹͳ͍ͬͯΔ
w "DUPSSFFOUSBODZ
w ಉ͡BDUPSಉ࢜ͷॲཧͰɺBXBJUͰڬΈࠐ·ΕΔՄೳੑ͕͋Δ
w $PPQFSBUJWF5ISFBE1PPM
w εϨουͰ࣮ߦ͞ΕΔॱ൪ɺ࣮ߦ։࢝͠Α͏ͱͨ͠ॱ൪ͱݶΒͳ͍
Slide 28
Slide 28 text
·ͱΊ
ϨʔείϯσΟγϣϯͷରԠ
w ہॴతʹҰͭͷBDUPSͷதͰBTZODؔΛΘͣʹ
Ͳ͏ݺΕͯෆ߹͕ى͖ͳ͍ঢ়ଶΛ࡞Δ
w BTZODؔΛΈ߹Θͤͳ͍ͱ͍͚ͳ͚Εɺ
ΫϦςΟΧϧηΫγϣϯ͕ಉ࣌ʹ࣮ߦ͞Εͳ͍Α͏ʹߟྀ࣮ͯ͢͠Δ
Slide 29
Slide 29 text
ࢀߟ
w 88%$
w .FFUBTZODBXBJUJO4XJGU
w 1SPUFDUNVUBCMFTUBUFXJUI4XJGUBDUPST
w 4XJGUDPODVSSFODZ#FIJOEUIFTDFOFT