Skip to content

mohayonao/ouroboros-worker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OUROBOROS WORKER

Build Status NPM Version License

WebWorker to share the code of the main thread

Installation

$ npm install ouroboros-worker

API

  • run(mainThread: function, workerThread: function): void

Example

const OuroborosWorker = require("ouroboros-worker");

function mainThread(worker) {
  worker.postMessage("hello!"); // (1) send to the worker
  worker.onmessage = function(e) { // (4) receive from the worker
    console.log(e.data); // → good bye!    
  };
}

function workerThread(self) {
  self.onmessage = function(e) { // (2) receive from the main thread
    console.log(e.data); // → hello!
    self.postMessage("good bye!"); // (3) send to the main thread
  }
}

OuroborosWorker.run(mainThread, workerThread);

License

MIT

About

WebWorker to share the code of the main thread

Resources

Stars

Watchers

Forks

Packages

No packages published