{"id":22031795,"url":"https://github.com/divine-software/divine-synchronization","last_synced_at":"2025-05-07T12:45:07.741Z","repository":{"id":42191958,"uuid":"159050770","full_name":"Divine-Software/divine-synchronization","owner":"Divine-Software","description":"The Divine Synchronization Library","archived":false,"fork":false,"pushed_at":"2024-11-19T09:09:55.000Z","size":155,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-18T07:45:06.541Z","etag":null,"topics":["barrier","blocking-queue","condition","condition-variable","cyclic-barrier","ddr-queue","deficit-round-robin","fair-mutex","fair-queue","fair-semaphore","lightswitch","lock","mutex","queue","read-write-lock","semaphore","signal","synchronization"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Divine-Software.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2018-11-25T16:19:15.000Z","updated_at":"2024-11-19T09:09:53.000Z","dependencies_parsed_at":"2024-06-19T16:42:04.963Z","dependency_job_id":"b70bfe68-427a-4f25-885a-956c09047cfa","html_url":"https://github.com/Divine-Software/divine-synchronization","commit_stats":null,"previous_names":["leviticusmb/divine-synchronization"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Divine-Software%2Fdivine-synchronization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Divine-Software%2Fdivine-synchronization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Divine-Software%2Fdivine-synchronization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Divine-Software%2Fdivine-synchronization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Divine-Software","download_url":"https://codeload.github.com/Divine-Software/divine-synchronization/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252881401,"owners_count":21819147,"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":["barrier","blocking-queue","condition","condition-variable","cyclic-barrier","ddr-queue","deficit-round-robin","fair-mutex","fair-queue","fair-semaphore","lightswitch","lock","mutex","queue","read-write-lock","semaphore","signal","synchronization"],"created_at":"2024-11-30T08:23:27.676Z","updated_at":"2025-05-07T12:45:07.716Z","avatar_url":"https://github.com/Divine-Software.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The Divine Synchronization Library\n\n[![npm version](https://badge.fury.io/js/%40divine%2Fsynchronization.svg)](https://badge.fury.io/js/%40divine%2Fsynchronization)\n[![Build Status](https://travis-ci.org/LeviticusMB/divine-synchronization.svg?branch=master)](https://travis-ci.org/LeviticusMB/divine-synchronization)\n[![Coverage Status](https://coveralls.io/repos/github/LeviticusMB/divine-synchronization/badge.svg?branch=master)](https://coveralls.io/github/LeviticusMB/divine-synchronization?branch=master)\n\n## Introduction\n\nMany *JavaScript* or *TypeScript* developers don't think much about synchronization, even if they should. While it's true\nthat JavaScript in *Node.js* or on the web is single-threaded, anytime an asynchronous function call is invoked,\nsomething else might be executed before control is handed back to your callback.\n\nThis library contains a classical set of high-quality synchronization primitives that can be used to protect critical\nsections in such code.\n\nIt's written in *TypeScript* (which means it provides excellent IDE/editor support out of the box) and down-compiled to\nES5, so it works equally well in *Node.js* or in any web browser (a `Promise` polyfill might be required, though).\n\n## About fairness\n\nMost synchronization primitives in this library has a \"fair\" counterpart, that requires the waiter to provide an ID\ntoken. The waiters are then woken up not in FIFO order but in such a way that each ID is processed before a waiter with\na duplicate ID.\n\n## Provided primitives\n\nThis section lists the synchronization primitives provided by this library.\n\n### `DDRQueue`\n\nAlthough not really a classical primitive, it's a fair queue based on the paper [Efficient Fair Queuing Using Deficit\nRound-Robin](http://www.ecs.umass.edu/ece/wolf/courses/ECE697J/papers/DRR.pdf). It's more or less just a *TypeScript*\nrewrite of Matt Lavin's [drr-fair-queue](https://github.com/mdlavin/drr-fair-queue).\n\nThis queue is the foundation of all the \"fair\" variants of the synchronization primitives.\n\n### `Queue` and `FairQueue`\n\nA blocking queue (strict FIFO, or fair).\n\n### `Condition` and `FairCondition`\n\nA condition variable implementation with `notify()`, `notifyAll` and `wait()` methods.\n\n### `Signal` and `FairSignal`\n\nA trivial extension to the condition variable that allows a value to be passed to the waiter.\n\n***NOTE***: *Don't mistake this for a* Pub/Sub *primitive!* While possible, it's very difficult to use these two\nprimitives as event emitters without losing messages. See below instead.\n\n### `PubSub` and `FairPubSub`\n\nA *Pub/Sub* primitive, with configurable capacity, blocking publishing and generator-based subscription, suitable to be\nused in a `for await`-loop.\n\n### `Semaphore` and `FairSemaphore`\n\nA classical semaphore that can be signaled and waited for. There is also a non-blocking `take()` method available.\n\n### `Mutex` and `FairMutex`\n\nJust a semaphore initialized to 1 and with more appropriate method names.\n\n### `Barrier`, `Lightswitch` and `ReadWriteLock`\n\nA few extra primitives taken more or less verbatim from the [The Little Book of\nSemaphores](http://greenteapress.com/wp/semaphores/) by Allen B. Downey. There are no fair variants of these.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdivine-software%2Fdivine-synchronization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdivine-software%2Fdivine-synchronization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdivine-software%2Fdivine-synchronization/lists"}