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, and can also 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 through the shared Fiber object, the current fiber is obtained through coroutine.current , and the purpose of sharing data is achieved 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, the local variables of the current fiber are automatically copied 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 the fiber call

1
readonly Fiber Fiber.caller;

stack

String, query the call stack of the fiber

1
readonly String Fiber.stack;

Member function

join

Waiting for the fiber end

1
Fiber.join();

toString

Returns a string representation of the object, usually "[Native Object]". Objects can be reimplemented according to their own characteristics

1
String Fiber.toString();

Returns the result:

  • String , returns a string representation of the object

toJSON

Returns a JSON representation of the object, typically returning a collection of readable properties defined by the object

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

Call parameters:

  • key : String, unused

Returns the result:

  • Value , returns a value containing a JSON serializable