Skip to content
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

[Concurrency] TaskExecutor ownership fixes #74000

Merged
merged 10 commits into from
Jun 14, 2024
Prev Previous commit
Next Next commit
un-comment some test coverage
  • Loading branch information
ktoso committed Jun 14, 2024
commit 9ac80fa35733e74186b13243f5c10ef8030f2453
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,29 @@ actor Worker {
}

func test(_ expectedExecutor: NaiveQueueExecutor) async {
// // we are isolated to the serial-executor (!)
// dispatchPrecondition(condition: .onQueue(expectedExecutor.queue))
// expectedExecutor.preconditionIsolated()
//
// // the nonisolated async func properly executes on the task-executor
// await nonisolatedFunc(expectedExecutor: expectedExecutor)
//
// /// the task-executor preference is inherited properly:
// async let val = {
// dispatchPrecondition(condition: .onQueue(expectedExecutor.queue))
// expectedExecutor.preconditionIsolated()
// return 12
// }()
// _ = await val
//
// we are isolated to the serial-executor (!)
dispatchPrecondition(condition: .onQueue(expectedExecutor.queue))
expectedExecutor.preconditionIsolated()

// the nonisolated async func properly executes on the task-executor
await nonisolatedFunc(expectedExecutor: expectedExecutor)

// the task-executor preference is inherited properly:
async let val = {
dispatchPrecondition(condition: .onQueue(expectedExecutor.queue))
expectedExecutor.preconditionIsolated()
return 12
}()
_ = await val

// as expected not-inheriting
_ = await Task.detached {
dispatchPrecondition(condition: .notOnQueue(expectedExecutor.queue))
}.value
//
// // we properly came back to the serial executor, just to make sure
// dispatchPrecondition(condition: .onQueue(expectedExecutor.queue))
// expectedExecutor.preconditionIsolated()

// we properly came back to the serial executor, just to make sure
dispatchPrecondition(condition: .onQueue(expectedExecutor.queue))
expectedExecutor.preconditionIsolated()
}
}

Expand All @@ -84,12 +84,8 @@ actor Worker {
let executor = NaiveQueueExecutor(queue)

await Task(executorPreference: executor) {
print(">>> INSIDE TASK")
let worker = Worker(on: executor)
print(">> AFTER WORKER")
await worker.test(executor)
print(">> AFTER TEST()")
}.value
print(">> AFTER TASK.VALUE")
}
}