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

async-base-iterator

v0.4.0

Published

Basic iterator for [async][] library that handles async and synchronous functions, also emits `beforeEach`, `afterEach` and `error` events. Using [async-simple-iterator][] and used in [async-control][].

Downloads

5

Readme

async-base-iterator npmjs.com The MIT License

Basic iterator for async library that handles async and synchronous functions, also emits beforeEach, afterEach and error events. Using async-simple-iterator and used in async-control.

code climate standard code style travis build status coverage status dependency status

Install

npm i async-base-iterator --save

Usage

For more use-cases see the tests

var base = require('async-base-iterator')
// or get constructor
var AsyncBaseIterator = require('async-base-iterator').AsyncBaseIterator

API

AsyncBaseIterator

Initialize AsyncBaseIterator with options, see also async-simple-iterator.

Params

  • options {Object=}: Pass beforeEach, afterEach and error hooks or settle option.

Example

var ctrl = require('async')
var AsyncBaseIterator = require('async-base-iterator').AsyncBaseIterator

var fs = require('fs')
var base = new AsyncBaseIterator({
  settle: true,
  beforeEach: function (fn) {
    console.log('before each:', fn.name)
  },
  error: function (err, res, fn) {
    console.log('on error:', fn.name)
  }
})
var iterator = base.makeIterator({
  afterEach: function (err, res, fn) {
    console.log('after each:', err, res, fn.name)
  }
})

ctrl.mapSeries([
  function one () { return 1 },
  function two (done) { done(null, 2) },
  function three () { return 3 },
], iterator, function (err, results) {
  // => `err` will always be null, if `settle:true`
  // => `results` is [1, 2, 3]
})

.makeIterator

Make iterator to be passed to async lib.

Params

  • [options] {Object=}: Pass beforeEach, afterEach and error hooks or settle option.
  • returns {Function}: Iterator that can be passed to any async method.

Events

  • emits: beforeEach with signature fn, next
  • emits: afterEach with signature err, res, fn, next
  • emits: error with signature err, res, fn, next

Example

var ctrl = require('async')
var base = require('async-simple-iterator')

base
  .on('afterEach', function (err, res, fn) {
    console.log('after each:', err, res, fn.name)
  })
  .on('error', function (err, res, fn) {
    console.log('on error:', err, res, fn.name)
  })

var iterator = base.makeIterator({
  settle: true,
  beforeEach: function (fn) {
    console.log('before each:', fn.name)
  }
})

function throwError () {
  throw new Error('two err')
}

ctrl.mapSeries([
  function one () { return 1 },
  function two () {
    throwError()
    return 2
  },
  function three (cb) { cb(null, 3) }
], iterator, function (err, res) {
  // `err` is always `null` when `settle: true`
  console.log(err) // => null
  console.log(res) // => [1, [Error: two err], 3]
})

.doneCallback

Helper, wrapper function. Use it to wrap you final callback function which you pass to async lib. This may be needed if you want to catch if error happens in the final callback function, because actually it is executed in promise as the other functions in stack. There's just no other way to handle errors from final callback, it is rare case, but sometimes it may be needed. Be aware of that.

Params

  • <fn> {Function}: called with arguments passed to the returned callback
  • [done] {Function=}: optional
  • returns {Function}: callback function that you can pass to async methods

Example

var base = require('async-base-iterator')
var ctrl = require('async')
var assert = require('assert')

ctrl.mapSeries([function () {
  return 123
}], base.makeIterator(), base.doneCallback(function (err, res) {
  console.log(err) // => null
  console.log(res) // => 123
  assert.strictEqual(res, 555) // intentionally
}, function (err) {
  console.log(err) // => AssertionError
}))

Related

  • async: Higher-order functions and common patterns for asynchronous code | homepage
  • async-control: Ultimate asynchronous control flow goodness with built-in hook system and compose, series, define and parallel methods. Uses async.map and async.mapSeries methods. Allows passing custom iterator function. | homepage
  • async-simple-iterator: Making simple iterator for async lib that adds beforeEach, afterEach, error hooks and support for settling. It also emits beforeEach, afterEach and error events. | homepage
  • iterator-async: Iterate over a stack of async functions. | homepage
  • iterator-promise: Iterate over a stack of functions. | homepage
  • letta: Let's move to promises! Drop-in replacement for co@4 (passing 100% tests), but on steroids. Accepts sync, async and generator functions. | homepage
  • relike: Simple promisify a callback-style function with sane defaults. Support promisify-ing sync functions. | homepage
  • then-callback: Wrap a promise to allow passing callback to .then of given promise, also works as normal .then | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github