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

nonblocking

v1.0.3

Published

asynchronous Array.prototype functions that won't block on large arrays

Downloads

966

Readme

nonblocking

Array.prototype functions that won't block on large arrays

js standard style

build status

usage

var nonblocking = require('nonblocking')

var bigArray = []
for (var i; i < 10000000; i++) {
  bigArray.push(i)
}

nonblocking(bigArray).forEach(function (el) {
  console.log(el)
}, function (err) {
  console.log('all done!')
})

When iterating over large arrays, even simple functions may become blocking. In a browser, this might mean an slow, "janky" page. In Node.js, this might mean a completely non-responsive web server!

Use this module to fan out over a large array. Note that the functions being applied to each element are not treated asynchronously or in parallel, so it's not suited to file system or network IO. If that's what you want, consider the popular async module.

Measure before optimizing! You can use the event-loop-lag module to measure if you have anything blocking in your Node.js process. If those numbers start to rise, nonblocking might help you!

api

In brief, call any of filter, forEach, some, every, or map, passing the array as the first arugment, and a Node.js-style callback as the last.

The methods are also available in a fluent syntax like lodash or underscore. Use whichever one you prefer.

Using jsig annotation.

filter and forEach also accept Dictionary objects. Other functions may support operating on Dictionaries in the future

forEach(arr: Array | Dictionary, fn: Function) => Callback<>

The final callback parameter is optional.

e.g.

nonblocking.forEach([1, 2, 3], function (x) {
  console.log(x)
}, function (err) {
  // logged: 1\n2\n3
})

// or 

nonblocking([1, 2, 3]).forEach(function (x) {
  console.log(x)
}, function (err) {
  // logged: 1\n2\n3
})

// Dictionary usage

nonblocking({a: 1, b: 2, c: 3}).forEach(function (val, key) {
  console.log(key, val)
}, function (err) {
  // logged: "a" 1\n"b" 2\n"c" 3
})

filter(arr: Array | Dictionary, fn: Predicate) => Callback<Array>

e.g.

nonblocking.filter([1, 2, 3], function (x) { return x >= 2 }, function (err, out) {
  // out = [2, 3]
})

// or 

nonblocking([1, 2, 3]).filter(function (x) { return x >= 2 }, function (err, out) {
  // out = [2, 3]
})

// Dictionary usage

nonblocking({a: 1, b: 2, c: 3]).filter(function (val, key) { return val >= 2 }, function (err, out) {
  // out = {b: 2, c: 3}
})

map(arr: Array, fn: Function) => Callback<Array>

e.g.

nonblocking.map([1, 2, 3], function (x) { return x + 1 }, function (err, out) {
  // out = [2, 3, 4]
})

// or 

nonblocking([1, 2, 3]).map(function (x) { return x + 1 }, function (err, out) {
  // out = [2, 3, 4]
})

some(arr: Array, fn: Predicate) => Callback<Boolean>

e.g.

nonblocking.some([1, 2, 3], function (x) { return x < 0 }, function (err, out) {
  // out = false
})

// or 

nonblocking([1, 2, 3]).some(function (x) { return x < 0 }, function (err, out) {
  // out = false
})

every(arr: Array, fn: Predicate) => Callback<Boolean>

e.g.

nonblocking.every([1, 2, 3], function (x) { return x > 0 }, function (err, out) {
  // out = true
})

// or 

nonblocking([1, 2, 3]).every(function (x) { return x > 0 }, function (err, out) {
  // out = true
})

installation

$ npm install nonblocking

running the tests

From package root:

$ npm install
$ npm test

contributors

license

ISC. (c) MMXVI jden [email protected]. See LICENSE.md