Skip to content

Conversation

@DougGregor
Copy link
Member

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:

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.

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor changed the title [Concurrency] Stop runDetached from actually printing/running the task. [Concurrency] Introduce a small executable test using asynchronous futures Nov 17, 2020
@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - c8cc876adcb22d2cccd45cab1a06d121dfe65db4

Copy link
Contributor

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, helped me kickstart work on the groups 👍

Your call if we want to merge or not, might as well I suppose.

// failure seems unrelated https://ci.swift.org/job/swift-PR-osx/24459/testReport/Swift(iphonesimulator-i386)/IRGen/objc_generic_class_stub_swift/

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

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.
… test.

Extend the basic futures test to include a call to an async function so
that we exercise coroutine splitting.
@DougGregor DougGregor force-pushed the concurrency-basic-future branch from c8cc876 to 95edef7 Compare November 17, 2020 18:10
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor merged commit a9f5107 into swiftlang:main Nov 17, 2020
@DougGregor DougGregor deleted the concurrency-basic-future branch November 17, 2020 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants