Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
Q

quansync

> 编程语言
Open source

"Superposition" between sync and async

708 stars0 likes0 views
WebsiteGitHub

About

"Superposition" between sync and async

quansync

npm version npm downloads bundle JSDocs License

Create sync/async APIs with usable logic.

Quantum + Sync - "Superposition" between sync and async.

  • Typesafe
  • ESM, modern JavaScript
  • Zero dependencies

Heavily inspired by genasync by @loganfsmyth.

Why & How

Please refer to Anthony's blog post: Async, Sync, in Between.

Usage

bash
pnpm i quansync
…

getIsAsync

Returns a boolean indicating whether the current execution is in async mode.

typescript
import { getIsAsync, quansync } from 'quansync'

const fn = quansync(function* () {
  const isAsync: boolean = yield* getIsAsync()
  console.log(isAsync)
})

fn.sync() // false
await fn() // true
await fn.async() // true

all

typescript
import { all, quansync } from 'quansync'

const loadFiles = quansync(function* () {
  return yield* all([
    readFile('./one.js'),
    readFile('./two.js'),
    readFile('./three.js'),
  ])
})

const results = loadFiles.sync()
const asyncResults = await loadFiles.async()

Build-time Macro

If you don't like the function* and yield* syntax, we also provide a build-time macro via unplugin-quansync allowing you use quansync with async/await syntax, while still able to get the sync version out of that.

Here is an example:

…

For more details on usage, refer to unplugin-quansync's docs.

Benchmark

Run the following command to benchmark the performance of quansync:

bash
pnpm run build && pnpm run benchmark

Benchmark results indicate that each yield incurs an overhead of approximately 150 ns, comparable to that of await sync(). (On Apple M1 Max)

Sponsors

License

MIT License © Anthony Fu and Kevin Deng

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言