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

mech-async

v0.2.2

Published

Mechanisms to support asynchronous calls.

Readme

mech-async

Provides mechanisms to support asynchronous calls like those in the mech-ajax and mech-mongo libraries.

See Mechanisms Home for more information and other libraries.

Supported Mechanisms:

  • async - Support asynchronous calls.
  • asyncify - Treats synchronous mechanisms and literals as asynchronous mechanisms.

No Fibers or Promises

The intent of the async mechanism library is to provide an easy way to do asynchronous call backs without the need for fibers or promises.

There is nothing fancy going on behind the scenes. Underneath, these mechanisms work by using traditional javascript callbacks.

Supported Mechanisms

Async Mechanism

A mechanism for supporting asynchronous calls (Ajax, reading files, accessing databases, etc).

Traditionally

Traditionally, asynchronous callbacks are handled using a function. The documentation for mongodb npm has some great examples. Provided is one of the examples:

var MongoClient = require('mongodb').MongoClient;
var url = 'mongodb://localhost:27017/myproject';
MongoClient.connect(url, function(err, db) {
  db.close();
});

Using The Async Mechanism

m.async takes three parameters:

  • mech - The mechanism that will invoke an asynchronous call (ajax, mongo, async file access, etc.).
  • dest (optional) - The destination where the result of the call is placed (TODO: along with any errors). Scoping is done via cell scoping or traditional stack scoping to name a few.
  • bh (optional) - The mechanism to run when the asynchronous call completes.

Example:

// testdata.json on server
{
  "name" : "A Name",
  "age" : 23
}
// Run in a web browser
m.async(
  m.ajax.get("http://www.example.org/testdata.json"),
  m.cellRef("A:1"),
  m.writeLn(m.cellGet("A:1"))
).go; // returns immediately

For the above example, invoking go invokes an asynchronous ajax call: the first parameter. The call returns immediately but without a value.

When the ajax call is complete, m.async is notified and places the results in the mechanism configured in the second parameter.

  • cellRef - this example is using the cell scoping mechanism. cellRef(id) returns a reference to cell A:1 where the result of the asynchronous call is then stored (TODO: along with any errors).
  • stackRef - we could use stackRef(id) and the result would be placed on the stack.
  • other - other scoping mechanisms people might implement. Really, anything you could imagine.

Finally, m.async executes the mechanisms (the policy) configured in the third parameter. This means, any and all behavior that needs to run within the asynchronous call result needs to be placed within the third parameter. This can be anything from tests (in a testing environment) to another asynchronous call.

See mech-ajax for more examples.

Asyncify

Allows synchronous mechanisms to act like asynchronous mechanisms. Note that results are returned immediately.

HINT: Great for testing. Use asyncify for mocking asynchronous calls.

// asyncify any mechanism
m.asyncify(m.add(14, 5)).go; // immediately returns 19

// asyncify a literal
m.asyncify("hello").go; // immediately returns "hello"

m.async will return an immediate value and still behave as if the call was asynchronous.

m.cell("A:1"); // cell to place async call value
m.async(
  m.asyncify(m.add(14, 5)),
  m.cellRef("A:1"),
  m.writeLn(m.cell("A:1"))
).go; // returns 19 immediately

Async will return 19 immediately, the value in cell A:1 (where the results of the asynchronous call are placed) is set to 19 and 19 is written to the console (m.writeLn is the mechanism m.async runs when the asynchronous call is complete).

Setup

Using In Your Projects

Change directory to your node project.

$ npm install --save mech-async

Development

Get Involved!

There are a lot of core mechanisms just waiting to be created. Many of them can be created in a few hours including in-depth tests. Clone mech-library to get started!

Setup

Install:

$ npm install

Continuous test:

$ gulp

Test:

$ gulp webtests

Test Server

Read documentation in gulpfile.js to see how to setup automated web testing.

$ gulp webserver