Module jls.util.CoroutineScheduler

Provide a simple scheduler for coroutines.

The coroutines cooperates to allow concurrent programming, coroutines shall not block.

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. When the delay is more than twenty five days, it is considered as a timestamp. A negative delay indicates the schedule shall receive a timeout argument. 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) -- will resume in 15 seconds
      end
    end)
    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-29 17:26:36