Simple embeddable publish-subscribe implementation.

Including LibPubSub functionality

The easiest method for utilising LibPubSub is a mixin, like so:

MyAddon = LibStub('AceAddon-3.0'):NewAddon('MyAddon', 'LibPubSub-1.0')

If you're not using AceAddon, you can still embed LibPubSub in an
object/table via LibPubSub's Embed() function:


If you don't want to embed LibPubSub's methods in your objects, you can
get a separate LibPubSub object:

local Observer = LibStub('LibPubSub-3.0'):New()

In the following examples, please replace Observer with the right


Observer:Publish(message, ...)

This calls all listeners subscribed to this message, and passes the
arguments given after the message. Multiple objects or functions can be
subscribed to the same message.


  • message (string)
    • The message to publish
  • ... (mixed)
    • Any arguments to pass to the listeners

Observer:Subscribe(message[, object][, function])

There are multiple ways to subscribe to messages, and multiple listeners
can be attached for the same message:

  • Observer:Subscribe('NAME_OF_MESSAGE') will call
  • Observer:Subscribe('NAME_OF_MESSAGE', funcref) will call funcref()
  • Observer:Subscribe('NAME_OF_MESSAGE', 'FunctionName') will call
  • Observer:Subscribe('NAME_OF_MESSAGE', Object) will call
  • Observer:Subscribe('NAME_OF_MESSAGE', Object, 'FunctionName') will
    call Object:FunctionName()

The second, third and fourth version of attaching listeners can also be
passed as a table, as shorthand for attaching listeners for multiple

  • Observer:Subscribe({NAME_OF_MESSAGE = funcref, OTHER_MESSAGE = 'FunctionName'})

The arguments passed to the listener are the arguments passed to the
Publish function after the message name.


  • message (string)
    • The message to subscribe to
  • object (table)
    • The object the function should be called on
  • function (string/funcref)
    • The function to call

Observer:Unsubscribe(message[, object][, function])

This works exactly the same as subscribing to a message. Note that you
need to pass the same arguments to Unsubscribe as you passed to
Subscribe to remove a listener for a message. That means that, if you
subscribed using Observer:Subscribe('NAME_OF_MESSAGE', funcref) you
need to unsubscribe using Observer:Unsubscribe('NAME_OF_MESSAGE', funcref).

The possible ways to call this function:

  • Observer:Unsubscribe('NAME_OF_MESSAGE')
  • Observer:Unsubscribe('NAME_OF_MESSAGE', funcref)
  • Observer:Unsubscribe('NAME_OF_MESSAGE', 'FunctionName')
  • Observer:Unsubscribe('NAME_OF_MESSAGE', Object)
  • Observer:Unsubscribe('NAME_OF_MESSAGE', Object, 'FunctionName')
  • Observer:Unsubscribe({NAME_OF_MESSAGE = funcref, OTHER_MESSAGE = 'FunctionName'})


  • message (string)
    • The message to unsubscribe from
  • object (table)
    • The object the function would be called on
  • function (string/funcref)
    • The subscribed function


Removes all currently subscribed listeners immediately.



You must login to post a comment. Don't have an account? Register to get one!


Date created
Apr 17, 2013
Last updated
Apr 20, 2013