Commit Graph

264 Commits

Author SHA1 Message Date
Doug Gregor
a1284d062c [Concurrency] Stop runDetached from actually printing/running the task.
Rather than immediately running the task synchronously within
runDetached, return the handle to the newly-created task. Add a method
task.Handle.run() to execute the task. This is just a temporary hack
that should not persist in the API, but it lets us launch tasks on a
particular Dispatch queue:

```swift
extension DispatchQueue {
  func async<R>(execute: @escaping () async -> R) -> Task.Handle<R> {
    let handle = Task.runDetached(operation: execute)

    // Run the task
    _ = { self.async { handle.run() } }()

    return handle
  }
}
```

One can pass asynchronous work to DispatchQueue.async, which will
schedule that work on the dispatch queue and return a handle. Another
asynchronous task can then read the result.

Yay for rdar://71125519.
2020-11-17 10:04:26 -08:00
Doug Gregor
2a41920c00 [Concurrency] Implement basic runDetached on top of createAsyncTaskFuture. 2020-11-15 22:37:13 -08:00
Arnold Schwaighofer
193a3d5a8f Temporarily add runAsync to run a task synchronously in the current thread
Add a temporary runtime entry to run a task synchronous.
2020-11-13 10:41:42 -08:00
Doug Gregor
c291eb596b [Concurrency] Add cancelAsyncTask() builtin.
Implement a new builtin, `cancelAsyncTask()`, to cancel the given
asynchronous task. This lowers down to a call into the runtime
operation `swift_task_cancel()`.

Use this builtin to implement Task.Handle.cancel().
2020-11-05 13:50:17 -08:00
Konrad `ktoso` Malawski
27d734a709 [Concurrency] Include Task.sleep(until:) and Task.yield() placeholders 2020-11-02 20:51:00 +09:00
Konrad `ktoso` Malawski
9e8f2cc031 [Concurrency] Task cancellation and deadline stubs 2020-11-02 20:51:00 +09:00
Konrad `ktoso` Malawski
107bc27c96 [Concurrency] Remove Handle.Failure, since we do not use it as get() is always throwing currently;
There is no meaningful way to restrict the error type (or expect it for that matter.
2020-10-28 17:04:06 +09:00
Konrad `ktoso` Malawski
3e261781e3 [concurrency] task is only a namespace after all; remove Task.current() 2020-10-28 16:54:52 +09:00
Konrad `ktoso` Malawski
d6d3e957d0 [Concurrency] add currentPriority to task 2020-10-28 14:15:20 +09:00
Konrad `ktoso` Malawski
b5fd2a5c56 Address review comments; get() must throw, formatting 2020-10-27 11:30:53 +09:00
Konrad `ktoso` Malawski
579c89c222 [Concurrency] More documentation of Task.Priority 2020-10-26 19:02:07 +09:00
Konrad `ktoso` Malawski
d6adac3172 [Concurrency] Stubs for Task.current() 2020-10-26 19:02:07 +09:00
Konrad `ktoso` Malawski
07f80bed64 [Concurrency] API stubs: Task.Handle, priority and runDetached 2020-10-26 19:02:07 +09:00
Konrad `ktoso` Malawski
9023e56bd9 [Concurrency] Add minimal placeholders for Task and UnsafeContinuation 2020-10-26 19:02:02 +09:00