{"id":34778188,"url":"https://github.com/mimamch/mutex","last_synced_at":"2026-04-19T23:31:34.852Z","repository":{"id":268739014,"uuid":"703356052","full_name":"mimamch/mutex","owner":"mimamch","description":"NodeJS Transaction Locking Mutex Example","archived":false,"fork":false,"pushed_at":"2023-10-11T05:06:45.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-18T16:34:56.477Z","etag":null,"topics":["js-mutex","lock","locking","mutex","mutex-lock","mutex-synchronisation","node","transaction"],"latest_commit_sha":null,"homepage":"","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/mimamch.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":"2023-10-11T05:06:41.000Z","updated_at":"2023-10-11T06:08:04.000Z","dependencies_parsed_at":"2024-12-18T16:34:58.646Z","dependency_job_id":"da03f791-cc13-425a-9770-e6a91ca96655","html_url":"https://github.com/mimamch/mutex","commit_stats":null,"previous_names":["mimamch/mutex"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mimamch/mutex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mimamch%2Fmutex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mimamch%2Fmutex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mimamch%2Fmutex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mimamch%2Fmutex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mimamch","download_url":"https://codeload.github.com/mimamch/mutex/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mimamch%2Fmutex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32026602,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T20:23:30.271Z","status":"online","status_checked_at":"2026-04-19T02:00:07.110Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["js-mutex","lock","locking","mutex","mutex-lock","mutex-synchronisation","node","transaction"],"created_at":"2025-12-25T08:39:56.394Z","updated_at":"2026-04-19T23:31:34.843Z","avatar_url":"https://github.com/mimamch.png","language":"TypeScript","readme":"# NodeJS Mutex Example\n\nThis is a simple example of how to use mutexes in NodeJS for transaction.\n\n## How it's works?\n\nFirst you call this function, it will add lock data into transaction mutex's map.\n\n```\nstartTransaction('user123', {createdAt: new Date()});\n```\n\nThen on twice you call the method again, its will be throw an error because the user123 transaction is already running.\n\nWhen you call\n\n```\nendTransaction('user123')\n```\n\nIt will remove the lock data from transaction mutex's map. And you can call the startTransaction again.\n\n## How about startTransaction function called in same time?\n\nJavascript is running by single thread. So it will be executed one by one.\n\n## How about deadlock?\n\nBefore its throw an error, the startTransaction will check when the last transaction is started. And if last transaction started on more than 60 seconds ago, it will not throw an error and the transaction will be started again.\n\n## Usage Example\n\n```javascript\nconst transactionExample = async () =\u003e {\n  const userId = \"123\";\n  try {\n    await startTransaction(userId, {\n      createdAt: new Date(),\n    });\n\n    // Simulate a long running transaction\n    await new Promise((resolve) =\u003e setTimeout(resolve, 1000));\n    userBalance = userBalance + 1000;\n  } catch (error) {\n    console.log(error);\n  } finally {\n    await endTransaction(userId);\n  }\n};\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmimamch%2Fmutex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmimamch%2Fmutex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmimamch%2Fmutex/lists"}