Module jls.util.CoroutineScheduler

Provide a simple scheduler for coroutines.

Class CoroutineScheduler

CoroutineScheduler:new () Creates a new CoroutineScheduler.
coroutineScheduler:schedule (cr[, daemon=false[, at=0]]) Schedules the specified coroutine.
coroutineScheduler:stop () Stops this scheduler from running.
coroutineScheduler:run () Runs this scheduler.


Class CoroutineScheduler

A CoroutineScheduler class. A CoroutineScheduler provides a way to coordinate mutliple coroutines.
CoroutineScheduler:new ()
Creates a new CoroutineScheduler.

Returns:

    a new CoroutineScheduler
coroutineScheduler:schedule (cr[, daemon=false[, at=0]])
Schedules the specified coroutine. When yielding the coroutine may indicate the delay or timestamp before this scheduler shall resume it. Using a negative delay indicates that the coroutine shall be resumed at soon at possible. If the yield value is a coroutine then it is scheduled with this scheduler. When a scheduled coroutine dies it is removed from this scheduler

Parameters:

  • cr The coroutine or function to add to this scheduler.
  • daemon true to indicate that the coroutine will not stop the scheduler from running (default false)
  • at An optional time for the first resume (default 0)

Usage:

    local scheduler = CoroutineScheduler:new()
    scheduler:schedule(function ()
      while true do
        print('Hello')
        coroutine.yield(15000) -- resume in 15 seconds
      end
    end, true)
    scheduler:run()
coroutineScheduler:stop ()
Stops this scheduler from running.
coroutineScheduler:run ()
Runs this scheduler. If there are no schedule for some time then this scheduler will sleep. When there is no more scheduled coroutine then the scheduler stop running.
generated by LDoc 1.4.6 Last updated 2022-01-22 16:32:56