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

@bradleymeck/thenables

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bradleymeck/thenables

some simple utilities for awaiting

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

thenables

There is no index/main file. Grab the utilities as needed.

DO NOT return thenables from async functions as they will be turned into regular Promises.

iter

A thenable which is inteded to have multiple values and a done condition.

iter.Iter

A flexible way to generate an iter.

const fs = require('fs');
const iter = require('./iter');
;(async () => {
  const ee = fs.createReadStream(process.argv[2]);
  const stream = iter.Iter((onvalue, ondone, onerror) => {
    stream.on('data', onvalue);
    stream.on('error', (err) => {
      stream.removeListener('data', onvalue);
      stream.removeListener('done', ondone);
      onerror(err);
    });
    stream.on('close', (value) => {
      stream.removeListener('data', onvalue);
      stream.removeListener('error', onerror);
      ondone(value);
    });
  });
  let value, done;
  let buffered = [];
  while({value, done} = await stream, !done) {
    buffered.push(value);
  }
  const body = require('buffer').Buffer.concat(buffered);
  console.log(body.toString());
})();

iter.fromReadStream

Simplifies read stream consumption.

const fs = require('fs');
const iter = require('./iter');
;(async () => {
  const ee = fs.createReadStream(process.argv[2]);
  const stream = iter.fromReadStream(ee);
  let value, done;
  let buffered = [];
  while({value, done} = await stream, !done) {
    buffered.push(value);
  }
  const body = require('buffer').Buffer.concat(buffered);
  console.log(body.toString());
})();

semaphore

semaphore.ExclusiveSemaphore

The most general use Semaphore, it expects to stay in the same thread.

const ExclusiveSemaphore = require('./semaphore').ExclusiveSemaphore;
const semaphore = new ExclusiveSemaphore(+process.argv[2] || 1);
;(async () => {
  let {unlock} = await semaphore;
  console.log('start: A');
  await {
    then: f => setTimeout(f, 1000)
  }
  console.log('close: A');
  unlock();
})();

Keywords

FAQs

Package last updated on 05 Oct 2017

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