New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

majak

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

majak

Simple promise based pub/sub

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

Majak Build Status

Small promise based pub-sub/eventEmitter

Usage

Basic usage example

const Majak = require('majak');

const majacek = new Majak();

majacek.subscribe('channel', (message) => {
	return `Received message: ${message}`;
});

majacek.subscribe('channel', (message) => {
	return new Promise((resolve, reject) => {
		global.setTimeout(() => resolve('I made you wait for it'), 2000);
	});
});

majacek.publish('channel', 'Lovely message on channel')
	.then((responses) => responses.forEach(console.log));

// Outputs [
// 	'Received message: Lovely message on channel',
// 	'I made you wait for it'
// ]

API

  • new Majak(dispatcher) Creates new Majak instance

  • dispatcher: Function with following signature (subscribers, message) => Promise

    • Responsible for dispatching the event to subscribers
    • Default is based on Promise.all collecting results from subscribers
  • Majak.prototype.purge() Removes all subscriptions

  • Majak.prototype.publish(channel, message) Publishes message to all subscribers in channel

  • Majak.prototype.subscribe(channel, listener) Registers listener callback to a channel

  • Majak.prototype.unsubscribe(channel, listener) Removes callback subscription from channel

TO-DOS

  • This Readme
  • Topic style subscriptions
  • More builtin dispatchers
  • Some more tests

Keywords

promise

FAQs

Package last updated on 04 Aug 2017

Did you know?

Socket

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