# SE-0304 (3rd review): Structured Concurrency

**URL:** <https://forums.swift.org/t/se-0304-3rd-review-structured-concurrency/48847>\
**Category:** Proposal Reviews\
**Created:** [May 24, 2021, 10:52pm UTC](https://forums.swift.org/t/se-0304-3rd-review-structured-concurrency/48847 "2021-05-24T22:52:14Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![Douglas\_Gregor](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/douglas_gregor/32/1362_2.png) [@Douglas\_Gregor](https://forums.swift.org/u/Douglas_Gregor)\
**Post date:** [June 1, 2021, 6:28pm UTC](https://forums.swift.org/t/se-0304-3rd-review-structured-concurrency/48847/17 "2021-06-01T18:28:56Z")

</div>

> [@benrimmington](#):
>
> [`Darwin.sleep(_:)`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/sleep.html) has a `seconds: CUnsignedInt` parameter. Which top-level functions accept a plain integer as _nanoseconds_ ?
> 
> `Task.sleep(_:)` would be improved with an argument label, and possibly a different parameter type:
> 
> ```swift
> extension Task where Success == Never, Failure == Never {
> public static func sleep(forTimeInterval seconds: Double) async
> }
> 
> ```
> 
> This would match the existing [`Foundation.Thread`](https://developer.apple.com/documentation/foundation/thread/1413673-sleep) API, and be compatible with the `Foundation.Date` APIs. If `Double` (as an alias for `TimeInterval` ) has 15 significant digits, then it should have nanosecond precision for a range of several days?

That `sleep` has an unlabeled parameter specified in nanoseconds is definitely a problem. I'm not sure we want to push the idea of specifying seconds as a `Double` down into the standard library at all, and doing so for this one API seems unfortunate. Perhaps the easy way out is to use an argument label:

```swift
extension Task where Success == Never, Failure == Never {
  public static func sleep(nanoseconds: UInt64) async
}

```

The API is intentionally ugly, and leaves open space for us to create a nicer `sleep(_:)` with a proper time type at some point in the future.

> [@benrimmington](#):
>
> > Because use-sites look quite explicit in the way they have to prefix this call with an `await` keyword ( `await Task.sleep(nanos)` ), we prefer to use the well-known `sleep` word rather than introduce new words for this functionality.
> 
> `Task.yield()` could also be renamed. The documentation comments for both APIs are "suspends the current task", so perhaps `await Task.suspend()` and `await Task.suspend(forTimeInterval: seconds)` .

Yeah. The [AsyncStream proposal](https://github.com/apple/swift-evolution/blob/main/proposals/0314-async-stream.md) and [modify accessors](https://forums.swift.org/t/modify-accessors/31872) consistently use "yield" to mean "produce a value". I agree that `suspend` is a better term here.

> [@benrimmington](#):
>
> Can only the current task be suspended, or should it be possible to suspend (and resume) via a task handle?

Only the current task. You cannot ask someone else's task to suspend, because they might not be at a potential suspension point.

Doug

---

_[View the full topic](https://forums.swift.org/t/se-0304-3rd-review-structured-concurrency/48847)._
