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

gen-prom

v1.0.1

Published

Promise version of gen-run to use generators as async/await in node 4.x and 6.x

Downloads

4

Readme

gen-prom

This is a simple library for consuming promise based APIs using generators to simulate async/await syntax in much older environments (such as the current LTS release of nodeJS when this was created.)

Install

npm install --save gen-prom

Usage

The only export is a run(iter) -> Promise function that expects a generator iterator instance and returns a promise that will be resolve when the generator runs to completion or fails on uncaught exception.

'use strict';
let run = require('gen-prom');

// A simple promise-returning async function that works in ES2016
// Waits ms delay before resolving.
// Emulates `async` function that we would be consuming
function sleep(ms) {
  return new Promise(function (resolve) {
    setTimeout(resolve, ms);
  });
}


// A generator function used to simulate `await` when consuming promises.
function* test() {
  console.log('Counting...');
  for (let i = 0; i < 10; i++) {
    yield sleep(200);
    console.log(i);
  }
  return 42;
}

// Create an iterator from the generator function
let iterator = test();
// Run it through gen-prom to act as promise awaiting async function.
run(iterator).then(function (result) {
  console.log('done!', result);
}).catch(function (err) {
  console.error('error!', err);
});

Supported Environments

This should work on any JS environment that ES6 Promise globally and ES6 generator syntax support. This means nodeJS newer than 0.10.x and any modern browser.

Tested on:

  • nodeJS v0.11.16 (with --harmony_generators flag)
  • nodeJS v0.12.18 (with --harmony_generators flag)
  • ioJS v1.8.4
  • ioJS v2.5.0
  • ioJS v3.3.1
  • nodeJS v4.8.0
  • nodeJS v5.12.0
  • nodeJS v6.10.0
  • nodeJS v7.7.1

Notice that starting with nodeJS v7.7.x there is built-in async/await syntax support that is better than this workaround.

Also tested on:

  • Chrome 56.0.2924.87
  • Firefox 52.0
  • Safari 10.0.3