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

worker.io

v1.2.3

Published

workerio allow pub/sub and other cool features for interacting with web wrokers

Downloads

6

Readme

WorkerIO


Messaging pub/sub api for web workers includes Parallel libary

New: Parallel functionality - with an ability to send job and split it to sub workers More details below

The new parallel libary including those features:

  • [x] pub/sub - send and get messages from the job during proccessing
  • [x] waitAny - get a notification on the caller side when a sub worker finish its job with the result of the job.
  • [x] WaitAll - get a notification on the caller side when a the whole job is finshed includes the result of the job
  • [x] broadcasting - broadcasting message to the whole wrokers
  • [x] cancelAll - close the workers
  • [ ] limiting worker numbers- (in the next few days) an ability to limit the number of workers that will handle the job

More details below under the user instructions section

Usage instructions:

worker:

  • create a worker on a separated file

  • import workerIO lib to your worker using importScripts() then

  • init workerIO var yourWorkerName = IO.Worker();

  • call to start method you should recive your socket instance for communicating with the caller side

    yourWorkerName.start(function(socket){  
                            \\body   ....    });
  • within the start function you can recive messages by calling to on function
    socket.on("messageName",callbackFunction(Data))
  • sending messages using emit function socket.emit("messageName","Data")
  • full worker sample code
\\"testWorker.js" file
function Worker() {
  importScripts('../dist/WorkerIO.js');
  var testWorker = IO.Worker();
  testWorker.start(function(socket){
    socket.on("emitTest",function(data){
      console.log(data);

    })
    socket.emit("test","bla")
  })
  Worker();

caller:

  • init workerIO caller var yourCallerName = IO.Reciver("testWorker.js");
  • start processing the job by calling to start function
    yourCallerName.start(function(socket){
                          ...      })
  • within the start function you can recive messages by calling to on function javascript socket.on("messageName",callbackFunction(Data))

  • sending messages using emit function javascript socket.emit("messageName","Data")

  • full caller sample code

 var io= IO.Reciver("testWorker.js");
  io.start(function(socket){
    socket.on("test",function(data){
      console.log("on: "+data);
      socket.emit("emitTest","bla");
    });
    socket.emit("emitTest","bla");
  });

parallel:

  • init parallel job is done using var parallel= IO.Parallel("workerUnit.js");
  • in order to start a new job you should use
parallel.foreach([array of jobs...],function(socket,data){
      //communicating with a specific worker
      socket.emit("runParallel",data);
      socket.on("status",function(data){
        console.log("status: "+data);
      })
  • then you can register to the following events
    • on waitAny callback you will get the workerName and the result of the worker
    • on waitAll callback you will get the results from all the workers
parallel.waitAny(function(workerName,data){
    //getting message when each  worker finish its job
    console.log("WaitAny: data was procced on: "+workerName+" with result "+data);
  }).waitAll(function(data){
    //getting message when all the job finsh their job
    console.log("WaitAll: data was procced with result "+data);
  })
  • sending brodacast meesage to all of the workers is done using parallel.broadcast.emit("messageTopic",data)
  • you can also cancel to job during proccessing by using cancelAll parallel.cancelAll();

full parallel example

caller:

  //imitJob
  var parallel= IO.Parallel("workerUnit.js");
  //Setting  Job and creating wrokers
  parallel.foreach([1,2,3,4,5,6,7,8],function(socket,data){
      //communicating with a specific worker
      socket.emit("runParallel",data);
      socket.on("status",function(data){
        console.log("status: "+data);
      })
  }).waitAny(function(workerName,data){
    //getting message when each  worker finish its job
    console.log("WaitAny: data was procced on: "+workerName+" with result "+data);
  }).waitAll(function(data){
    //getting message when all the job finsh their job
    console.log("WaitAll: data was procced with result "+data);
  });
  setTimeout(function(){
    //brodcasting message to the workers
    parallel.broadcast.emit("broadcasting",":)")
  }, 6000);

  function stopJob() {
    //removing all the jobs
    parallel.cancelAll();
  }

worker:

function parallelTest() {
  importScripts('../../dist/WorkerIO.js');
  var inter= null ;
  var testWorker = IO.Worker();
  testWorker.start(function(socket){
    socket.on("runParallel",function(data){
      console.log("runParallel: "+data);
      calc_data(data);
    }).on("broadcasting",function(data){
      console.log("broadcasting: "+data);
      });

    setInterval(function () {
      socket.emit("status","!!!Not finished yet")
    },5000);
    function calc_data(data) {
      inter =  setInterval(function(){
           var calcData = data*5
           socket.returnResult(calcData);
        }, data*1000);

    }
  })
}
parallelTest();