Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

leave-a-message

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leave-a-message

A pub-sub pattern like event system. But instead of push message to subscribers, subscribers must manually pull message from pub-sub center.

latest
Source
npmnpm
Version
0.1.3
Version published
Maintainers
1
Created
Source

leave-a-message

A pub-sub pattern like event system. But instead of push message to subscribers, subscribers must manually pull message from pub-sub center.

Usage

import { publish, subscribe } from 'leave-a-message';

let options = {
  // If `saveHistory === false`, only the latest message would be kept,
  // otherwise, user can read an array of new messages. Default is false.
  saveHistory: true 
};

let channelName = 'channel_foo';

let { readMsg, unsubscribe } = subscribe(channelName, options);

publish(channelName, 'abc');
publish(channelName, 'def');

// Get ['def', 'abc'] or 'def' if `saveHistory === false`
console.log( readMsg() ); 

// No new messages. Get [] or undefined if `saveHistory === false`.
console.log( readMsg() ); 


unsubscribe();

// Throw error if user already unsubscribed the channel.
readMsg();

FAQs

Package last updated on 24 Mar 2018

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