mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 11:37:46 +00:00
runtime: handle negative sleep times
This change fixes the edge case where a negative sleep time is provided. When this happens, the call now returns immediately (as specified by the docs for time.Sleep).
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
//go:build !scheduler.none
|
||||
// +build !scheduler.none
|
||||
|
||||
package runtime
|
||||
@@ -7,6 +8,10 @@ import "internal/task"
|
||||
// Pause the current task for a given time.
|
||||
//go:linkname sleep time.Sleep
|
||||
func sleep(duration int64) {
|
||||
if duration <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
addSleepTask(task.Current(), nanosecondsToTicks(duration))
|
||||
task.Pause()
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
//go:build scheduler.none
|
||||
// +build scheduler.none
|
||||
|
||||
package runtime
|
||||
|
||||
//go:linkname sleep time.Sleep
|
||||
func sleep(duration int64) {
|
||||
if duration <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
sleepTicks(nanosecondsToTicks(duration))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user