Closed litlighilit closed 3 months ago
BTW, It seems to deadloop as os.sleep calls Sleep on Windows, whose parameter type, is in fact DWORD
, an uint32, but Nim wraps it as int32, so pass negative int just becomes a large unsigned int.
Still a DWORD
relative issue...
What's wrong with -1
meaning "forever"?
on posix, it returns immediately. (and set errno to EINVAL
)
What's wrong with -1 meaning "forever"?
And strictly speaking, not forever, but a very large uint amount of time.
e.g. Currently on Windows:
sleep(-1)
in fact does Sleep(4294967295)
a.k.a. while sleep(-1)
means sleep forever is somewhat reasonable, it means sleep for 49 days on Windows and sleep for no time on POSIX.
sleep
should take Natural
.
Description
BTW, on POSIX, it just returns immediately, as sleep calls
nanosleep
, which exits with errno set asEINVAL
for negative values.Nim Version
At least from 1.6.14 to 2.1.1 and devel
Current Output
No response
Expected Output
No response
Possible Solution
Two direction:
Additional Information
In Python, time.sleep raises ValueError on negative value.
Maybe we can raises OSError as Nim's sleep is in
std/os
if the first direction is accepted.On the other hand, golang's time.Sleep will return immediately for negative values.