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

ework

v0.4.0

Published

[![NPM version][npm-image]][npm-url] [![build status][ci-image]][ci-url] [![npm download][download-image]][download-url]

Downloads

32

Readme

ework

NPM version build status npm download

Ework.

Execute your tasks on another thread or in parallel, with a simple to use and cross-platform (Node.js >=10 and modern browsers) API.

Installation

$ npm i ework

Usage

import { Ework } from 'ework';

async function run() {
  const worker = new Ework((value) => value ** 2);
  const value = await worker.execute(6); // 36
  const values = await worker.map([1, 2, 3]); // [1, 4, 9]
  await worker.terminate();
}

run().catch((e) => {
  console.error(e);
  process.exit(1);
});

API

new Ework(executor[, options])

executor

Must be a function or async function. It will receive the argument passed to execute(). The code of this function will be passed to the worker, but not its context, so it shouldn't use variables from its surrounding scope.

options

An object with the following optional properties:

  • init: Function Initialization function that will be executed after spawning the worker and before sending jobs to it. If the function returns a Promise, it will be awaited.
  • initData: any Optional data passed to the init function of each spawned worker.
  • numWorkers: number Number of workers to spawn. If this option is specified, maxWorkers and minFreeThreds will be ignored.
  • maxWorkers: number (Default: number of logical CPUs) Maximum number of workers that will be spawned. This number must be at least one and is only taken into account if smaller than the total number of CPUs.
  • minFreeThreads: number (Default: 1) Minimum number of CPU threads that will be kept free. Along with maxWorkers, this will determine the number of workers that will be spawned. If there is only one CPU, this option is ignored and one worker will be spawned.

Ework#execute(value)

Run the executor on one of the free workers with the passed value. Returns a Promise that will be resolved with the value returned from the executor. If no worker is free, the call is added to a FIFO queue.

Ework#map(iterable)

Send each value of the iterable to the executor. Once every value was processed, resolves with an array of results.

Ework#terminate

Terminate all the spawned workers. This must be called to cleanup if the ework instance won't be used anymore.

License

MIT