datainout
Version:
Import and reports data
85 lines (83 loc) • 2.61 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// src/common/core/RingPromise.ts
var RingPromise_exports = {};
__export(RingPromise_exports, {
RingPromise: () => RingPromise
});
module.exports = __toCommonJS(RingPromise_exports);
var import_stream = require("stream");
var RingPromise = class {
constructor(ringSize, task) {
this.ring = [];
this.index = 0;
this.ring = new Array(ringSize).fill(Promise.resolve());
this.task = task;
}
run(...arg) {
return __async(this, null, function* () {
this.index = (this.index + 1) % this.ring.length;
this.ring[this.index] = this.task(...arg);
if (this.index === this.ring.length - 1) yield Promise.all(this.ring);
});
}
stream() {
const that = this;
return new import_stream.Writable({
objectMode: true,
write(arg, _encoding, callback) {
return __async(this, null, function* () {
try {
yield that.run(...arg);
} catch (err) {
return callback(err);
}
callback();
});
},
final(callback) {
Promise.all(that.ring).then(() => callback()).catch((err) => callback(err));
}
});
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
RingPromise
});