You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cvm/lib/tasks/progress-indicator.js

26 lines
609 B
JavaScript

'use strict';
const Promise = require("bluebird");
const createEventEmitter = require("create-event-emitter");
module.exports = function(total, completionValue) {
return createEventEmitter({
await: function awaitCompletion() {
return new Promise((resolve, reject) => {
this.once("completed", () => {
resolve(completionValue);
}).once("error", (err) => {
reject(err);
});
});
},
report: function reportStatus(status, description) {
this.emit("progress", status / total, description, status, total);
if (status >= total) {
this.emit("completed");
}
}
});
}