# extra-runnable

> The Runnable and Runner in JavaScript/Typescript.

Latest version **7.0.1** (published 2026-09-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install extra-runnable
pnpm add extra-runnable
yarn add extra-runnable
bun add extra-runnable
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 7.0.1 |
| Published | 2026-09-22 |
| First published | 2022-06-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22 |
| Dependencies | 9 |
| Unpacked size | 46.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | BlackGlory |
| Maintainers | black_glory |

## Links

- npm: https://www.npmjs.com/package/extra-runnable
- Repository: https://github.com/BlackGlory/extra-runnable
- Homepage: https://github.com/BlackGlory/extra-runnable#readme
- Issues: https://github.com/BlackGlory/extra-runnable/issues
- npm.io page: https://npm.io/package/extra-runnable

## Dependencies (9)

- [nanoid](https://npm.io/package/nanoid.md) ^6.0.1
- [hotypes](https://npm.io/package/hotypes.md) ^0.6.5
- [extra-fsm](https://npm.io/package/extra-fsm.md) ^0.2.1
- [delight-rpc](https://npm.io/package/delight-rpc.md) ^7.0.0
- [url-operator](https://npm.io/package/url-operator.md) ^0.3.5
- [extra-promise](https://npm.io/package/extra-promise.md) ^7.1.1
- [@blackglory/prelude](https://npm.io/package/@blackglory/prelude.md) ^0.5.0
- [@delight-rpc/child-process](https://npm.io/package/@delight-rpc/child-process.md) ^0.7.5
- [@delight-rpc/worker-threads](https://npm.io/package/@delight-rpc/worker-threads.md) ^8.0.1

## Recent versions

- 7.0.1 (latest) — 2026-09-22
- 7.0.0 — 2026-02-15
- 6.1.1 — 2026-01-25
- 6.1.0 — 2025-08-11
- 6.0.0 — 2025-07-17
- 5.0.2 — 2023-06-11
- 5.0.1 — 2023-01-31
- 5.0.0 — 2022-12-15
- 4.0.0 — 2022-12-14
- 3.0.1 — 2022-06-12
- 3.0.0 — 2022-06-12
- 2.0.0 — 2022-06-11
- 1.0.0 — 2022-06-10

## README

# extra-runnable
The Runnable and Runner in JavaScript/Typescript.

## Install
```sh
npm install --save extra-runnable
# or
yarn add extra-runnable
```

## API
```ts
interface IRunnable<Args extends unknown[], Result> {
  init(): Awaitable<void>
  run(...args: Args): Awaitable<Result>
  abort(): Awaitable<void>
  destroy(): Awaitable<void>
}

type IRawRunnableFunction<Args extends unknown[], Result> = (
  signal: AbortSignal
, ...args: Args
) => Awaitable<Result>

interface IRawRunnableModule<Args extends unknown[], Result> {
  default: IRawRunnableFunction<Args, Result>

  destroy?(): Awaitable<void>
}
```

### Runner
```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<Args extends unknown[], Result> {
  constructor(runnable: IRunnable<Result, Args>)

  getState(): RunnableState

  init(): Promise<void>
  run(...args: Args): Promise<Result>
  abort(): Promise<void>
  destroy(): Promise<void>
}
```

### Runnables
All runnables do not support concurrent running,
their behavior during concurrent running is unpredictable.

#### RunnableFunction
```ts
class RunnableFunction<Args extends unknown[], Result> implements IRunnable<Args, Result> {
  constructor(fn: IRawRunnableFunction<Args, Result>)

  init(): void
  run(...args: Args): Promise<Result>
  abort(): void
  destroy(): void

  clone(): RunnableFunction<Args, Result>
}
```

#### RunnableModule
```ts
class RunnableModule<Args extends unknown[], Result> implements IRunnable<Args, Result> {
  /**
   * @param filename The file should be a module that exports `IRawRunnableModule<Args, Result>`
   */
  constructor(filename: string)

  init(): Promise<void>
  run(...args: Args): Promise<Result>
  abort(): void
  destroy(): void

  clone(): RunnableModule<Args, Result>
}
```

#### RunnableThread
```ts
class RunnableThread<Args extends unknown[], Result> implements IRunnable<Args, Result> {
  /**
   * @param filename The file should be a module that exports `IRawRunnableModule<Args, Result>`
   */
  constructor(filename: string)

  init(): Promise<void>
  run(...args: Args): Promise<Result>
  abort(): Promise<void>
  destroy(): Promise<void>

  clone(): RunnableThread<Args, Result>
}
```

#### RunnableProcess
```ts
class RunnableProcess<Args extends unknown[], Result> implements IRunnable<Args, Result> {
  /**
   * @param filename The file should be a module that exports `IRawRunnableModule<Args, Result>`
   */
  constructor(filename: string)

  init(): Promise<void>
  run(...args: Args): Promise<Result>
  abort(): Promise<void>
  destroy(): Promise<void>

  clone(): RunnableProcess<Args, Result>
}
```

---
_Source: https://npm.io/package/extra-runnable · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
