Skip to main content
Closing a thread allows you to explicitly mark threads as completed or cancelled. Contract-based threads end automatically at terminal steps, while non-contract threads require manual ending.

Contract vs Non-Contract

Contract-based threads end automatically when a terminal step is reached. Non-contract threads require manual ending via complete() or cancel().
Manual completion is rejected for contract-based threads unless a terminal step has been reached.

Basic Usage

const thread = await threadify.start(); // No contract

// Record some steps
await thread.step('process_order').success();
await thread.step('send_email').success();

// Manually end the thread
await thread.complete('All steps finished');
// OR
await thread.cancel('User cancelled order');

Properties

MethodDescriptionParameters
complete(reason?)Mark thread as successfully completedreason (string/object, optional)
cancel(reason?)Mark thread as cancelledreason (string/object, optional)

Notifications

When a thread ends, Threadify emits events:
  • thread.completed - Triggered when complete() is called or a terminal step is reached
  • thread.cancelled - Triggered when cancel() is called

Next Steps

Working with Contracts

Learn how contracts enforce terminal steps

Notifications

Subscribe to thread completion events