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

@lightningjs/threadx

v0.3.5

Published

A web browser-based JavaScript library that helps manage the communcation of data between one or more web worker threads.

Downloads

800

Readme

ThreadX (Beta)

Warning: This is beta software and all of the exposed APIs are subject to breaking changes

ThreadX is a web browser-based JavaScript library that helps manage the communcation of data between one or more web worker threads.

ThreadX handles data communcation in two ways:

One is via the standard postMessage() API. This facilitates passing of complex nested object data.

The other is via SharedArrayBuffer between two workers. ThreadX provides two base classes which can be implemented side-by-side in order to facilitate fast exchange of object properties: BufferStruct and SharedObject. The BufferStruct defines the basic structure of data as it will exist in the SharedArrayBuffer, while the SharedObject provides an API for either worker to access and set properties in a syncronous manner.

Examples on how BufferStructs and SharedObjects are used are available in our browser-tests directory and in the Lightning 3 Renderer repo.

Setup

  • npm install

Build

  • npm run build
  • npm run watch (Watch Mode)

This builds the library using the TypeScript compiler and places the output to a directory named dist.

When run in Watch Mode, the TypeScript compiler will listen for changes to files and automatically recompile

Docs

  • npm run typedoc

This builds the TypeDoc API documentation files which you can browse using your web browser from the docs folder.

Tests

  • npm run test:browser (Browser Integration Tests)
  • npm run test (Unit Tests)

There are two categories of tests run by the commands above: Unit Tests and Browser Integration Tests. When running either category, the test runner will remain open and re-run when any changes are detected to the code.

Browser Integration Tests

Browser Integration Tests focus on the user-end capabilities / features of ThreadX, such as creating/closing workers, sending messages to workers, receiving responses from workers, and using SharedObjects / BufferStructs to share data between workers. These tests use Mocha + Chai and are launched (by default) in the Chrome browser.

NOTE: The Integration Tests rely on the built assets in the dist folder. For the best live testing experience, run a build in Watch Mode at the same time as running the Integration Tests.

Unit Tests

Unit Tests focus on whatever we can test that does not rely on browser APIs such as Workers. Self-contained utility methods are great candidates for unit tests. These tests are written with Vitest which uses virtually similar testing constructs as Mocha + Chai.

Security

As a requirement, your app needs to be in a secture context. For top level documents, two headers need to be set to cross-origin isolate yout app.

  • Cross-Origin-Embedder-Policy : require-corp ( protects your origin from attackers )
  • Cross-Origin-Opener-Policy : same-origin ( protects victims from your origin )

to test if isolation is succesfull you can check the crossOriginIsolated property available in Worker and Window contexts:

if (globalThis.crossOriginIsolated) {
  // app logic
}

Atomics

Since we share memory and multiple threads can read and write to the same piece of memory, we need the Atomics object to perform atomic operations on the SharedArrayBuffer objects. Atomics make sure that operations run uninterrupted and are finished before the next will.