npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tab-elect

v0.1.2

Published

Leader election for browser tabs and workers

Downloads

749

Readme

tab-elect Build Status npm

Leader election for browser tabs

Sauce Test Status

Tab-elect solves the problem of only wanting one browser tab to run a job, and ensure that there is always one browser tab running it even if the previous running tab was closed. This package takes care of the inter-tab communication required to elect one tab as the leader and ensure that there is always a leader even if the previous leader quits. A browser tab gets notified when it has been elected as the new leader, and this allows the tab to run whatever code the leader should run. When another tab takes the leadership position, the previous leader gets notified that it has been deposed.

Tab-elect uses the atomic operations of IndexedDB to ensure that only one leader gets elected even if many candidates attempt to elect themselves simultaneously. BroadcastChannels are used to broadcast when a new leader has taken over; because of this there is a short amount of time during the transition from one leader to another that both instances think they are the leader.

Usage

var te = TabElect('campain name')

console.log('Am I the leader?', te.isLeader)

te.on('elected', function () {
  console.log('I am the leader!')
})

te.on('deposed', function () {
  console.log('I am no longer the leader')
})

te.on('error', function (err) {
  console.log('Error', err)
})

API

var te = new TabElect(name)

Constructs a new TabElect instance with the given name. name is used to group instances together so instances with different names will have different elections.

te.isLeader

A boolean that indicates if this instance is the leader.

te.elect([cb])

Attempt to elect this instance as the leader. cb is called with cb(err, elected) where err is null if there were no errors and elected is true if the instance is now the leader. This method throws an exception if it is called while the instance is the leader.

te.stepDown()

Forces the instance to relinquish it's leadership status. All other tab-elect instances will attempt to become the next leader. If the instance is not the leader then this method throws an exception.

te.destroy()

Destroys the instance and frees all internal resources. If this instance was the leader than a new leader will be elected. No more events will be emitted.

Events

te.on('elected', function () {})

The instance is the new leader

te.on('deposed', function () {})

The instance is no longer the leader

te.on('error', function () {})

A critical error occurred. This instance attempts to relinquish it's leader status and destroys itself.

License

MIT. Copyright (c) Austin Middleton.