@simpleview/promiselib

1.0.1 • Public • Published

Build Status

@simpleview/promiselib

Promise utilities

Getting Started

npm install @simpleview/promiselib
const promiseLib = require("@simpleview/promiselib");

API

promisifyCached

promisifyCached provides caching micro-optimizations in cases when you execute util.promisify the same method many times. In example, calling it for each instance of an object is very expensive, and this eliminates the expense.

You use this method exactly like you would use Node's util.promisify().

  • fn - function - The function you want to promisify.
var cbFunction = function(cb) { return cb(null, "someValue"); }
var promisified = promiseLib.promisifyCached(cbFunction);

promisifyMethods

promisifyMethods is used for creating a .promises object which contains promisifed variants of methods on the normal prototype.

  • object instance - object - The object which contains the methods and will be used for scope.
  • methods - array of string - Array of method names to promisify.

In the following block each instance of MyClass will have this.promises.methodA and this.promises.methodB and both to the context of their specific instances.

var MyClass = function() {
	this.promises = promiseLib.promisifyMethods(this, ["methodA", "methodB"]);
};
MyClass.prototype.methodA = function(cb) {};
MyClass.prototype.methodB = function(cb) {};

Readme

Keywords

none

Package Sidebar

Install

npm i @simpleview/promiselib

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

2.81 kB

Total Files

4

Last publish

Collaborators

  • georgeyb-sv
  • sloutrel
  • dlford
  • korychinn_sv
  • sv-mikael
  • actionawesome
  • arkmuntasser
  • leandrodalmassoglb
  • kristian.gonzalez
  • davidlpons
  • mauriciodeleonc
  • mpcarolin
  • csarantidessv
  • mikesan789
  • owenallenaz
  • qman33
  • svjoshua
  • mkes99
  • colin.booen
  • ssmith_sv
  • aglazebrook
  • rmaynes