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

glassfiber

v1.0.10

Published

Co-routines implemented using Promises

Downloads

15

Readme

NPM version Downloads Rate on Openbase Lib Size Code Quality

Glassfiber is an intuitive Javascript co-routine library implemented using Promises.

Requirements

It runs inside any webbrowser or NodeJS environment supporting at least ECMAScript ES2018.

Minified and gzip-compressed, it is less than 1 KB of code.

It has zero dependencies on other modules.

Basic usage

Example:

var Glassfiber = require("glassfiber.min.js");

async function threadA(a, b) {
  console.log("A starting");
  await Glassfiber.yield();
  console.log(a);
  await Glassfiber.sleep(1000);
  await Glassfiber.yield();
  console.log(b);
  await Glassfiber.yield();
  console.log("A done");
}

async function threadB(a, b, c) {
  console.log("B starting");
  await Glassfiber.yield();
  console.log(a);
  await Glassfiber.yield();
  await Glassfiber.sleep(500);
  console.log(b);
  await Glassfiber.yield();
  console.log(c);
  await Glassfiber.yield();
  console.log("B done");
}

async function threadC(a) {
  console.log("C starting");
  await Glassfiber.yield();
  await Glassfiber.sleep(250);
  console.log(a);
  await Glassfiber.yield();
  console.log("C done");
}

async function main() {
  var p1 = Glassfiber.spawn( threadA(12, 13) );
  var p2 = Glassfiber.spawn( threadB(14, 15, 16) );
  var p3 = Glassfiber.spawn( threadC(17) );
  await Promise.all([p1, p2, p3]);
}

main();

Reference documentation

API

Specified parameters:

  • priority is an optional priority Can be 0, 1, 2 or 3 (defaults to 0 if omitted).
  • ms delay in milliseconds

Exposed API-list (in NodeJS and the browser):

  • Glassfiber.spawn(promise) Spawn a new co-routine. Passes through the promise.
  • Glassfiber.yield(priority?) Give other coroutines a chance to run, specifying our own priority (lower numbers are more important). Returns a Promise.
  • Glassfiber.sleep(ms) Sleeps for this many milliseconds, returns a Promise.

References

Card-carrying member of the zerodeps movement.