
Company News
Meet the Socket Team at RSAC and BSidesSF 2026
Join Socket for live demos, rooftop happy hours, and one-on-one meetings during BSidesSF and RSA 2026 in San Francisco.
Create sync/async APIs with usable logic.
Quantum + Sync - "Superposition" between sync and async.
Heavily inspired by genasync by @loganfsmyth.
Please refer to Anthony's blog post: Async, Sync, in Between.
pnpm i quansync
import fs from 'node:fs'
import { quansync } from 'quansync'
// Create a quansync function by providing `sync` and `async` implementations
const readFile = quansync({
sync: (path: string) => fs.readFileSync(path),
async: (path: string) => fs.promises.readFile(path),
})
// Create a quansync function by providing a generator function
const myFunction = quansync(function* (filename) {
// Use `yield*` to call another quansync function
const code = yield* readFile(filename, 'utf8')
return `// some custom prefix\n${code}`
})
// Use it as a sync function
const result = myFunction.sync('./some-file.js')
// Use it as an async function
const asyncResult = await myFunction.async('./some-file.js')
getIsAsyncReturns a boolean indicating whether the current execution is in async mode.
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
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:
import fs from 'node:fs'
import { quansync } from 'quansync/macro'
// Create a quansync function by providing `sync` and `async` implementations
const readFile = quansync({
sync: (path: string) => fs.readFileSync(path),
async: (path: string) => fs.promises.readFile(path),
})
// Create a quansync function by providing an **async** function
const myFunction = quansync(async (filename) => {
// Use `await` to call another quansync function
const code = await readFile(filename, 'utf8')
return `// some custom prefix\n${code}`
})
// Use it as a sync function
const result = myFunction.sync('./some-file.js')
// Use it as an async function
const asyncResult = await myFunction.async('./some-file.js')
For more details on usage, refer to unplugin-quansync's docs.
Run the following command to benchmark the performance of quansync:
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)
MIT License © Anthony Fu and Kevin Deng
FAQs
Create sync/async APIs with usable logic
The npm package quansync receives a total of 6,963,886 weekly downloads. As such, quansync popularity was classified as popular.
We found that quansync demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Join Socket for live demos, rooftop happy hours, and one-on-one meetings during BSidesSF and RSA 2026 in San Francisco.

Research
/Security News
Malicious Packagist packages disguised as Laravel utilities install an encrypted PHP RAT via Composer dependencies, enabling remote access and C2 callbacks.

Research
/Security News
OpenVSX releases of Aqua Trivy 1.8.12 and 1.8.13 contained injected natural-language prompts that abuse local AI coding agents for system inspection and potential data exfiltration.