class

Tryst::TaskContext(Result)

Inherits Reference < Object

Context passed to the work block.

Constructors

new(output_queue : Channel(BackgroundDone | BackgroundProgress(Result) | BackgroundUserMessage | BackgroundFailure), message_queue : Channel(BackgroundMessage))
Source

Instance methods

check_message

Non-blocking check for messages from main thread. Returns the message, or nil if none. Crystal's select/else (used here) checks emptiness and receives atomically, unlike ruby-tryst's separate #empty?-then-#pop(true) - so there's no equivalent race to rescue ThreadError for. Checks @pending first.

Source
check_pause

Check pause state, blocking while paused. A String message drained along the way is buffered onto @pending, not discarded.

Source
send_message(msg : String) : Nil

Send a message back to the main thread (not a result).

Source
wait_message

Blocking wait for the next message. Checks @pending first.

Source
yield(value : Result) : Nil

Yield a result to the main thread.

Source

Nested types