previous up next     contents index
Next: Units with Signatures Up: Libraries Previous: Syntax Rules

Triggers

  Files: ``trigger.ss'', ``triggeru.ss'', ``triggers.ss'', ``triggerc.ss''
Signature: mzlib:trigger tex2html_wrap_inline2054
Unit:  mzlib:trigger@

  Triggers were originally provided in MzScheme before sempahores were added to the language. Triggers have a single advantage over semaphores: multiple threads can block on a single trigger and be released at the same time.

The only actions available on a trigger are hit and test for hit. Each trigger keeps its own internal history of hits.

 

(make-trigger) (procedure)

Creates and returns a new trigger (that has never been hit).

 

(trigger? v) (procedure)

Returns #t if v is a trigger created by make-trigger or #f otherwise.

 

(trigger-hit trigger) (procedure)

Hits trigger once.

 

(trigger-hit? trigger) (procedure)

Returns #t is trigger has ever been hit (one or more times) or #f otherwise.

 

(trigger-test-and-hit? trigger) (procedure)

Performs an atomic test and hit on trigger. The trigger is only hit if it has not been hit previously. The return value is #t if the trigger had not been hit previously or #f otherwise.

 

(trigger-block trigger ever?) (procedure)

Waits until a hit appears on trigger. If ever? is #f, then the hit must happen after trigger-block starts waiting, otherwise trigger-block returns immediately if trigger has ever been hit. The ever? argument is optional; it defaults to #f.

 

(trigger-callback trigger closure) (procedure)

Installs closure to be invoked when when trigger is next hit. The trigger-callback procedure can only be used within applications that have a top-level event loop instead of a simple read-eval-print loop. (MrEd is such an application.)   The closure procedure is invoked in the thread that handles events -- usually the main thread -- in a single-threaded manner. The callback closure is invoked only once following the first hit; additional hits are ignored.

 

(input-port-trigger port trigger) (procedure)

Hits trigger when a character is ready to be read from port. The trigger is only hit once. The port is checked by periodically evaluating   (char-ready? port). (Therefore, it may be possible to read characters from port without incurring a hit on trigger. The input-port-trigger is most useful when port is read only after a hit on trigger.)


previous up next     contents index
Next: Units with Signatures Up: Libraries Previous: Syntax Rules

PLT