Product Site

5.4.7.6. wait

Returns .true if waiting for the event semaphore to get posted has been successful or the semaphore is already in the posted state, and .false if a timeout occurred while waiting.

If timeout is specified it must be a TimeSpan instance or a valid Rexx number. If the value is negative or if timeout is omitted, wait suspends the current activity until the semaphore gets posted.

If timeout is zero, wait immediately returns with a return value as if isPosted had been called.

If the timeout period is positive, wait suspends the current activity for timeout seconds or until the semaphore gets posted, whatever comes first.

Any number of activities can wait for an event semaphore. When the semaphore is posted, all waiting activities are released. The exact order in which released activities resume execution is unspecified and should not be relied upon.

Example 5.241. EventSemaphore class — wait method
event = .EventSemaphore~new

say "main starts tasks"
do nr = 1 to 5
  .task~new~waitFor(event, "task" nr)
end
call SysSleep 0.1

say "main posts"
event~post
say "main ends"

::class Task

::method waitFor
  reply
  use strict arg event, name
  say name "waits"
  event~wait
  say name "runs"

may output
main starts tasks
task 2 waits
task 5 waits
task 1 waits
task 3 waits
task 4 waits
main posts
main ends
task 4 runs
task 3 runs
task 1 runs
task 2 runs
task 5 runs