Avatar
omochimetaru 11/1/2020 9:01 AM
This maintains proposals for changes and user-visible enhancements to the Swift Programming Language. - DougGregor/swift-evolution
9:01 AM
func chop(_ vegetable: Vegetable) async throws -> Vegetable { await try Task.checkCancellation() // automatically throws `CancellationError` // chop chop chop ... // ... guard await !Task.isCancelled() else { print("Canceled mid-way through chopping of \(vegetable)!") throw CancellationError() } // chop some more, chop chop chop ... }
9:01 AM
キャンセルの取り扱いはStructured Concurrencyの方に出てきた。
9:05 AM
func test_cancellation_withCancellationHandler(_ anything: Any) async -> PictureData { let handle = Task.runDetached { () -> PictureData in let file = SomeFile() return await try Task.withCancellationHandler( handler: { file.close() }, operation: { await test_cancellation_guard_isCancelled(file) }) } handle.cancel() }
9:06 AM
コールバック式のやつもPRにあった。