eventory

1.1.9 • Public • Published

Event Hub

Event Hub provides event pub/sub.

Features:

  • synchronized callback along all async handlers
  • support Promises (promit)
  • emission timeout
  • keys with placeholder
  • key-as-function
  • defered emitting (await for postponed addition of listener)

Implementation

  • written in JS6
  • no extra dependencies

API

class EventHub

   once(key, handler): ownerId
   
   on(key, handler, ownerId): ownerId
   
   offOwner(ownerId)
   
   off(keyPrefix)
   
   emit(key, {timeoutInSeconds:10, ...params}, [callback])
  
   promit(key, {...params}).then((after)=>{})

Example

var hub = new EventHub();

hub.on('api', (params, cb)=> cb(null, params));

hub.emit('api', params, callback);

hub.off('api');

See test/test.js for more use cases.

Repo

[https://github.com/alitskevich/eventhub]

Legal

The MIT License (MIT)

Copyright (c) 2015 Alex Litskevich

Dependencies (0)

    Dev Dependencies (5)

    Package Sidebar

    Install

    npm i eventory

    Weekly Downloads

    2

    Version

    1.1.9

    License

    MIT

    Last publish

    Collaborators

    • alitskevich