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

qjs

v0.0.2

Published

Use the await keyword with Q promises to tame your async code

Downloads

10

Readme

Build Status

QJS

QJS adds an await keyword for use with Q promises. To use it, you must 'compile' your code. Unfortunately this somewhat destroy's your stack traces at the moment. I'd really like to come up with a way of repairing them. Other than that though, it's pretty much perfect.

Hello World Example

PromisedMath.js

require('qjs').compile(module, function () {
    //All your module code must go in here.

    module.exports.add = function (a, b) {
        return await(a) + await(b);
    };
});

Consumer.js

var Q = require('q');
var math = require('./PromisedMath');
math.add(Q.delay(3, 5000), Q.delay(2, 5000)).then(console.log).end();

If you ran consumer.js, it would create a promise for 2 and a promise for 3. These promises both take 5 seconds to resolve (you could imagine them being pulled from a server). The add method recieves both promises and then waits (sequentially) for both to be resolved before adding them together. We then log the output of 5.

Because the time starts when we create the promise, it is not important that we then wait for them sequentially.

Useful Example

api.js

var Q = require('q');
var api = require('api');
module.exports.getNextMessage = Q.nbind(api.getNextMessage);

index.js

require('qjs').compile(module, function () {
    //All your module code must go in here.
    var api = require('./api');
    function run() {
        while (message = await(api.getNextMessage())) {
            console.log(message);
        }
    };
});

API

The qjs library consists of a single function that compiles code that contains await into code that can run asyncronously. If any part of a module requires use of await like keywords, the whole module should be wrapped by the qjs compiler.

Inside the compiler you have access to await which will return the result of a promise, once it has been resolved. You also get access to Q which is the promise library and simply saves you putting var Q = require('q'); at the top of your file.

Contributing

Please fork and update this project, it's very much a work in progress, but hopefully someone will find it useful.

Unsupported Features

I will accept pull requests that fix these, and I intend to fix all of them in the near future. In the mean time, if I find it and can't fix it I document it.

  • Await in catch blocks
  • Finally blocks where there's an await in the try block (or the finally block)
  • Lazy operations such as && and || are not always as lazy as they should be if there's an await on the right hand side of the expression.
  • Select Case with an await statement in it.