Fiber lock object
Unlike the lock of the operating system, the fiber lock is implemented by pure logic, and the load of locking and unlocking is very small
1 2 3 4var l = new coroutine.Lock(); l.acquire(); ..... l.release();
Take ownership of the lock
1Boolean Lock.acquire(Boolean blocking = true);
- blocking : Boolean, specify whether to wait, wait if true, default is true
- Boolean , returns whether the lock was successfully acquired, true means successful acquisition
The acquire method is used to acquire the ownership of the lock. When the lock is in an acquireable state, this method returns true immediately.
When the lock is unavailable and blocking is true, the current fiber goes to sleep. When other fibers release the lock, this method returns true.
When the lock is not available and the blocking is false, the method returns false.
Release ownership of the lock
This method will release the ownership of the lock. If the current fiber does not own the lock, this method will throw an error.
Query the current number of waiting tasks
- Integer , returns the number of tasks
Returns the string representation of the object, generally returns "[Native Object]", the object can be reimplemented according to its own characteristics
- String , returns a string representation of the object
Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object
1Value Lock.toJSON(String key = "");
- key : String, unused
- Value , returns a value containing JSON serializable