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

uvrun2

v0.3.0

Published

NodeJS binding to uv_run (..., UV_RUN_ONCE) in libuv and synchronizing of asynchronous functions

Downloads

8

Readme

uvrun2

Build Status

Copyright

(C) 2015 Jeff Walter [email protected], http://jwalter.sh/

License

This module is licensed under the MIT License (MIT). Please see the accompanying LICENSE file for more information.

Contributions

None yet

Requirements

  • NodeJS >= 0.11.0

Installation

The easiest way is to use NPM:

npm install uvrun2

You can also clone this repo and build the module yourself:

git clone https://github.com/jeffwalter/node-uvrun2.git
cd node-uvrun2
node-gyp configure build

Testing

Dirt simple:

npm test

Usage

Running the loop once and handling a single event:

var uvRunOnce = require ('uvrun2').runOnce;

setTimeout (function () { console.info ("Hello!"); }, 5000);
while (1) {
  uvRun ();
}

Pause code to wait for an asynchronous call to complete:

var uvWaitFor = require ('uvrun2').waitFor;

var wait = new uvWaitFor ();
setTimeout (function () {wait.provide (1);}, 5000);
var returnValue = wait.accept ();

Methods

uvrun2.runOnce (nonBlocking = false)

Process a single event from the libuv loop. By default this call will block until it has processed an event, but you can pass true as the sole argument causing the call to either process a waiting event or return immediately.

Classes

uvrun2.waitFor

A class added for convenience. It's designed to allow synchronizing of asynchronous functions. Why would you want to do that? Maybe you're getting a little deep into callback hell. Maybe you'd like to serialize a section of code but don't feel async is the way to go. Whatever the reason, this will handle the task.

Basically the class pauses execution at the variable assignment spinning over a uvrun2.runOnce (true) (see above) while checking for a provided value. Once it sees a value it is returned. Meanwhile, asynchronous events and code continue to run.

Please note that waitFor will only allow a single value to be provided in each instance. They cannot be re-used.

new uvrun2.waitFor ()

Constructs a new waitFor instance. It has no arguments.

uvrun2.waitFor.accept (block = true)

Use this to assign the result of the asynchronous code to a variable. You can use the block argument to control the call to uvrun2.runOnce(). Setting block to true will set nonBlocking to false and visa versa. The functionality is identical, but setting block to true has the effect of lowering CPU use by removing the spin on uvrun2.runOnce(). It is recommended to use the default value by either not passing a value for block or by setting it to true.

uvrun2.waitFor.provide (value)

Goes in the asynchronous call to provide the value back to the accept() call.