Skip to content

Commit

Permalink
refactor: define TZurkOn handlers ifaces
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Mar 15, 2024
1 parent 5d0d1d6 commit 86d19dd
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main/ts/zurk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ export const ZURK = Symbol('Zurk')

export type TZurkListener = (value: any, ctx: TZurkCtx) => void

export interface TZurk extends TSpawnResult {
export interface TZurkOn<R> {
on(name: 'stdout', listener: (data: Buffer, ctx: TZurkCtx) => void): R
on(name: 'stderr', listener: (data: Buffer, ctx: TZurkCtx) => void): R
on(name: 'end', listener: (result: TZurk, ctx: TZurkCtx) => void): R
on(name: 'err', listener: (error: any, ctx: TZurkCtx) => void): R
on(name: 'abort', listener: (error: any, ctx: TZurkCtx) => void): R
}

export interface TZurk extends TSpawnResult, TZurkOn<TZurk> {
_ctx: TZurkCtx
on(event: string | symbol, listener: TZurkListener): TZurk
}
Expand All @@ -20,10 +28,9 @@ export type TZurkCtx = TSpawnCtxNormalized & { nothrow?: boolean, nohandle?: boo

export type TZurkOptions = Partial<Omit<TZurkCtx, 'callback'>>

export type TZurkPromise = Promise<TZurk> & Promisified<TZurk> & {
export type TZurkPromise = Promise<TZurk> & Promisified<TZurk> & TZurkOn<TZurkPromise> & {
_ctx: TZurkCtx
stdio: TZurkCtx['stdio']
on(event: string | symbol, listener: TZurkListener): TZurkPromise
}

export const zurk = <T extends TZurkOptions = TZurkOptions, R = T extends {sync: true} ? TZurk : TZurkPromise>(opts: T): R =>
Expand Down

0 comments on commit 86d19dd

Please sign in to comment.