Skip to content

Commit 193a3d5

Browse files
committed
Temporarily add runAsync to run a task synchronously in the current thread
Add a temporary runtime entry to run a task synchronous.
1 parent 2271d4d commit 193a3d5

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

include/swift/Runtime/Concurrency.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
145145
NearestTaskDeadline
146146
swift_task_getNearestDeadline(AsyncTask *task);
147147

148+
// TODO: Remove this hack.
149+
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
150+
void swift_task_run(AsyncTask *taskToRun);
151+
148152
}
149153

150154
#endif

stdlib/public/Concurrency/Task.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,8 @@ swift::swift_task_create_f(JobFlags flags, AsyncTask *parent,
132132

133133
return {task, initialContext};
134134
}
135+
136+
// TODO: Remove this hack.
137+
void swift::swift_task_run(AsyncTask *taskToRun) {
138+
taskToRun->run(ExecutorRef::noPreference());
139+
}

stdlib/public/Concurrency/Task.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,11 @@ extension Task {
306306
fatalError("\(#function) not implemented yet.")
307307
}
308308
}
309+
310+
@_silgen_name("swift_task_run")
311+
public func runTask(_ task: __owned Builtin.NativeObject)
312+
313+
public func runAsync(_ asyncFun: @escaping () async -> ()) {
314+
let childTask = Builtin.createAsyncTask(0, nil, asyncFun)
315+
runTask(childTask.0)
316+
}

0 commit comments

Comments
 (0)