The event-emitter Reference Manual

Next: , Previous: , Up: (dir)   [Contents][Index]

The event-emitter Reference Manual

This is the event-emitter Reference Manual, version 0.0.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Thu Sep 15 04:41:49 2022 GMT+0.

Table of Contents


1 Introduction

Event Emitter

Event Emitter provides an event mechanism like Node.js for Common Lisp objects.

Mostly ported from Node.js 'events' module.

Usage

;; Defining Event Emitter class.
(defclass person (event-emitter)
  ((name :initarg :name
         :reader name)))

(defvar *user*
  (make-instance 'person :name "Eitaro Fukamachi"))

;; Attach a event listener for an event ':say-hi'.
(on :say-hi *user*
    (lambda () (format t "Hi!")))

;; *user* says 'Hi!' when an event ':say-hi' is invoked.
(emit :say-hi *user*)
;-> Hi!

(emit :say-hi *user*)
;-> Hi!

(emit :say-hi *user*)
;-> Hi!

;; Attach an one time event listener.
(once :say-hi *user*
      (lambda ()
        (format t "How's it going?")))

;; 'Hi!' and "How's it going?" will be printed.
(emit :say-hi *user*)
;-> Hi!
;   How's it going?

;; *user* doens't say "How's it going?" anymore.
(emit :say-hi *user*)
;-> Hi!

(emit :say-hi *user*)
;-> Hi!

'event-glue'

There's already similar library named event-glue which you may like to know.

API

[Class] event-emitter

Base standard class for 'event-emitter's.

(defclass person (event-emitter)
  ((name :initarg :name)))

[Strucuture] event-emitter*

Base strucuture class for 'event-emitter's.

(defstruct (person :include event-emitter*)
  name)

[Function] (add-listener object event listener)[Function] (on event object listener)

Adds a listener to the end of the listeners array for the specified event.

(on :connection server
    (lambda (stream) ...))

NOTE: add-listener and on takes 'object' and 'event' the opposite order.

[Function] (once event object listener)

Adds a one time listener for the event. This listener is invoked only the next time the event is fired, after which it is removed.

(once :connection server
      (lambda (stream) ...))

[Function] (remove-listener object event listener)

Removes a listener from the listener array for the specified event.

(defun connection-cb (stream)
  ...)

(on :connection server #'connection-cb)
(remove-listener server :connection #'connection-cb)

[Function] (remove-all-listeners object &optional event)

Removes all listeners, or those of the specified event.

(remove-all-listeners server)
(remove-all-listeners server :connection)

[Function] (listeners object event)

Returns an array of listeners for the specified event.

[Function] (emit event object &rest args)

Executes each of the listeners in order with the supplied arguments.

Returns T if the event had listeners, NIL otherwise.

[Function] (listener-count object event)

Returns the number of listeners for a given event.

Copyright

Copyright (c) 2014 Eitaro Fukamachi (e.arrows@gmail.com)

License

Licensed under the BSD 2-Clause License.


2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 event-emitter

Event mechanism for Common Lisp objects

Author

Eitaro Fukamachi

License

BSD 2-Clause

Version

0.0.1

Source

event-emitter.asd.

Child Component

src/event-emitter.lisp (file).


3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


3.1.1 event-emitter/event-emitter.asd

Source

event-emitter.asd.

Parent Component

event-emitter (system).

ASDF Systems

event-emitter.

Packages

event-emitter-asd.


3.1.2 event-emitter/src/event-emitter.lisp

Source

event-emitter.asd.

Parent Component

event-emitter (system).

Packages

event-emitter.

Public Interface
Internals

4 Packages

Packages are listed by definition order.


Next: , Previous: , Up: Packages   [Contents][Index]

4.1 event-emitter-asd

Source

event-emitter.asd.

Use List
  • asdf/interface.
  • common-lisp.

Previous: , Up: Packages   [Contents][Index]

4.2 event-emitter

Source

src/event-emitter.lisp.

Use List

common-lisp.

Public Interface
Internals

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Public Interface


5.1.1 Ordinary functions

Function: add-listener (object event listener)
Package

event-emitter.

Source

src/event-emitter.lisp.

Function: emit (event object &rest args)
Package

event-emitter.

Source

src/event-emitter.lisp.

Function: listener-count (object event)
Package

event-emitter.

Source

src/event-emitter.lisp.

Function: listeners (object event)
Package

event-emitter.

Source

src/event-emitter.lisp.

Function: on (event object listener)
Package

event-emitter.

Source

src/event-emitter.lisp.

Function: once (event object listener)
Package

event-emitter.

Source

src/event-emitter.lisp.

Function: remove-all-listeners (object &optional event)
Package

event-emitter.

Source

src/event-emitter.lisp.

Function: remove-listener (object event listener &key start)
Package

event-emitter.

Source

src/event-emitter.lisp.


5.1.2 Structures

Structure: event-emitter*
Package

event-emitter.

Source

src/event-emitter.lisp.

Direct superclasses

structure-object.

Direct slots
Slot: silo
Initform

(make-hash-table :test (quote eq))

Readers

event-emitter*-silo.

Writers

(setf event-emitter*-silo).


Previous: , Up: Public Interface   [Contents][Index]

5.1.3 Classes

Class: event-emitter
Package

event-emitter.

Source

src/event-emitter.lisp.

Direct slots
Slot: silo
Initform

(make-hash-table :test (quote eq))


5.2 Internals


Next: , Previous: , Up: Internals   [Contents][Index]

5.2.1 Ordinary functions

Function: %add-listener (object event listener)
Package

event-emitter.

Source

src/event-emitter.lisp.

Function: copy-event-emitter* (instance)
Package

event-emitter.

Source

src/event-emitter.lisp.

Function: copy-listener (instance)
Package

event-emitter.

Source

src/event-emitter.lisp.

Function: event-emitter*-p (object)
Package

event-emitter.

Source

src/event-emitter.lisp.

Reader: event-emitter*-silo (instance)
Writer: (setf event-emitter*-silo) (instance)
Package

event-emitter.

Source

src/event-emitter.lisp.

Target Slot

silo.

Reader: listener-function (instance)
Writer: (setf listener-function) (instance)
Package

event-emitter.

Source

src/event-emitter.lisp.

Target Slot

function.

Reader: listener-once (instance)
Writer: (setf listener-once) (instance)
Package

event-emitter.

Source

src/event-emitter.lisp.

Target Slot

once.

Function: listener-p (object)
Package

event-emitter.

Source

src/event-emitter.lisp.

Function: make-event-emitter* (&key silo)
Package

event-emitter.

Source

src/event-emitter.lisp.

Function: make-listener (function &key once)
Package

event-emitter.

Source

src/event-emitter.lisp.

Function: silo (object)
Package

event-emitter.

Source

src/event-emitter.lisp.


5.2.2 Structures

Structure: listener
Package

event-emitter.

Source

src/event-emitter.lisp.

Direct superclasses

structure-object.

Direct slots
Slot: function
Package

common-lisp.

Readers

listener-function.

Writers

(setf listener-function).

Slot: once
Readers

listener-once.

Writers

(setf listener-once).


Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts


Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   %   (  
A   C   E   F   L   M   O   R   S  
Index Entry  Section

%
%add-listener: Private ordinary functions

(
(setf event-emitter*-silo): Private ordinary functions
(setf listener-function): Private ordinary functions
(setf listener-once): Private ordinary functions

A
add-listener: Public ordinary functions

C
copy-event-emitter*: Private ordinary functions
copy-listener: Private ordinary functions

E
emit: Public ordinary functions
event-emitter*-p: Private ordinary functions
event-emitter*-silo: Private ordinary functions

F
Function, %add-listener: Private ordinary functions
Function, (setf event-emitter*-silo): Private ordinary functions
Function, (setf listener-function): Private ordinary functions
Function, (setf listener-once): Private ordinary functions
Function, add-listener: Public ordinary functions
Function, copy-event-emitter*: Private ordinary functions
Function, copy-listener: Private ordinary functions
Function, emit: Public ordinary functions
Function, event-emitter*-p: Private ordinary functions
Function, event-emitter*-silo: Private ordinary functions
Function, listener-count: Public ordinary functions
Function, listener-function: Private ordinary functions
Function, listener-once: Private ordinary functions
Function, listener-p: Private ordinary functions
Function, listeners: Public ordinary functions
Function, make-event-emitter*: Private ordinary functions
Function, make-listener: Private ordinary functions
Function, on: Public ordinary functions
Function, once: Public ordinary functions
Function, remove-all-listeners: Public ordinary functions
Function, remove-listener: Public ordinary functions
Function, silo: Private ordinary functions

L
listener-count: Public ordinary functions
listener-function: Private ordinary functions
listener-once: Private ordinary functions
listener-p: Private ordinary functions
listeners: Public ordinary functions

M
make-event-emitter*: Private ordinary functions
make-listener: Private ordinary functions

O
on: Public ordinary functions
once: Public ordinary functions

R
remove-all-listeners: Public ordinary functions
remove-listener: Public ordinary functions

S
silo: Private ordinary functions

Jump to:   %   (  
A   C   E   F   L   M   O   R   S