Skip to content

Commit b31958d

Browse files
committed
Use isCurrentExecutor check in startOnMainActorImpl
startOnMainActor checked the current executor directly, which in some cases came back as a `nullptr`. This happens with older API which don't know to set the current executor. `swift_task_isCurrentExecutor` knows how to check for the current dispatch queue and the main thread though, so switching the main-executor check to use that API instead.
1 parent 9d9b964 commit b31958d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

stdlib/public/Concurrency/Task.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ SWIFT_CC(swift)
15981598
static void swift_task_startOnMainActorImpl(AsyncTask* task) {
15991599
AsyncTask * originalTask = _swift_task_clearCurrent();
16001600
ExecutorRef mainExecutor = swift_task_getMainExecutor();
1601-
if (swift_task_getCurrentExecutor() != swift_task_getMainExecutor())
1601+
if (!swift_task_isCurrentExecutor(mainExecutor))
16021602
swift_Concurrency_fatalError(0, "Not on the main executor");
16031603
swift_retain(task);
16041604
swift_job_run(task, mainExecutor);

0 commit comments

Comments
 (0)