sla

A module which avoid boilerplate code when coding an SLA function in Node

Usage no npm install needed!

<script type="module">
  import sla from 'https://cdn.skypack.dev/sla';
</script>

README

node-sla

A tiny SLA node module that avoids setTimeout boilerplate code and allows an elapsed callback to be passed.

Example

var sla = require('sla');

//Will execute the code in the first callback
sla(1000, function(done) {
    console.log("Waiting....");
    setTimeout(done,900);
  }, function() {
    console.log("Elapsed");
  });
  
//Will execute the code in the second(elapsed) callback
sla(1000, function(done) {
    console.log("Waiting....");
    setTimeout(done,1001);
  }, function() {
    console.log("Elapsed");
  });

Installation

$ npm install sla