Object built-in object

Object Fiber

Fiber operation object, this object cannot be created directly

use coroutine.startAfter the fiber is created, this object will be returned for fiber processing and inter-fiber communication. The main fiber function can access this fiber object through this, or throughcoroutine.current Get the current fiber.

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();

Fiber local storage is completed through the shared Fiber object, through coroutine.current Get the current fiber, modify and query its variables to achieve the purpose of sharing data.

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

When a 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

#lineWidth: 1.5 #font: Helvetica,sans-Serif #fontSize: 10 #leading: 1.6 #.this: fill=lightgray #.class: fill=white [<class>object|toString();toJSON()] [<this>Fiber|id;caller;stack;stack_usage|join()] [object] <:- [Fiber] Fiber id caller stack stack_usage join() object toString() toJSON()

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;

stack_usage

Integer, query the used stack size of the fiber

1
readonly Integer Fiber.stack_usage;

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