-
Notifications
You must be signed in to change notification settings - Fork 0
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
typesafe time units: proc sleep(t: Duration)
, allowing sleep(1.second)
, sleep(1.millisecond)
etc
#617
Comments
proc sleep(t: TimeInterval)
, allowing sleep(1.seconds)
, sleep(1.milliseconds)
etc
proc sleep(t: TimeInterval)
, allowing sleep(1.seconds)
, sleep(1.milliseconds)
etcproc sleep(t: Duration)
, allowing sleep(1.second)
, sleep(1.millisecond)
etc
Now, we could have sleep(1'second)
sleep(1'millisecond)
sleep(100'millisecond + 1'second)
sleep(1.5'hour) Consider following APIs sleepForproc sleepFor(t: Duration) The thread blocks for at least specified duration. sleepUntilproc sleepUntil(t: DateTime) The thread blocks until specified time arrived. |
yes.
maybe sleepMin, sleepMax is less ambiguous? but also, can you explain the semantics of those 2 procs, and in which case you'd end up sleep more than sleepFor or less than sleepUntil? also: std/durations should be separate from std/times and be imported/re-exported from std/times |
closing, as I'm opening the corresponding RFC nim-lang/RFCs#383 (because I'm seeing PRs that introduce duration params as int) |
as noted in nim-lang#17149 (comment),
sleep
is confusing:this is confusing, not self documenting, error prone and not particularly typesafe
proposal
add
proc sleep(t: Duration)
example:
note
std/times is a heavy dependency, ideally we'd be able to do this without depending on std/times, refs nim-lang/RFCs#55, via a new std/durations module (imported by std/times)
note
TimeInterval
is not good, this has overhead because it's calendar basedwe can define
millisecond
,second
(etc) withouts
to avoid confusion with the existingmilliseconds
+ friends.eg:
The text was updated successfully, but these errors were encountered: