Skip to content

LostEclair/event-bus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Documentation

(make-event-bus)

make-event-bus returns a closure, which can receive a set of messages. Provide #t if you want your event-bus throwing error when same procedure is added multiple times to the same event (#f to disable)

Messages

The bus mentioned here is a scheme object, which was created by the make-event-bus

‘go!

Runs all events

‘propagate!

Calls all of the event receivers, with given set of arguments.

(bus 'propagate! 'event 'next-come-the-arguments)

‘has-attached?

Checks if the receiver has been attached to the event.

‘attach!

Attaches a receiver function to the event. You cannot duplicate receivers. If #t was provided to make-event-bus, additional check will be executed to ensure that the procedure is unique for that event

(define (some-receiver symbol)
  (format #t "Got a symbol: ~A~%" symbol))

(define (some-other-receiver symbol)
  (format #t "Hey, thats a symbol: ~A~%" symbol))

(bus 'attach! 'symbol some-receiver)
(bus 'attach! 'symbol some-other-receiver)

(bus 'propagate! 'symbol 'foo) ; Those two functions get called.

‘detach!

Detaches a receiver function from an event.

(define (some-receiver symbol)
  (format #t "Got a symbol: ~A~%" symbol))

(bus 'attach! 'symbol some-receiver)
(bus 'detach! 'symbol some-receiver)

(bus 'propagate! 'symbol 'foo) ; Nothing will happen

‘reset!

Resets a bus to an initial state.

(define (some-receiver symbol)
  (format #t "Got a symbol: ~A~%" symbol))

(bus 'attach! 'symbol some-receiver)
(bus 'attach! 'another-symbol some-receiver)

(bus 'reset!) ; => bus is empty

‘dump-bus

Dumps the internal bus hashtable

(hashtable-values (bus 'dump-bus))
;; => #(((#{ebus-procedure-token: fx3240cs5gwemy2596v1k6lcv-5}
;;         .
;;         #<procedure>)))

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors