-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[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
Conversation
_enqueueJobGlobalWithDelay(duration, Builtin.convertTaskToJob(task)) | ||
|
||
let _ = await Handle<Void, Never>(task).get() | ||
} |
There was a problem hiding this comment.
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?
stdlib/public/Concurrency/Task.swift
Outdated
flags.isFuture = true | ||
|
||
// Create the asynchronous task future. | ||
let (task, _) = Builtin.createAsyncTaskFuture(flags.bits, nil, {}) |
There was a problem hiding this comment.
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...?)
1c68543
to
fab072f
Compare
@swift-ci smoke test |
@swift-ci smoke test |
fab072f
to
51d3899
Compare
@swift-ci smoke test |
1 similar comment
@swift-ci smoke test |
@swift-ci smoke test |
@swift-ci test macos |
Build failed |
@swift-ci smoke test |
@swift-ci smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :-)
This is lovely and we should land it. |
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? :-) |
No description provided.