Sha256: c238c58e9e97267238f3fd7b87206be7bd917f10a19d7a4c8f8cabd4bf571104
Contents?: true
Size: 774 Bytes
Versions: 5
Compression:
Stored size: 774 Bytes
Contents
"use strict"; var reducible = require("reducible/reducible") var reduce = require("reducible/reduce") var isReduced = require("reducible/is-reduced") var end = require("reducible/end") function delay(source, ms) { ms = ms || 6 // Minimum 6ms, as on less dispatch order becomes unreliable return reducible(function reduceDelayed(next, result) { var timeout = 0 var ended = false reduce(source, function reduceDelaySource(value) { setTimeout(function delayed() { if (!ended) { timeout = timeout - ms result = next(value, result) if (isReduced(result)) { ended = true next(end) } } }, timeout = timeout + ms) return result }) }) } module.exports = delay
Version data entries
5 entries across 2 versions & 1 rubygems