New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bs-webworkers

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bs-webworkers

Bucklescript bindings for Web Workers

  • 0.2.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Reason Bindings for the Web Workers API

This repository contains bindings for the Web Workers API.

Read more about these here, but keep in mind these bindings have been improved since this article was written.

Example

The main script creates a new Web Worker from the worker.re script and posts a message to it. The Web Worker replies back to that message. The main thread listens to that and prints out the message it received from the Web Worker.

main.re

let worker = WebWorkers.create_webworker("worker.bs.js");

let msg = {"text": "Hello world"};

WebWorkers.postMessage(worker, msg);

let msgBackHandler = (e: WebWorkers.MessageEvent.t) => {
  Js.log("I am the main thread and I have received a message back from the worker:");
  Js.log(WebWorkers.MessageEvent.data(e))
};

WebWorkers.onMessage(worker, msgBackHandler);

worker.re

WebWorkers.setWorkerOnMessage(
  WebWorkers.self,
  (e: WebWorkers.MessageEvent.t) => {
    Js.log("I am the Web Worker and I have received a message:");
    Js.log(WebWorkers.MessageEvent.data(e));
    WebWorkers.postMessageFromWorker("my result")
  }
);

Installation

  1. Install the bindings using npm install --save bs-webworkers
  2. Add the bindings to bsconfig.json:
{
  "bs-dependencies": [
      "bs-webworkers"
  ]
}

Look in the example/ directory for an example of how to use the bindings.

Build

npm install
npm run build

Tests

npm install
npm run test

Demo

npm install
npm run example

Todo

The full Web Workers API is still not yet implemented (e.g. Shared Workers, Service Worker, WorkerNavigator, WorkerLocation, etc.). PRs are welcome!

Keywords

FAQs

Package last updated on 21 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc