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, specifies the function executed by the fiber
  • args : ..., a sequence of variable parameters, this sequence will be passed to the function in the fiber

Return result:

  • Fiber , returns the 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, 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 executed in parallel
  • 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 repeated 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 current fiber for the specified time

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

Call parameters:

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

Static properties

fibers

Array, returns all the currently running fiber arrays

1
static readonly Array coroutine.fibers;

spareFibers

Integer, query and set the number of idle Fiber . When the server jitter is large, the number of idle Fiber can be increased appropriately. The default is 256

1
static Integer coroutine.spareFibers;

vmid

Integer, query the current vm number

1
static readonly Integer coroutine.vmid;

loglevel

Integer, modify and query the output level of this vm to filter the output information, the default is console.NOTSET , all output

1
static Integer coroutine.loglevel;