cl-async

Notifiers

A notifier is an object that lets you trigger a callback in your event loop thread from any other thread in a safe way. This can be very useful for triggering callbacks in your event loop thread if, say, a worker thread has finished a job and wants to let you know it’s done.

notifier

This class wraps a notifier, an object which lets you trigger a callback that runs in your event loop from another thread.

It is an opaque object meant to be passed to trigger-notifier or free-notifier.

notifier-freed-p
(defmethod notifier-freed-p ((notifier notifier)))
  => t/nil

This method lets us know if an notifier has already been freed.

make-notifier

(defun make-notifier (callback &key event-cb (single-shot t)))
  => notifier

Returns a notifier object, which can be given to trigger-notifier from any thread to trigger callback in the current event loop. This allows you to safely run code in your event loop that’s triggered by some event or action in another thread.

Note that the notifier is by default a single-shot, meaning once it is triggered it frees itself. This behavior can be changed bas passing :single-shot nil.

You can optionally pass an :event-cb function, called when errors occur while running.

trigger-notifier

(defun trigger-notifier (notifier))
  => nil

Triggers the given notifier. This can be called from any thread, and will cause the event loop to invoke the notifier’s callback in the event loop thread.

free-notifier

(defun free-notifier (notifier))
  => nil

Stops the given notifier and frees its resources.

ref

(defmethod ref ((handle notifier)))
  => nil

References the notifier, making it so that the event loop will not exit until the notifier is freed.

See unref as well.

unref

(defmethod unref ((handle notifier)))
  => nil

Unreferences the notifier. This means that even if it’s active in the event loop, the loop can exit without closing the notifier. This allows you to have open notifiers in other threads without blocking your event loop from closing.

See ref as well.