Object built-in object

Object Fiber

Fiber operation object, this object cannot be created directly

After creating a fiber using coroutine.start , this object will be returned for fiber processing and inter-fiber communication. The main fiber function can access this fiber object through this, or get the current fiber through coroutine.current .

1 2 3 4 5 6 7 8 9
function func(v1) { console.log(v1 + this.v); } var fb = coroutine.start(func, 100); fb.v = 123; fb.join();

The fiber local storage is completed by the shared Fiber object, the current fiber is obtained through coroutine.current , and the data is shared by modifying and querying its variables.

1 2 3 4 5 6 7
function func() { console.log(coroutine.current().v); } coroutine.current().v = 100; func();

When the fiber is created, it will automatically copy the local variables of the current fiber to the new fiber. After that, the modification of the respective local variables will not affect each other unless the variable itself is an object reference.

1 2 3 4 5 6 7 8 9 10 11
function func() { console.log(coroutine.current().v); } coroutine.current().v = 100; var fb = coroutine.start(func); coroutine.current().v = 200; fb.join();

Inheritance

Member attributes

id

Long, query the unique id of the fiber

1
readonly Long Fiber.id;

caller

Fiber, query fiber calling fiber

1
readonly Fiber Fiber.caller;

stack

String, query the call stack of the fiber

1
readonly String Fiber.stack;

Member function

join

Wait for fiber to end

1
Fiber.join();

toString

Returns the string representation of the object, generally returns "[Native Object]", the object can be re-implemented according to its own characteristics

1
String Fiber.toString();

Return result:

  • String , returns the string representation of the object

toJSON

Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object

1
Value Fiber.toJSON(String key = "");

Call parameters:

  • key : String, unused

Return result:

  • Value , returns a value containing JSON serializable