Object built-in object

Object Event

Event object

To achieve the purpose of controlling a group of fibers through an event (the state of the event object is of type bool)

Inheritance

Constructor

Event

Event object constructor

1
new Event(Boolean value = false);

Call parameters:

  • value : Boolean, specify whether to wait, wait when true, the default is false

Member function

isSet

Determine whether the event object is true

1
Boolean Event.isSet();

Return result:

  • Boolean , if the event is true, return true

set

Activate the event (change the event state to true) and call pulse()

1
Event.set();

pulse

Activate all fibers waiting for the event

1
Event.pulse();

clear

Reset event (change event status to false)

1
Event.clear();

wait

Waiting for an event

1
Event.wait();

acquire

Acquire lock ownership

1
Boolean Event.acquire(Boolean blocking = true);

Call parameters:

  • blocking : Boolean, specify whether to wait, wait when true, the default is true

Return result:

  • Boolean , returns whether the lock is 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 blocking is false, the method returns false.


release

Release lock ownership

1
Event.release();

This method will release the ownership of the lock. If the current fiber does not own the lock, this method will throw an error.


count

Query the current number of waiting tasks

1
Integer Event.count();

Return result:

  • Integer , returns the number of tasks

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 Event.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 Event.toJSON(String key = "");

Call parameters:

  • key : String, unused

Return result:

  • Value , returns a value containing JSON serializable