{"id":25963343,"url":"https://github.com/shahradelahi/deasync","last_synced_at":"2025-07-10T07:37:44.121Z","repository":{"id":280511097,"uuid":"941279990","full_name":"shahradelahi/deasync","owner":"shahradelahi","description":"⚡ A Node.js Addon for synchronous execution of async functions","archived":false,"fork":false,"pushed_at":"2025-06-14T15:58:55.000Z","size":83,"stargazers_count":12,"open_issues_count":11,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-20T21:14:55.426Z","etag":null,"topics":["blocking","deasync","nodejs","sync"],"latest_commit_sha":null,"homepage":"https://npmjs.com/@se-oss/deasync","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shahradelahi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-01T22:57:02.000Z","updated_at":"2025-06-12T16:39:41.000Z","dependencies_parsed_at":"2025-03-03T21:22:34.430Z","dependency_job_id":"7a78f065-9608-4163-ba3f-824331d60e0d","html_url":"https://github.com/shahradelahi/deasync","commit_stats":null,"previous_names":["shahradelahi/deasync"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/shahradelahi/deasync","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Fdeasync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Fdeasync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Fdeasync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Fdeasync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shahradelahi","download_url":"https://codeload.github.com/shahradelahi/deasync/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Fdeasync/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261019429,"owners_count":23097962,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blocking","deasync","nodejs","sync"],"created_at":"2025-03-04T20:29:54.859Z","updated_at":"2025-07-10T07:37:44.116Z","avatar_url":"https://github.com/shahradelahi.png","language":"TypeScript","readme":"# @se-oss/deasync\n\n[![CI](https://github.com/shahradelahi/deasync/actions/workflows/CI.yml/badge.svg)](https://github.com/shahradelahi/deasync/actions/workflows/CI.yml)\n[![NPM Version](https://img.shields.io/npm/v/@se-oss/deasync.svg)](https://www.npmjs.com/package/@se-oss/deasync)\n[![MIT License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat)](/LICENSE)\n[![Install Size](https://packagephobia.com/badge?p=@se-oss/deasync)](https://packagephobia.com/result?p=@se-oss/deasync)\n\n_@se-oss/deasync_ is a Node.js addon that enables synchronous execution of asynchronous functions by blocking the event loop. The core of project is written in Rust for performance and reliability.\n\n---\n\n- [Installation](#-installation)\n- [Usage](#-usage)\n- [Documentation](#-documentation)\n- [Contributing](#-contributing)\n- [Credits](#-credits)\n- [License](#license)\n\n## 📦 Installation\n\n```bash\nnpm install @se-oss/deasync\n```\n\n## 📖 Usage\n\n#### Wrapping an Asynchronous Function\n\n`deasync` converts an asynchronous function with the conventional callback pattern `function(p1, ...pn, callback(error, result))` into a synchronous function. It returns the result and throws an error if one occurs.\n\n```typescript\nimport { deasync } from '@se-oss/deasync';\n\nfunction asyncFunction(input: string, callback: (err: any, result: string) =\u003e void) {\n  setTimeout(() =\u003e {\n    callback(null, `Hello, ${input}!`);\n  }, 1000);\n}\n\nconst syncFunction = deasync(asyncFunction);\nconsole.log(syncFunction(\"World\")); // Blocks for 1 second, then prints \"Hello, World!\"\n```\n\n#### Blocking Execution with `loopWhile`\n\nUse `loopWhile(predicateFunc)` to block execution while the given predicate function returns `true`.\n\n```typescript\nimport { sleep } from '@se-oss/deasync';\nlet done = false;\n\nsetTimeout(() =\u003e {\n  done = true;\n}, 1000);\n\nloopWhile(() =\u003e !done);\n\n// The task is now complete\n```\n\n#### Sleeping for a Fixed Duration\n\nThe sleep function blocks the current thread for the specified number of milliseconds. It behaves similarly to the [`Atomic.wait()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait) API.\n\n```typescript\nimport { sleep } from '@se-oss/deasync';\n\nconsole.log(Date.now(), 'Hello');\nsleep(1000);\nconsole.log(Date.now(), 'World!');\n```\n\n## 📚 Documentation\n\nFor all configuration options, please see [the API docs](https://www.jsdocs.io/package/@se-oss/deasync).\n\n## 🤝 Contributing\n\nWant to contribute? Awesome! To show your support is to star the project, or to raise issues on [GitHub](https://github.com/shahradelahi/deasync)\n\nThanks again for your support, it is much appreciated! 🙏\n\n## 🙌 Credits\n\nThis project is inspired by [deasync](https://github.com/abbr/deasync), originally created by [Vladimir Kurchatkin](https://github.com/vkurchatkin) and later maintained by [@abbr](https://github.com/abbr).\n\n## License\n\n[MIT](/LICENSE) © [Shahrad Elahi](https://github.com/shahradelahi) and [contributors](https://github.com/shahradelahi/deasync/graphs/contributors).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshahradelahi%2Fdeasync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshahradelahi%2Fdeasync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshahradelahi%2Fdeasync/lists"}