Skip to content

[Concurrency] Add asynchronous Task.sleep function #35983

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

Merged
merged 6 commits into from
Mar 5, 2021

Conversation

drexin
Copy link
Contributor

@drexin drexin commented Feb 16, 2021

No description provided.

@drexin drexin marked this pull request as draft February 16, 2021 01:05
_enqueueJobGlobalWithDelay(duration, Builtin.convertTaskToJob(task))

let _ = await Handle<Void, Never>(task).get()
}
Copy link
Contributor

@ktoso ktoso Feb 16, 2021

Choose a reason for hiding this comment

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

Hmm, I wonder if implementing this without a detached implicitly created task might be better?

It'd need much more boilerplate to introduce a new "awaitable" function like I did for swift_task_group_wait_next for groups... It'd save some allocations (the task allocates, and if we wanted to make this task a child that's another allocation and hitting a lock in the parent too).

What do @DougGregor @jckarter think?

flags.isFuture = true

// Create the asynchronous task future.
let (task, _) = Builtin.createAsyncTaskFuture(flags.bits, nil, {})
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it matters to pass in the parent... maybe for debugging it might be better to get the current task and tread this as if a child after all, just in case someone "stops execution" and happens to end up in the sleep somewhere... (Can this even happen...?)

@drexin
Copy link
Contributor Author

drexin commented Feb 26, 2021

@swift-ci smoke test

@drexin drexin marked this pull request as ready for review February 26, 2021 00:00
@drexin
Copy link
Contributor Author

drexin commented Feb 26, 2021

@swift-ci smoke test

@drexin
Copy link
Contributor Author

drexin commented Feb 26, 2021

@swift-ci smoke test

1 similar comment
@drexin
Copy link
Contributor Author

drexin commented Feb 26, 2021

@swift-ci smoke test

@drexin drexin force-pushed the wip-async-sleep branch from 7950fb5 to 5f6c64a Compare March 3, 2021 18:52
@drexin
Copy link
Contributor Author

drexin commented Mar 3, 2021

@swift-ci smoke test

2 similar comments
@drexin
Copy link
Contributor Author

drexin commented Mar 3, 2021

@swift-ci smoke test

@drexin
Copy link
Contributor Author

drexin commented Mar 3, 2021

@swift-ci smoke test

@drexin
Copy link
Contributor Author

drexin commented Mar 4, 2021

@swift-ci test macos

@swift-ci
Copy link
Contributor

swift-ci commented Mar 4, 2021

Build failed
Swift Test OS X Platform
Git Sha - 41be930d85516483ae9a793f43953d24ca2848d9

@drexin drexin force-pushed the wip-async-sleep branch from 41be930 to 54e78cc Compare March 4, 2021 17:38
@drexin
Copy link
Contributor Author

drexin commented Mar 4, 2021

@swift-ci smoke test

@drexin
Copy link
Contributor Author

drexin commented Mar 4, 2021

@swift-ci smoke test

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.

LGTM :-)

@DougGregor
Copy link
Member

This is lovely and we should land it.

@DougGregor DougGregor merged commit 531b080 into swiftlang:main Mar 5, 2021
@JJJensen
Copy link

I'm not sure which proposal this belongs to, but shouldn't this support cancellation? Or is this on purpose to avoid implementing a semaphore kind of thing on top of this? :-)

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.

5 participants