ObjectFiber
Fiber operation object, this object cannot be created directly
usecoroutine.startAfter the fiber is created, this object is returned and used for fiber processing and inter-fiber communication. The fiber main function can access this fiber object through this, or throughcoroutine.currentGet the current fiber.
1
2
3
4
5
6
7
8
9function func(v1) {
console.log(v1 + this.v);
}
var fb = coroutine.start(func, 100);
fb.v = 123;
fb.join();
Fiber local storage is accomplished through shared Fiber objects, throughcoroutine.currentGet the current fiber and achieve the purpose of sharing data by modifying and querying its variables.
1
2
3
4
5
6
7function 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, modifications to the respective local variables will not affect each other unless the variables themselves are object references.
1
2
3
4
5
6
7
8
9
10
11function func() {
console.log(coroutine.current().v);
}
coroutine.current().v = 100;
var fb = coroutine.start(func);
coroutine.current().v = 200;
fb.join();
inheritance relationship
member properties
id
Long, query the unique id of the fiber
1readonly Long Fiber.id;
caller
Fiber, the calling fiber of the query fiber
1readonly Fiber Fiber.caller;
stack
String, query the call stack of the fiber
1readonly String Fiber.stack;
stack_usage
Integer, query the stack size used by the fiber
1readonly Integer Fiber.stack_usage;
member function
join
Wait for fiber to end
1Fiber.join();
toString
Returns the string representation of the object. Generally, "[Native Object]" is returned. The object can be re-implemented according to its own characteristics.
1String Fiber.toString();
Return results:
- String, returns the string representation of the object
toJSON
Returns a JSON format representation of the object, generally returning a collection of readable properties defined by the object.
1Value Fiber.toJSON(String key = "");
Call parameters:
- key: String, not used
Return results:
- Value, returns a value containing JSON serializable