github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/runtime/scheduler_any.go (about)

     1  //go:build !scheduler.none
     2  
     3  package runtime
     4  
     5  import "internal/task"
     6  
     7  // Pause the current task for a given time.
     8  //
     9  //go:linkname sleep time.Sleep
    10  func sleep(duration int64) {
    11  	if duration <= 0 {
    12  		return
    13  	}
    14  
    15  	addSleepTask(task.Current(), nanosecondsToTicks(duration))
    16  	task.Pause()
    17  }
    18  
    19  // run is called by the program entry point to execute the go program.
    20  // With a scheduler, init and the main function are invoked in a goroutine before starting the scheduler.
    21  func run() {
    22  	initHeap()
    23  	go func() {
    24  		initAll()
    25  		callMain()
    26  		schedulerDone = true
    27  	}()
    28  	scheduler()
    29  }
    30  
    31  const hasScheduler = true