Skip to main content
Version: Next

New signal

New signal { ( description : Text ) } : 4D.Signal

ParameterTypeDescription
descriptionTextDescription for the signal
Function result4D.SignalNative object encapsulating the signal
History
ReleaseChanges
17 R4Added

Description

The New signal command creates a 4D.Signal object.

A signal is a shared object which can be passed as parameter from a worker or process to another worker or process, so that:

  • the called worker/process can update the signal object after specific processing has completed
  • the calling worker/process can stop its execution and wait until the signal is updated, without consuming any CPU resources.

Optionally, in the description parameter you can pass a custom text describing the signal. This text can also be defined after signal creation.

Since the signal object is a shared object, it can also be used to maintain user properties, including the .description property, by calling the Use...End use structure.

Returned value

A new 4D.Signal object.

Example

Here is a typical example of a worker that sets a signal:

 var $signal : 4D.Signal
$signal:=New signal("This is my first signal")

CALL WORKER("myworker";"doSomething";$signal)
$signaled:=$signal.wait(1) //wait for 1 second max

If($signaled)
ALERT("myworker finished the work. Result: "+$signal.myresult)
Else
ALERT("myworker has not finished in less than 1s")
End if

The doSomething method could be like:

 #DECLARE ($signal : 4D.Signal)
//any processing
//...
Use($signal)
$signal.myresult:=$processingResult //return the result
End use
$signal.trigger() // The work is finished