MCPcopy Create free account
hub / github.com/Effect-TS/effect / lifecycle

Function lifecycle

packages/sql/pg/test/utils.ts:36–59  ·  view source on GitHub ↗
(id: string, step: string, run: () => Promise<A>, signal?: AbortSignal)

Source from the content-addressed store, hash-verified

34}
35
36const lifecycle = async <A>(id: string, step: string, run: () => Promise<A>, signal?: AbortSignal): Promise<A> => {
37 if (!lifecycleEnabled) return run()
38 const started = Date.now()
39 const log = (state: string) => lifecycleLog(id, step, state, Date.now() - started)
40 log("start")
41 const pending = setInterval(() => log("pending"), 5_000)
42 pending.unref()
43 const interrupted = () => {
44 clearInterval(pending)
45 log("interrupted")
46 }
47 signal?.addEventListener("abort", interrupted, { once: true })
48 try {
49 const value = await run()
50 log("done")
51 return value
52 } catch (error) {
53 lifecycleLog(id, step, "failed", Date.now() - started, error)
54 throw error
55 } finally {
56 clearInterval(pending)
57 signal?.removeEventListener("abort", interrupted)
58 }
59}
60
61const marker = (id: string, step: string) => Effect.sync(() => lifecycleLog(id, step, "mark", 0))
62

Callers 2

utils.tsFile · 0.70
PgContainerClass · 0.70

Calls 6

lifecycleLogFunction · 0.85
logFunction · 0.70
unrefMethod · 0.65
addEventListenerMethod · 0.65
removeEventListenerMethod · 0.65
runFunction · 0.50

Tested by

no test coverage detected