Socket
Socket
Sign inDemoInstall

watch-notify

Package Overview
Dependencies
2
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    watch-notify

The omnipresent publish subscribe design pattern.


Version published
Weekly downloads
27
decreased by-58.46%
Maintainers
1
Install size
16.2 kB
Created
Weekly downloads
 

Readme

Source

Watch notify

The omnipresent publish subscribe design pattern. The observers are called in the same order that they are added. If an observer throws an error when executed, the exception is caught and the execution continue to the next one.

Installation

npm install watch-notify

How to use

Require and initialize watch-notify:

var watchNotify = require("watch-notify");

var watchNotify = new WatchNotify();

Watch on a specific topic:

var handle = watchNotify.watch("topic", function handler(message) {
  // this === scope
}, scope /* optional */);

The topic can also be a number:

var handle = watchNotify.watch(1337, function handler() { ... });

Notify on a specific topic:

watchNotify.notify("topic", "hi!");

Several types can be given to notify:

watchNotify.notify("topic", "message1", "message2", anObject, ...);

Remove an observer:

watchNotify.unwatch(handle);

Observe only once. The handler will be called once and then removed, so any new message on topic won't trigger it.

var handle = watchNotify.once("topic", function handler() { ... });

Remove the handler before it's even called for the first time:

watchNotify.unwatch(handle);

CHANGELOG

0.0.3 - 7 APR 2015

  • console.error when an observer throws an error to help with debugging

LICENSE

MIT

Keywords

FAQs

Last updated on 08 Apr 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc