Module | Rubygame::MailQueue
In: | lib/rubygame/queue.rb

A mixin module to extend EventQueue with the ability to ‘deliver’ specific types of events to subscribed objects, a la a mailing list. Each object must subscribe for the classes of events it wishes to receive; when the MailQueue receives an event of that type, it will deliver it to the subscribers. See subscribe for more information.

Please note that if you extend an already-existing EventQueue object with this mixin module (rather than including it in a class), you must call setup before using the object. This will create the necessary internal variables for the MailQueue to work.

### Methods

deliver list new push setup subscribe subscribed? unsubscribe

### Attributes

autodeliver | [RW] | Whether to automatically deliver events as they are received. Enabled by default.

### Public Class methods

new()

Create a new MailQueue object. Like EventQueue.new, this method will yield self if a block is given.

### Public Instance methods

deliver()

Deliver each pending event to all objects which are subscribed to that event class. Every client object MUST have a push method, or events can‘t be delivered to it, and it will become very lonely!

The queue will be cleared of all events after all deliveries are done.

list()

Returns an Array of all event classes which have at least one subscriber.

push(*args)

Append events to the queue. If @autodeliver is enabled, all events on the queue will be delivered to subscribed client objects immediately.

setup()

Create the necessary internal variables for the MailQueue.

subscribe(client,klass)

Subscribe `client` to receive events that match `klass`.

After the client object has been subscribed, the MailQueue will push along any event for which "klass === event" is true. This usually means that the event is an instance of klass or one of klass‘s child classes; however, note that klass may have changed its own #=== operator to have different behavior, so this is not always the case.

Important: the MailQueue uses the client‘s push method to deliver events! If the client does not have such a method, MailQueue will silently catch the error and move on to the next client.

A client object may be subscribed for many different types of events simultaneously, and more than one client object may be subscribed to any type of event (in which case each object will receive the event). A client may also be subscribed multiple times for the same type (in which case it will receive duplicate events). Likewise, the client will receive duplicates if it is subscribed to multiple classes which share ancestry, for example Numeric and Float.

If a client wishes to receive ALL types of events, it can subscribe to Object, which is a parent class of all objects.

If the queue‘s @autodeliver is true, it will deliver events to subscribers immediately after they are posted, rather than waiting for deliver to be called.

subscribed?(client,klass)

Returns true if `client` is currently subscribed to receive events of type `klass`.

unsubscribe(client,klass)

Unsubscribes the client to stop receiving events of type `klass`. It is safe (has no effect) to unsubscribe for an event type you are not subscribed to receive.

[Validate]