Lua:Class:Event
Jump to navigation
Jump to search
<> Reference
class Event : Object
The Event class represents a synchronization event object.
An Event inherits from Object. It can be used to signal between threads or to wait until a specific condition has been set.
Contents
Inheritance[edit]
| Class | Inherits From | Description |
|---|---|---|
| Event | Object | A synchronization event object. |
Creation[edit]
<> Reference
function createEvent(ManualReset, InitialState) : Event
Creates an Event object.
Function Parameters[edit]
| Parameter | Type | Description |
|---|---|---|
| ManualReset | Boolean | If true, the event must be reset manually using resetEvent(). If false, the event automatically resets after releasing a waiting thread. |
| InitialState | Boolean | If true, the event is created in the signaled state. If false, the event is created in the non-signaled state. |
Returns[edit]
Event — The created Event object.
Properties[edit]
This class has no documented properties.
Methods[edit]
| Method | Return Type | Description |
|---|---|---|
| resetEvent() | void | Resets the event to the non-signaled state. |
| setEvent() | void | Sets the event to the signaled state. |
| waitFor(timeout) | Integer | Waits for the event to be set. Returns a wait result value. |
Wait Result Values[edit]
| Value | Constant | Description |
|---|---|---|
| 0 | wrSignaled | The event was signaled. |
| 1 | wrTimeout | The wait timed out. |
| 2 | wrAbandoned | The wait was abandoned. |
| 3 | wrError | An error occurred while waiting. |
Examples[edit]
local event = createEvent(true, false)
event.setEvent()
local result = event.waitFor(1000)
if result == wrSignaled then
print("Event was signaled")
elseif result == wrTimeout then
print("Wait timed out")
end
event.resetEvent()
local event = createEvent(false, false)
local thread = createThread(function()
sleep(1000)
event.setEvent()
end)
local result = event.waitFor(5000)
if result == wrSignaled then
print("Thread signaled the event")
else
print("Event was not signaled: " .. tostring(result))
end
See Also[edit]
Main Pages