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 🙏

© 2026 – Pkg Stats / Ryan Hefner

nocallback

v0.2.0

Published

Async JS without callbacks. Get things simple again.

Downloads

5

Readme

nocallback.js

Async JS without callbacks. Get things simple again.

Use ES6's generators in order to write async code but keep a simple control flow, free of callbacks hell. It just looks like it's synchronous, but it isn't!

    var data = yield $.get('data.json');
    
    if (data.success) {
        console.log('got data', data.args[0]);
    } else {
        console.log('failed to get data');
    }

Did you notice? Here you use a typical jQuery get request, but without giving any callback!

Usage

Two main concepts operate here: coroutines and promises.

A coroutine is a function that will execute async code, wrapped in nocallback.js's thin layer of magic.

It uses a generator in order to interrupt the control flow by yielding promises, and start it again when the promise resolves.

Simple use

Here's an example:

var doStuff = nocallback.couroutine(function* () {
    console.log('hello...');
    yield nocallback.sleep(1000);
    console.log('world!');
});

Returned object

Promise results are returned in an object in the form of:

{
    'success': /* true if resolved, false if rejected */,
    'args': /* list of arguments given to resolve/reject */
}

Coroutine from coroutine

Coroutines do actually return promises, so you can use a coroutine from a coroutine. To complete the previous example:

var doOtherStuff = nocallback.coroutine(function* () {
    yield doStuff();
    console.log('world has been greeted');
});

Return values

As coroutines return promises, reaching the end of a coroutine results in resolving the promise. If you provide a return value, it will be given as argument to the promise resolution.

var doSomething = nocallback.coroutine(function* () {
        return 42;
    }),
    doSomethingMore = nocallback.coroutine(function* () {
        var answer = yield doSomething();
        console.log(answer.args[0]); // --> 42
    });
    
doSomethingMore();

You can also reject the promise, with a special fail value

var doSomething = nocallback.coroutine(function* () { 
    return nocallback.fail('did not work');
});

Complete example

You can find a complete working example in example/app.js.

Inspiration

This project is basically inspired by Task.js and Python's asyncio.

Although it uses the same technique as Task.js, it has a different goal and a different API. Task.js tried to be a pseudo-thread, whereas here the focus is just on having a simple library that allows you to use and combine coroutines.

Compatibility

As-is, the lib is compatible with the latest versions of Google Chrome and Firefox.

Compatibility with older browsers can be achieved with an ES6 transpiler, like Babel.

Licence

This project is available under the terms of the WTFPL. See the file COPYING for more details.

Contributor(s):

  • Rémy Sanchez