Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@songkick/promise-stopwatch

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@songkick/promise-stopwatch

Mesure a Promise resolution duration using Performance API with fallback to `new Data()`

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
3
Weekly downloads
 
Created
Source

promise-stopwatch Build Status Code Climate Test Coverage

Mesure a Promise resolution duration using Performance API with fallback to new Data().

var stopwatch = require('promise-stopwatch');
function resolveInOneSec() {
  return new Promise(function(resolve, reject){
    setTimeout(function(){
      resolve('yay');
    }, 1000);
  });
}

var settings = {}; // there is none available for now

stopwatch(settings)(resolveInOneSec)().then(function(response){
  var result = response.result;  // === 'yay'
  var duration = response.duration; // ~== 1000
  var settings = response.settings; // === {}

  console.log('Resolution took ' + duration + 'ms');

  return result; // return the result so you can handle it normally
});

function rejectInOneSec() {
  return new Promise(function(resolve, reject){
    setTimeout(function(){
      reject('nay');
    }, 1000);
  });
}

stopwatch(settings)(rejectInOneSec)().catch(function(response){
  var error = response.error;  // === 'nay'
  var duration = response.duration; // ~== 1000
  var settings = response.settings; // === {}

  console.log('Rejection took ' + duration + 'ms');

  throw error; // possibly re-throw the error so you can handle it normally
});

Options

None, for now, but it might come, so we keep this signature similar to other promise helper and be able to some without change the API.

See also

promise-stopwatch composes really well with the following promise helper:

Keywords

FAQs

Package last updated on 11 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc