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

ack-p

v1.0.14

Published

Promises for Javascript. Extra full featured Promise-like implementation, that works with and just like you wished other Promise libraries would.

Downloads

27

Readme

ack-p, the Acker way of implementing promises

build status js-standard-style NPM version

Extra full featured Promise-like implementation, that works with and just like you wished other Promise libraries would.

Back in the Internet Explorer days, this code library was originally just one persons efforts to make async functionality cleaner and easier to implement. Now, this code has been matured into a Promise library specfically intended to stay competitive with bluebird. Ack-p is intended to do Promises with a different approach without the restrictions of the Promises/A+ spefication that bluebird adheres to.

Table of Contents

Create Your Own NEW Promise

Note: Constructing your own new promise, is only needed when an existing process-flow is async but is not a thenable

var ackP = require('ackP')//if this is nodeJs, if browser, just include ack-p

new ackP(function(resolve,reject){
  setTimeout(function(){//arbitrary async timeout
    resolve('a','b','c')
  }, 10)
})
.then(function(a,b,c){
  assert(a,'a')
  assert(b,'b')
  assert(c,'c')
})

resolve

Resolve Position-Values into Argument-Positions

Note: Other promise libraries that "chain" into ackP, will only receive the first argument

ackP.resolve('a','b','c')
.then(function(a,b,c){
  assert(a,'a')
  assert(b,'b')
  assert(c,'c')
})

spread

Spread Arrays into Argument-Positions

Note: Other promise libraries that "chain" into ackP, will only receive the first argument

ackP.resolve(['a','b','c'])
.spread()
.then(function(a,b,c){
  assert(a,'a')
  assert(b,'b')
  assert(c,'c')
})

finally

An always run process regardless of error. Receives no input, output is ignored.

const loading = 1

ackP.then(()=>{
  throw 'some error'
})
.finally(()=>{
  --loading
})
.catch(e=>console.error(e))

callback

Spread callback-argument-positions into argument-positions

ackP.resolve('a')
.callback(function(a, callback){
  assert.equal(a, 'a')
  callback(null, a,'b','c')
})
.then(function(a,b,c){
  assert(a,'a')
  assert(b,'b')
  assert(c,'c')
})

if

Conditional thenables

Note: Older browsers may choke on using reserved word (alternatives available)

ackP.resolve(22)
.if(33,function(){
  throw 'I wish I was 22'
})
.if(function(v){
  return v==68
},function(){
  throw 'I wish I was 68'
})
.if(22,function(){
  return [88,99];
})
.spread(function(a,b){
  assert.equal(a, 88)
  assert.equal(b, 99)
})

all

  • Kick start a Promise with an array of running promises
ackP.all([
  ackP.resolve(1),
  ackP.resolve(2)
])
.then(function(a,b){
  assert(a,'1')
  assert(b,'2')
})
  • Resolve a promise value that is an array of promises, into an array of values
ackP.resolve(2)
.then(function(x){
  return [
    ackP.resolve(1),
    ackP.resolve(x)
  ]
})
.all()
.then(function(r){
  assert(r[0],'1')
  assert(r[1],'2')
})

promisify

Promisify expects a function, where that function expects that it's last argument will be a callback. Returns wrapper of defined function, that when called, returns a promise of calling defined function

function databaseCall(a,b,callback){
  setTimeout(function(){
    callback(null,55)
  }, 10)
}

var databasePromise = ackP.promisify(databaseCall)

databasePromise(1,2)
.then(function(res){
  assert.equal(res, 55)
})

Differences From bluebird (as of 4/1/2016)

This project is absolutely fond of bluebird but it does differ for pratical reasons:

  • ack-p does not automatically error by default if no catch is chained to a running promise. Instead, not catching promise errors works just like ECMA6 Promises.
  • ack-p has ackP.if(condition, thenable) <- This thenable, is only executed when the condition evaluates true
  • ack-p can catch errors by type-name -> ackP.catch('TypeError', thenable)

bluebird Specific Features Not Yet Added

  • .catchThrow
  • .catchReturn ()
  • .done (unsure if will be added)
  • ... I'm sure bluebird has more that's been missed here (bluebird is great)

History

Acker Apple originally created a function-chaining library that worked in all browsers, before Promises were publically standardized. As Promises became standardized, the original function-chaining library Acker created, was then massaged into something that resembled Promises. And then along came the library bluebird, and ack-p was born from the original function-chaining library to be made to stay competitive with bluebird.

Please Note:

At this time, the bluebird Promise library has far more contributors, far more community involvement, and is overall a more publically perfected Promise library than ack-p. Their is room for improvement in both Promise libraries and always a benefit to doing things in different ways.