everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
42 lines (40 loc) • 1.08 kB
JavaScript
import { Clock, Effect, Exit } from "effect";
import { EventEmitter } from "node:events";
//#region src/progress.ts
const pluginEvents = new EventEmitter();
const emitProgress = (event) => Effect.sync(() => {
pluginEvents.emit("progress", event);
});
const timedPhase = Effect.fn("timedPhase")(function* (timings, name, effect) {
yield* emitProgress({
phase: name,
status: "running"
});
const startedAt = yield* Clock.currentTimeMillis;
const exit = yield* Effect.exit(effect);
const durationMs = (yield* Clock.currentTimeMillis) - startedAt;
if (Exit.isSuccess(exit)) {
timings.push({
name,
durationMs
});
yield* emitProgress({
phase: name,
status: "done",
durationMs
});
return exit.value;
}
yield* emitProgress({
phase: name,
status: "error",
durationMs
});
return yield* Effect.failCause(exit.cause);
});
function timePhase(timings, name, fn) {
return Effect.runPromise(timedPhase(timings, name, Effect.promise(fn)));
}
//#endregion
export { emitProgress, pluginEvents, timePhase, timedPhase };
//# sourceMappingURL=progress.mjs.map