The Runnable and Runner in JavaScript/Typescript.
npm install extra-runnablesh
npm install --save extra-runnable
or
yarn add extra-runnable
`API
`ts
interface IRunnable {
init(): Awaitable
run(...args: Args): Awaitable
abort(): Awaitable
destroy(): Awaitable
}type IRawRunnableFunction = (
signal: AbortSignal
, ...args: Args
) => Awaitable
interface IRawRunnableModule {
default: IRawRunnableFunction
destroy?(): Awaitable
}
`$3
`ts
enum RunnerState {
Created = 'created' // => Initializing
, Initializing = 'initializing' // => Ready or Crashed
, Crashed = 'crashed' // => Initializing
, Ready = 'ready' // => Starting or Destroyed
, Starting = 'starting' // => Running or Error
, Running = 'running' // => Stopping or Completed or Error
, Stopping = 'stopping' // => Stopped
, Stopped = 'stopped' // => Destroyed or Starting
, Completed = 'completed' // => Destroyed or Starting
, Error = 'error' // => Destroyed or Starting
, Destroyed = 'destroyed'
}class Runner {
constructor(runnable: IRunnable)
getState(): RunnableState
init(): Promise
run(...args: Args): Promise
abort(): Promise
destroy(): Promise
}
`$3
#### RunnableFunction
`ts
class RunnableFunction implements IRunnable {
constructor(fn: IRawRunnableFunction) init(): void
run(...args: Args): Awaitable
abort(): void
destroy(): void
clone(): RunnableFunction
}
`#### RunnableModule
`ts
class RunnableModule implements IRunnable {
/**
* @param filename The file should be a module that exports IRawRunnableModule
*/
constructor(filename: string) init(): Promise
run(...args: Args): Promise
abort(): void
destroy(): void
clone(): RunnableModule
}
`#### RunnableThread
`ts
class RunnableThread implements IRunnable {
/**
* @param filename The file should be a module that exports IRawRunnableModule
*/
constructor(filename: string) init(): Promise
run(...args: Args): Promise
abort(): Promise
destroy(): Promise
clone(): RunnableThread
}
`#### RunnableProcess
`ts
class RunnableProcess implements IRunnable {
/**
* @param filename The file should be a module that exports IRawRunnableModule
*/
constructor(filename: string) init(): Promise
run(...args: Args): Promise
abort(): Promise
destroy(): void
clone(): RunnableProcess
}
``