Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

glassfiber

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glassfiber

Co-routines implemented using Promises

  • 1.0.10
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Glassfiber

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.

Keywords

FAQs

Package last updated on 14 Dec 2023

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