Module basic module

Module coroutine

Concurrency Control Module

Reference method:

1
var coroutine = require('coroutine');

Object

Lock

Lock object, see Lock

1
Lock coroutine.Lock;

Semaphore

Semaphore object, see Semaphore

1
Semaphore coroutine.Semaphore;

Condition

Condition variable object, see Condition

1
Condition coroutine.Condition;

Event

Event object, see Event

1
Event coroutine.Event;

Worker

Independent thread work object, see Worker

1
Worker coroutine.Worker;

Static function

start

Start a fiber and return to the fiber object

1 2
static Fiber coroutine.start(Function func, ...args);

Call parameters:

  • func: Function, specify the function to be executed by the fiber
  • args: ..., variable parameter sequence, this sequence will be passed to the function in the fiber

Return result:

  • Fiber, Return fiber object

parallel

Execute a set of functions in parallel and wait for the return

1 2
static Array coroutine.parallel(Array funcs, Integer fibers = -1);

Call parameters:

  • funcs: Array, an array of functions executed in parallel
  • fibers: Integer, limit the number of concurrent fibers, the default is -1, enable the same number of fibers as funcs

Return result:

  • Array, Returns an array of function execution results

Execute a function in parallel to process a set of data and wait for the return

1 2 3
static Array coroutine.parallel(Array datas, Function func, Integer fibers = -1);

Call parameters:

  • datas: Array, data array for parallel execution
  • func: Function, function executed in parallel
  • fibers: Integer, limit the number of concurrent fibers, the default is -1, enable the same number of fibers as datas

Return result:

  • Array, Returns an array of function execution results

Execute a function multiple times in parallel and wait for return

1 2 3
static Array coroutine.parallel(Function func, Integer num, Integer fibers = -1);

Call parameters:

  • func: Function, the number of functions executed in parallel
  • num: Integer, the number of repetitive tasks
  • fibers: Integer, limit the number of concurrent fibers, the default is -1, enable the same number of fibers as funcs

Return result:

  • Array, Returns an array of function execution results

Execute a set of functions in parallel and wait for the return

1
static Array coroutine.parallel(...funcs);

Call parameters:

  • funcs: ..., a set of functions executed in parallel

Return result:

  • Array, Returns an array of function execution results

current

Returns the current fiber

1
static Fiber coroutine.current();

Return result:

  • Fiber, The current fiber object

sleep

Pause the time specified by the current fiber

1
static coroutine.sleep(Integer ms = 0) async;

Call parameters:

  • ms: Integer, specify the time to be suspended, in milliseconds, the default is 0, that is, if there is free time, it will resume operation immediately

Static properties

fibers

Array, returns all currently running fiber arrays

1
static readonly Array coroutine.fibers;

spareFibers

Integer, query and set idle Fiber Number, the idleness can be increased moderately when the server jitter is large Fiberquantity. The default is 256

1
static Integer coroutine.spareFibers;

vmid

Integer, query current vm serial number

1
static readonly Integer coroutine.vmid;

loglevel

Integer, modify and query this vm The output level, used to filter the output information, the default is console.NOTSET, All output

1
static Integer coroutine.loglevel;