Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Generated on Jul 20, 2024 via pnpm

co 4.6.0

generator async control flow goodness
Package summary
Share
0
issues
1
license
1
MIT
Package created
6 Jun 2013
Version published
9 Jul 2015
Maintainers
3
Total deps
1
Direct deps
0
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
co@4.6.0
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of co 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does co do?

Co is a popular npm package that provides generator-based control flow for Node.js and browser applications. It enables developers to write non-blocking code in a neat and concise way compatibly with promises. Co essentially helps handle promises better, and it serves as a stepping stone towards using ES7 async/await.

How do you use co?

The Co library is quite straightforward to use in your application. First, you need to install it in your project directory using npm as follows:

$ npm install co

Once installed, you can import it and use it in your JavaScript code. You can use co with generator function that yields Promise:

// Import co library
var co = require('co');

co(function* () {
  // yield any promise
  var result = yield Promise.resolve(true);
}).catch(function(err){
  console.error(err.stack);
});

You can also resolve multiple promises in parallel:

var co = require('co');

co(function* () {
  var a = Promise.resolve(1);
  var b = Promise.resolve(2);
  var c = Promise.resolve(3);
  var res = yield [a, b, c]; // resolve a, b, c in parallel
  console.log(res); // Logs [1, 2, 3]
}).catch(function(err){
  console.error(err.stack);
});

If you want to convert a co-generator-function into a regular function that returns a promise, use co.wrap(fn*):

var co = require('co');
var fn = co.wrap(function* (val) {
  return yield Promise.resolve(val);
});

fn(true).then(function (val) {
  console.log(val); // Logs: true
});

Where are the co docs?

The documentation for Co can be found in the README.md file available in the GitHub repository for the Co package. More in-depth examples, API reference, and other details can be found in this document. Note that it is important to handle all your errors in co to prevent any uncaught exceptions.