New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gensy

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gensy

Asynchronous utils focused on generators

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
132
decreased by-0.75%
Maintainers
1
Weekly downloads
 
Created
Source

GENSY

Asynchronous utils for Node.js/IO.js focused on generators.

1. Installation

Just run the following:

npm install gensy

Remember to add gensy as a dependency in your package.json file:

"dependencies": {
	...
	"gensy": "*"
	...
}

2. Usage

Simple generator

If you just want to run a generator to run some asynchronous code as if it were synchronous (by mean of the yield statement), just call gensy as follows:

var gensy = require('gensy');

gensy(function* (next) {
	try {
		...
		var x = yield foo(next);
		...
	} catch (error) {
		console.warn('Error:', error);
	}
});

Where foo is supposed to be an asynchronous function that uses next as a callback following the error+result arguments convention:

function foo(callback) {
	...
	return callback(error, result);
}

If an error is returned by foo, then generator's catch block will be executed.

This usage supports a callback to listen generator end. To use it the generator must call done() (a second argument) when finished:

var gensy = require('gensy');

function* genA(next, done) {
	try {
		var x = yield foo(next);
		...
		return done();
	} catch (error) {
		console.warn('Error:', error);
	}
}

gensy(genA);

Generator series

To run a list of generators, one by one, use gensy.series() as follows:

var gensy = require('gensy');

function* genA (next, done) {
	try {
		var x = yield foo(next);
		...
		return done();
	} catch (error) {
		console.warn('Error:', error);
	}
}

function* genB (next, done) {
	try {
		var x = yield foo(next);
		...
		return done();
	} catch (error) {
		console.warn('Error:', error);
	}
}

gensy.series([genA, genB], function () {
	console.log('Series ended');
});

Keywords

FAQs

Package last updated on 12 Aug 2015

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