Avatar
Avatar
shiz
今は async {} -> Taskのinit detach -> Task.detach に変わってますね(だいぶ議論になってますが) https://github.com/apple/swift-evolution/blob/main/proposals/0304-structured-concurrency.md#unstructured-tasks-1 https://github.com/apple/swift/pull/37495 違いとしてはざっくりと
  • Taskのinit -> 呼び出し側のmeta情報やpriorityなどを引き継ぐ
  • Task.detach -> ↑を引き継がない
なんですかね https://github.com/apple/swift-evolution/blob/main/proposals/0304-structured-concurrency.md#context-inheritance 僕はasyncHandlerの代わりだと思ってます。 We might need to create new tasks whose lifetime is not bound to the creating task, for example in order to fire-and-forget some operation or to initiate asynchronous work from synchronous code
(edited)
omochimetaru 6/7/2021 2:13 AM
ありがとうございます 以下は結構大事に思います
2:13 AM
// Actor context propagation func notOnActor(_: @Sendable () async -> Void) { } actor A { func f() { notOnActor { await g() // must call g asynchronously, because it's a @Sendable closure } Task { g() // okay to call g synchronously, even though it's @Sendable } } func g() { } }