explaingit

getify/caf

Analysis updated 2026-05-18

1,360JavaScriptAudience · developerComplexity · 3/5LicenseSetup · easy

TLDR

A JavaScript library that wraps generator functions so async code can be cancelled cleanly from outside, using a shareable cancellation token.

Mindmap

mindmap
  root((CAF))
    What it does
      Cancelable generators
      Async-like syntax
      Chained cancellation
    Tech stack
      JavaScript
      Node.js
      AbortController
    Use cases
      Cancel slow requests
      Timeout handling
      Cancelable streams
    Audience
      JavaScript developers
      Node.js developers

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Cancel a chain of async functions early when a request takes too long.

USE CASE 2

Build a cancelable timeout for a fetch call using CAF.timeout.

USE CASE 3

Emulate cancelable async generators for streaming data with CAG.

What is it built with?

JavaScriptNode.jsnpmAbortController

How does it compare?

getify/cafjasonkneen/tiny-world-builderfoundzigu/gujumpgate
Stars1,3601,3711,345
LanguageJavaScriptJavaScriptJavaScript
Last pushed2026-07-03
MaintenanceActive
Setup difficultyeasyeasyhard
Complexity3/52/54/5
Audiencedevelopergeneraldeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

Requires an ES2018-compatible environment or a polyfill for AbortController in older environments.

Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

In plain English

CAF, short for Cancelable Async Flows, is a JavaScript library that lets you write asynchronous code in a style that looks almost synchronous, while adding the ability to cancel it from outside. Asynchronous code is code that waits for something, like a network request, without freezing the rest of the program. JavaScript already has built-in ways to write async code, but canceling it partway through has historically been awkward. This library wraps a particular type of JavaScript function called a generator, making it behave like a modern async function. The key addition is a cancellation token: you create one before starting an operation, pass it in, and if you later decide to cancel, you call the abort method on the token. The wrapped function then stops immediately, even if it was mid-way through waiting on something. One useful aspect is that the cancellation can chain across multiple functions. If function A calls function B which calls function C, and all three share the same cancellation token, canceling once stops all three at whatever point they had reached. The library also includes a companion called CAG for generators that produce a stream of values asynchronously, not just a single result. CAF is a pure JavaScript utility, published to npm, and works in Node.js and browser environments that support ES2018 features. Older environments can use it after running the code through a transpiler. The README is detailed and covers many usage patterns and edge cases. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
Show me how to wrap a generator function with CAF so it can be cancelled with a token.
Prompt 2
Explain how CAF.timeout works and how to use it to cancel a slow fetch request.
Prompt 3
How do I chain cancellation across multiple CAF-wrapped functions calling each other?
Prompt 4
What is the difference between CAF and CAG in this library?

Frequently asked questions

What is caf?

A JavaScript library that wraps generator functions so async code can be cancelled cleanly from outside, using a shareable cancellation token.

What language is caf written in?

Mainly JavaScript. The stack also includes JavaScript, Node.js, npm.

What license does caf use?

Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

How hard is caf to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is caf for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.