1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 18:29:17 +02:00
OpenSTF/lib/util/promiseutil.js
2014-01-29 00:13:29 +09:00

24 lines
438 B
JavaScript

var Promise = require('bluebird')
module.exports.periodicNotify = function(promise, interval) {
var resolver = Promise.defer()
, timer = setInterval(notify, interval)
function notify() {
resolver.progress()
}
function resolve() {
resolver.resolve()
}
function reject() {
resolver.reject()
}
promise.then(resolve, reject)
return resolver.promise.finally(function() {
clearInterval(timer)
})
}