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

tinylet

v0.1.0

Published

🎨 redlet() and greenlet() threading helpers for Node.js, Deno, and the browser

Downloads

8

Readme

🚧 Under construction 👷‍♂️

tinylet

🎨 redlet() and greenlet() threading helpers for Node.js, Deno, and the browser

⏱ Run an async function synchronously with redlet()
🏃‍♂️ Offload a heavy function to a Worker with greenlet()
🌳 Fully tree-shakable
🦕 Supports Deno!
💻 Works in the browser
⚠️ redlet() requires enabling SharedArrayBuffer in the browser

Installation

npm Yarn pnpm jsDelivr

You can install this package using npm, Yarn, or pnpm:

npm install tinylet

If you're using Deno, you can import this package from an npm CDN like ESM>CDN or jsDelivr. You can also use Deno's new npm: specifier to import this package directly from npm!

import {} from "https://esm.run/tinylet";
import {} from "npm:tinylet";

If you're in the browser using a <script type="module"> tag, you can import this package straight from an npm CDN like ESM>CDN or jsDelivr!

<script type="module">
  import {} from "https://esm.run/tinylet";
</script>

Usage

Node.js Deno Browser

📚 Find more examples and docs on the documentation website!

You can use greenlet() to run a function asynchronously in a web worker! This is great for offloading complicated synchronous work (like image processing) to a web worker so that it doesn't block the main thread.

import { greenlet } from "tinylet";

// Runs asynchronously in a worker thread.
const f = greenlet((a, b) => {
  let n = 0;
  for (let i = 0; i < 1000000000; i++) {
    if (i % 5 === 0) n += a;
    if (i % 10 === 0) n -= i;
    if (i % 60 === 0) n *= 2;
    if (i % 75 === 0) n /= b;
  }
  return n;
});
// Takes ~3 seconds to run, but doesn't block the main thread!
console.log(await f(1, 200));
//=> -2066010092.990183

If you want to go the other way and run an async function in a worker thread, but still get the result back synchronously in the current thread, you can use redlet()! This is useful when you absolutely need something to be synchronous (like for WASM interop) but the underlying web API is asynchronous.

import { redlet } from "tinylet";

// Runs in a worker thread and uses Atomics.wait() to block the current thread.
const f = redlet(async (u) => {
  const response = await fetch(u);
  return await response.json();
});
// Takes 1 second to run and BLOCKS the current thread!
console.log(f("https://jsonplaceholder.typicode.com/todos/1"));
//=> { "userId": 1, "id": 1, "title": "delectus aut autem", "completed": false }

⚠️ redlet() works in browsers, only if you've enabled SharedArrayBuffer. Even then, you can't call redlet() on the main thread; it only works in worker threads. This is because browsers don't allow Atomics.wait() to be called on the main thread.

redlet() will always work in Node.js and other server-side environments like Deno. Those contexts all enable SharedArrayBuffer by default, and support Atomics.wait() on the main thread! 🎉

Development

TODO: Add development blurb