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

athome

v0.4.1

Published

Task Distribution

Downloads

11

Readme

AtHome npm Coverage Status Node CI

@Home

Tiny and elegant Cluster state manager.

  • Task pulling
  • Result validation
  • Error retries
  • Built in status

Install

npm install athome -S

Usage

const AtHome = require('athome')
const atHome = new AtHome()

const clusterId = atHome.join((n, m) => n + m)
atHome.pull(clusterId)
// Since there is no tasks, this pull will be added to pulls waiting list.

atHome.execute(3, 4)
  .then(console.log) // => 7

More realistic use case:

const AtHome = require('athome')
const atHome = new AtHome()

const functionTakesLongLongTimeRunsFarFarAway = n => new Promise(resolve => setTimeout(() => resolve(n * n), 1000))

const clusterId = atHome.join(functionTakesLongLongTimeRunsFarFarAway)

atHome.execute(8).then(console.log)
// Since there is no pulls, the task will be added to waiting list

atHome.pull(clusterId)
// A second later, output 64

With built in validator:

const AtHome = require('athome')

const atHome = new AtHome({ validator: result => result > 0 })
// result must be greater than 0

const reverse = n => new Promise(resolve => setTimeout(() => resolve(-n), 1000))
const stay = n => new Promise(resolve => setTimeout(() => resolve(n), 1000))

const reverseId = atHome.join(reverse)
const stayId = atHome.join(stay)

atHome.pull(reverseId)
atHome.pull(reverseId)
atHome.pull(stayId)


atHome.execute(-3).then(console.log)
atHome.execute(2).then(console.log)

// First -3 will go throw 1st reverse pull and output 3,
// the second 2 will go throw 2nd reverse pull and output -2,
// which will falls the validation, so it will go again with the 3rd stay pull,
// and output 2, which pass the validation.
// output: 3, 2

API Document

new Athome(options)

return atHome instance.

| Options | Type | Detail | Default | | --------- | --------------------------- | ---------------------------------- | ------------ | | validator | Function => Promise/Boolean | A function used to validate result | () => true | | retries | Number | Max retries limit | 5 |

atHome.join(clusterFunction)

Add a cluster to @Home network.

clusterFunction: function will be called with all params when this cluster is executing task.

return: String HomeID, cluster uuid

atHome.pull(id)

Pull task for this cluster, the correspond clusterFunction will be called when there is task available.

id: clutser's uuid

return: Promise<boolean> if this compute succeed

atHome.execute(data)

Execute a task.

The task will be either executed now if there is waiting pulls, or added to task waiting list for pulls.

params: params which pass to clusterFunction

return: Promise resolve the result, or reject when retries too much.

atHome.quit(id)

Remove a cluster from @Home network, this will also:

  • remove the cluster from pulling list;
  • fall all running task of this cluster;
    • which will then be handled by a different cluster;
    • (or reject task if the task reachs retries limit).

id: cluster's uuid

atHome.homes: Map<HomeID, Home>

Map with HomeID(uuid) and Home Instances.

Home Instance

home.id HomeID(uuid)

home.resolves number

Number of resolves.

home.rejects number

Number of rejects, include invalid response.

home.lastSeen number

Time stamp, refresh when:

  • join
  • pull
  • finish task

Contribution

Feel free to ask any question and create pull request :D