-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Cancellation of TaskGroup should not trigger cancel handler of parent task #40562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rokhinip
merged 1 commit into
main
from
rokhinip/86346865-taskgroup-cancellAll-cancellationHandler
Dec 22, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
test/Concurrency/Runtime/async_taskgroup_cancel_from_inside_child.swift
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
test/Concurrency/Runtime/taskgroup_cancelAll_cancellationHandler.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking %import-libdispatch -parse-as-library) | %FileCheck %s | ||
|
||
// REQUIRES: executable_test | ||
// REQUIRES: concurrency | ||
// REQUIRES: libdispatch | ||
|
||
// rdar://76038845 | ||
// REQUIRES: concurrency_runtime | ||
// UNSUPPORTED: back_deployment_runtime | ||
|
||
func test_taskGroup_cancelAll() async { | ||
|
||
await withTaskCancellationHandler { | ||
await withTaskGroup(of: Int.self, returning: Void.self) { group in | ||
group.spawn { | ||
await Task.sleep(3_000_000_000) | ||
let c = Task.isCancelled | ||
print("group task isCancelled: \(c)") | ||
return 0 | ||
} | ||
|
||
group.cancelAll() // Cancels the group but not the task | ||
_ = await group.next() | ||
} | ||
} onCancel : { | ||
print("parent task cancel handler called") | ||
} | ||
|
||
// CHECK-NOT: parent task cancel handler called | ||
// CHECK: group task isCancelled: true | ||
// CHECK: done | ||
print("done") | ||
} | ||
|
||
@available(SwiftStdlib 5.1, *) | ||
@main struct Main { | ||
static func main() async { | ||
await test_taskGroup_cancelAll() | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// RUN: %target-typecheck-verify-swift -disable-availability-checking | ||
// REQUIRES: concurrency | ||
|
||
@available(SwiftStdlib 5.1, *) | ||
func test_taskGroup_cancelAll() async { | ||
await withTaskGroup(of: Int.self, returning: Void.self) { group in | ||
group.spawn { | ||
await Task.sleep(3_000_000_000) | ||
let c = Task.isCancelled | ||
print("group task isCancelled: \(c)") | ||
return 0 | ||
} | ||
|
||
group.spawn { | ||
group.cancelAll() //expected-warning{{capture of 'group' with non-sendable type 'TaskGroup<Int>' in a `@Sendable` closure}} | ||
//expected-error@-1{{reference to captured parameter 'group' in concurrently-executing code}} | ||
return 0 | ||
} | ||
group.spawn { [group] in | ||
group.cancelAll() //expected-warning{{capture of 'group' with non-sendable type 'TaskGroup<Int>' in a `@Sendable` closure}} | ||
return 0 | ||
} | ||
_ = await group.next() | ||
} | ||
|
||
print("done") | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.