{"id":47088059,"url":"https://github.com/havelessbemore/semafy","last_synced_at":"2026-03-12T08:55:06.987Z","repository":{"id":65494361,"uuid":"360002004","full_name":"havelessbemore/semafy","owner":"havelessbemore","description":"A robust cross-agent synchronization library.","archived":false,"fork":false,"pushed_at":"2025-07-06T20:17:35.000Z","size":1437,"stargazers_count":4,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-20T19:55:05.646Z","etag":null,"topics":["async","barrier","concurrency","condvar","latch","lock","mutex","semaphore","workers"],"latest_commit_sha":null,"homepage":"","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/havelessbemore.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"havelessbemore"}},"created_at":"2021-04-21T01:52:11.000Z","updated_at":"2025-07-06T20:05:23.000Z","dependencies_parsed_at":"2024-05-29T01:03:06.006Z","dependency_job_id":"24a17186-28b0-434c-bd5e-a7f13965ce10","html_url":"https://github.com/havelessbemore/semafy","commit_stats":{"total_commits":24,"total_committers":1,"mean_commits":24.0,"dds":0.0,"last_synced_commit":"2e79073fa99d72a42ce4afc051af2c5b130abe97"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/havelessbemore/semafy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/havelessbemore%2Fsemafy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/havelessbemore%2Fsemafy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/havelessbemore%2Fsemafy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/havelessbemore%2Fsemafy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/havelessbemore","download_url":"https://codeload.github.com/havelessbemore/semafy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/havelessbemore%2Fsemafy/sbom","scorecard":{"id":457715,"data":{"date":"2025-08-11","repo":{"name":"github.com/havelessbemore/semafy","commit":"fd7210d2d21fb7573e985f105a0cfd192fd02652"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":5.3,"checks":[{"name":"Maintained","score":0,"reason":"1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: SECURITY.md:1","Info: Found linked content: SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1","Info: Found text in security policy: SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Info: jobLevel 'contents' permission set to 'read': .github/workflows/publish.yml:11","Warn: no topLevel permission defined: .github/workflows/coverage.yml:1","Warn: no topLevel permission defined: .github/workflows/main.yml:1","Warn: no topLevel permission defined: .github/workflows/publish.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/20 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":6,"reason":"dependency not pinned by hash detected -- score normalized to 6","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/coverage.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/havelessbemore/semafy/coverage.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/coverage.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/havelessbemore/semafy/coverage.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/coverage.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/havelessbemore/semafy/coverage.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/havelessbemore/semafy/main.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/havelessbemore/semafy/main.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/havelessbemore/semafy/publish.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/havelessbemore/semafy/publish.yml/main?enable=pin","Info:   0 out of   6 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned","Info:   3 out of   3 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Packaging","score":10,"reason":"packaging workflow detected","details":["Info: Project packages its releases by way of GitHub Actions.: .github/workflows/publish.yml:8"],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":10,"reason":"SAST tool is run on all commits","details":["Info: all commits (10) are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":9,"reason":"1 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-xffm-g5w8-qvg7"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T10:10:34.224Z","repository_id":65494361,"created_at":"2025-08-19T10:10:34.225Z","updated_at":"2025-08-19T10:10:34.225Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30420528,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T07:30:13.030Z","status":"ssl_error","status_checked_at":"2026-03-12T07:29:54.885Z","response_time":114,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["async","barrier","concurrency","condvar","latch","lock","mutex","semaphore","workers"],"created_at":"2026-03-12T08:54:44.590Z","updated_at":"2026-03-12T08:55:00.275Z","avatar_url":"https://github.com/havelessbemore.png","language":"TypeScript","funding_links":["https://github.com/sponsors/havelessbemore"],"categories":[],"sub_categories":[],"readme":"# Semafy\n\n**Semafy** provides synchronization and concurrency management across execution agents (main thread, web workers). It contains a robust set of tools modeled after C++ synchronization primitives, offering control and flexibility for managing shared resources and states.\n\n[![Version](https://img.shields.io/npm/v/semafy.svg)](https://www.npmjs.com/package/semafy)\n[![Maintenance](https://img.shields.io/maintenance/yes/2024.svg)](https://github.com/havelessbemore/semafy/graphs/commit-activity)\n[![License](https://img.shields.io/github/license/havelessbemore/semafy.svg)](https://github.com/havelessbemore/semafy/blob/master/LICENSE)\n[![codecov](https://codecov.io/gh/havelessbemore/semafy/graph/badge.svg?token=F362G7C9U0)](https://codecov.io/gh/havelessbemore/semafy)\n![npm bundle size](https://img.shields.io/bundlephobia/minzip/semafy)\n\n## Features\n\n- **Mutexes**: Exclusive and shared locking to protect data from concurrent access.\n- **Semaphores**: Control access to a finite number of resources.\n- **ConditionVariable**: Allows agents to wait for certain conditions to occur.\n- **Barriers**: Ensures agents reach a certain point before any can proceed.\n- **Utilities**: Manage async code with `lock`, `tryLock`, `lockGuard`, and `callOnce`.\n- **Error Handling**: Specific error classes to enhance debuggability and reliability.\n- **Platform Agnostic**: Works in any [browser](#browser-usage) or server-side environment that supports `SharedArrayBuffer`.\n\n## Installation\n\nNPM:\n\n```bash\nnpm install semafy\n```\n\nYarn:\n\n```bash\nyarn add semafy\n```\n\nJSR:\n\n```bash\njsr add @rojas/semafy\n```\n\n## API\n\n### Generics\n\n- **[Sync]BasicLockable**: A base interface that provides exclusive blocking for agents.\n\n- **[Sync]Lockable**: Extends `BasicLockable` to include attempted locking.\n\n- **SharedLockable**: Provides shared blocking semantics for agents.\n\n- **SharedResource**: Represents a shared resource that is backed by a `SharedArrayBuffer`.\n\n- **SharedTimedLockable**: Extends `SharedLockable` to include timed blocking.\n\n- **[Sync]TimedLockable**: Extends `Lockable` to include timed blocking.\n\n### Mutexes\n\n- **Mutex**: Provides essential mutex operations including `lock`, `unlock`, and `tryLock`.\n\n- **TimedMutex**: A timed variant that supports timed operations including `tryLockFor` and `tryLockUntil`.\n\n- **RecursiveMutex**: Allows multiple locks from the same agent.\n\n- **RecursiveTimedMutex**: A timed variant that supports timed operations.\n\n- **SharedMutex**: Allows multiple readers or exclusive writer access, facilitating reader-writer scenarios.\n\n- **SharedTimedMutex**: A timed variant that supports timed operations.\n\n### Mutex Management\n\n- **lock()**: Sequentially acquires the given locks. If any lock fails, the process is stopped, and any acquired locks are released in reverse order.\n\n- **lockGuard\\[Sync\\]()**: Locks a mutex before calling a callback function, ensuring the mutex is unlocked afterwards.\n\n- **MultiLock**: Wraps multiple `BasicLockable` objects to create a multi-lock. Calls to `lock`, `unlock`, etc will acquire / release locks on all of the wrapped objects.\n\n- **SharedLock**: Wraps a `SharedLockable` object (e.g. `SharedMutex`) to create a shared lock. Calls to `lock`, `unlock`, etc will acquire / release a shared lock instead of an exclusive lock.\n\n- **tryLock()**: Tries to sequentially acquire the given locks. If any lock fails, the process is stopped, and any acquired locks are released in reverse order.\n\n- **UniqueLock**: Wraps a `BasicLockable` object to create a unique lock. Calls to `lock`, `unlock`, etc will acquire / release a lock on the wrapped object.\n\n### Call Once\n\n- **callOnce()**: Executes a callback function at most once, based on the state of a provided `OnceFlag`.\n\n- **OnceFlag**: Represents a flag that can be set exactly once, shared across different execution agents.\n\n### Condition Variable\n\n- **ConditionVariable**: Allows agents to wait for specific conditions, tightly integrated with mutexes for state management.\n\n### Semaphores\n\n- **CountingSemaphore**: Manages access to a finite number of resources, allowing multiple entities to hold the semaphore concurrently up to a maximum count.\n\n### Barriers\n\n- **Latch**: Allows agents to wait until a set of operations has been completed. Ideal for scenarios where multiple tasks must reach a common point before proceeding. For example, the completion of multiple data loading operations before data processing begins.\n\n### Errors\n\n- **LockError**: A generic error related to errors in lock acquisition, release and management.\n\n- **MultiLockError**: Occurs when attempting to acquire multiple locks simultaneously.\n\n- **MultiUnlockError**: Occurs when attempting multiple unlocks simultaneously.\n\n- **OwnershipError**: Occurs when attempting to unlock an unacquired mutex.\n\n- **RelockError**: Occurs when attempting to lock an already acquired mutex. Prevents deadlocks from occurring.\n\n- **TimeoutError**: Occurs when an operation exceeds a set time, such as when using `tryLockFor` or `tryLockUntil`.\n\n## Browsers\n\nBrowser security requirements for using shared memory must be met. Please see [SharedArrayBuffer \u003e Security Requirements](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements) for details.\n\n### Sync methods\n\nThe use of synchronous methods (e.g. `lockSync`) may not be allowed on the main thread. If not, their async versions (e.g. `lock`) are available.\n\n## Contributing\n\nContributions are welcome!\n\n- **Bug Reports**: Please use the [GitHub issue tracker](https://github.com/havelessbemore/semafy/issues) to report any bugs. Include a detailed description and any relevant code snippets or logs.\n\n- **Feature Requests**: Please submit feature requests as issues, clearly describing the feature and its potential benefits.\n\n- **Pull Requests**: Please ensure your code adheres to the existing style of the project and include any necessary tests and documentation.\n\nFor more information, check out the [contributor's guide](https://github.com/havelessbemore/semafy/CONTRIBUTING.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhavelessbemore%2Fsemafy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhavelessbemore%2Fsemafy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhavelessbemore%2Fsemafy/lists"}