FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
postpostscript
postpostscriptinterruptibleChain
Public
Like
interruptibleChain
Home
Code
2
README.md
main.tsx
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
Code
/
Search
README.md

interruptibleChain: simple interface for pausing and resuming execution chains

⚠️ Moved to GitHub ⚠️

Create val
import { $chain } from "https://esm.town/v/postpostscript/interruptibleChain"; const multiply = $chain() .then(() => 1) .then((x) => x + 3) .then(async (x) => { await new Promise((resolve) => setTimeout(resolve, 1000)); return x * 2; }); const handle = multiply.init(); console.log(await handle.untilDone()); // { done: true, value: 8, handle: InterruptibleChainHandle { ... } } const handle2 = multiply.init({ index: 2, value: 4, }); await handle2.advance(); console.log(handle2.done, handle2.state); // true { index: 3, value: 8 } /**** Interrupts ****/ const handle3 = $chain().then(() => { throw new Error("failed"); }).init(); await handle3.advance(); console.log(handle3.done, handle3.interrupt); // false Interrupt { reason: Error: failed, chain: InterruptibleChain { index: 0 } } console.log(await handle3.untilDone()); // { done: false, interrupt: Interrupt { ... }, handle: InterruptibleChainHandle { ... } } const handle4 = $chain().then((_, interrupt) => { return interrupt("call me later"); }).init(); await handle4.advance() console.log(handle4.done, handle4.interrupt); // false Interrupt { reason: "call me later", chain: InterruptibleChain { index: 0 } }

Migrated from folder: Archive/interruptibleChain

Code
README.mdmain.tsx
Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.