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

@redtea/wod

v0.0.9

Published

Wod is a library that provide ability to spawn the web worker instance and execute any functions into it

Downloads

2

Readme

Wod

npm npm bundle size (minified + gzip) npm type definitions Travis npm GitHub stars

Introduction

Wod is a library that provide the ability to spawn the web worker instance and execute any functions into it.

Install

$ npm install --save @redtea/wod

Usage

Package supports ES6, UMD module systems.

ES6

import { Wod, useThread } from "@redtea/wod"

Commonjs

const wod = require("@redtea/wod");

HTML

<script src="https://unpkg.com/@redtea/wod"></script>
<script>var T1 = new Wod.Wod();</script>

Examples

// Create a instance of Wod. It also spawn a new web worker instance
const Worker_1 = new Wod(); // or Wod.spawn()

// Define event listeners
const listener = (event) => console.log(event.data);
const errorListener = (event) => console.log(event.message);

// Subscribe to any message from the Worker_1 thread
// The same as WebWorker.onmessage = function() {} 
Worker_1.on('message', listener);

// Subscribe to any errors that may occure in the Worker_1 thread
// The same as WebWorker.onerror = function() {} 
Worker_1.on('error', errorListener);

// This line execute the function in the Worker_1 thread context and post the 
// message to the Main thread. As result, message 'Message from Worker_1'
// will output to console of the Main thread
Worker_1.exec(() => postMessage('Message from Worker_1'));

// Using decorator

// Create a decorator that execute the function in the Worker_1 thread
let sayHelloToTheMainThread = useThread(Worker_1)(() => postMessage('Hello from Worker1'));

// This will print 'Hello from Worker1' to console of the Main thread
sayHelloToTheMainThread();

// Catching errors

// As we was subscribe to any error event from the Worker_1 above
// this will print the error message to the Main thread's console
Worker_1.exec(() => throw 'Error from Worker_1');

// Off event listener
Worker_1.off('message', listener);
Worker_1.off('error', errorListener);

// Terminate the worker
Worker_1.terminate();

Wod

Wod.on(event: string, listener: function): void

Subscribe to event. Currently supported: message, error.

Wod.off(event: string, listener: function): void

Unsubscribe from event.

Wod.exec(prog: function[, args: any[]]): void

Execute prog in web worker thread. Optional args will be passed to prog as arguments.

// print 6
Worker.exec((a, b, c) => console.log(a + b + c), [1, 2, 3]);

Wod.terminate(): void

Terminate the web worker.

Decorator

useThread(thread: Wod)(prog: function): function

Creates a decorator over prog. Each call of the decorator execute prog in the web worker context that thread bound to.


const wrapped = useThread(WodInstance)(function(arg) { postMessage(arg); });

wrapped('hello');