{"id":18096243,"url":"https://github.com/bredele/doors","last_synced_at":"2025-04-13T09:32:22.844Z","repository":{"id":11359222,"uuid":"13792559","full_name":"bredele/doors","owner":"bredele","description":":door: Mutable asynchronous operations with conditions","archived":false,"fork":false,"pushed_at":"2019-01-04T22:17:54.000Z","size":423,"stargazers_count":89,"open_issues_count":2,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-27T01:35:32.291Z","etag":null,"topics":["asynchronous","condition","promise","state-machine"],"latest_commit_sha":null,"homepage":"https://bredele.github.io/doors","language":"JavaScript","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/bredele.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}},"created_at":"2013-10-23T03:22:28.000Z","updated_at":"2023-07-20T17:01:48.000Z","dependencies_parsed_at":"2022-09-13T08:30:47.370Z","dependency_job_id":null,"html_url":"https://github.com/bredele/doors","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bredele%2Fdoors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bredele%2Fdoors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bredele%2Fdoors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bredele%2Fdoors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bredele","download_url":"https://codeload.github.com/bredele/doors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248243205,"owners_count":21071054,"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":["asynchronous","condition","promise","state-machine"],"created_at":"2024-10-31T19:13:08.357Z","updated_at":"2025-04-13T09:32:22.559Z","avatar_url":"https://github.com/bredele.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/bredele/doors/blob/master/doors.jpeg\" width=\"325\" height=\"260\" alt=\"doors\"\u003e\n  \u003cbr\u003e\n  \u003ca href=\"https://www.npmjs.org/package/doors\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/doors.svg?style=flat\" alt=\"npm\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://travis-ci.org/bredele/doors\"\u003e\u003cimg src=\"https://travis-ci.org/bredele/doors.svg?branch=master\" alt=\"travis\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://david-dm.org/bredele/doors\"\u003e\u003cimg src=\"https://david-dm.org/bredele/doors/status.svg\" alt=\"dependencies Status\"\u003e\u003c/a\u003e\n  \u003ca href='https://github.com/bredele/contributing-guide/blob/master/guidelines.m'\u003e\u003cimg src=\"https://bredele.github.io/contributing-guide/community-pledge.svg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n# doors\n\nUse doors to represent asynchronous operations depending on multiple conditions. Imagine a door with multiple locks, you can not open the door until all locks are unlocked and one lock is enough for the door to be closed.\n\n[Check it out online!](http://bredele.github.io/doors)\n\n## Usage\n\nA door is either opened or closed. The transition from one state to an other depends on conditions called \"locks\".\n\n```js\nconst Doors = require('doors')\n\n// create a promise that will resolve only once hello and world are unlocked\nconst promise = new Doors(door =\u003e {\n  door.unlock('hello')\n  setTimeout(() =\u003e {\n    door.unlock('world')\n  }, 2000)\n}, 'hello world')\n```\n\nAt the opposite of a promise, the transition from open to close is not immutable (see below) and a door can oscillate between those 2 states. For example, this module has been used in production to represent database connection hang up with automatic retry.\n\n## Api\n\n```js\nconst doors = require('doors')\n\n// initialize door with one lock\nconst door = doors('lock1')\n\n// listen when door opens\ndoor.on('open', () =\u003e console.log('do something when no lock'))\n// listen when door closes\ndoor.on('close', () =\u003e console.log('do something when at least one lock'))\n\ndoor.on('unlock lock1', () =\u003e console.log('do something when lock1 is unlocked'))\ndoor.on('unlock lock2', () =\u003e console.log('do something when lock1 is locked'))\n\n// is lock1 unlocked?\ndoor.knock('lock1')\n// =\u003e false\ndoor.unlock('lock1')\n\n// lock lock1 againi\ndoor.lock('lock1')\n\n```\n\nA transition may depend on multiple locks.\n\n```js\nconst door = doors('lock1 lock2 lock3')\ndoor.unlock('lock3 lock1')\ndoor.knock('lock2 lock1')\n// =\u003e false\ndoor.knock('lock3 lock1')\n// =\u003e true\n\n// unlock lock2 after 1 second\ndoor.unlock('lock2', new Promise(resolve =\u003e {\n  setTimeout(resolve, 1000)\n}))\n\n// door is opened\ndoor.knock()\n// =\u003e true\n```\n\nImmutable computations can be created from door locks.\n\n```js\n// create a promise that is fulfilled when door opens\ndoor.promise().then(\n  () =\u003e console.log('door is opened'),\n  () =\u003e console.log('door is closed')\n)\n\n// create a promise that is fulfilled when lock1 is unlocked\ndoor.promise('lock1').then(\n  () =\u003e console.log('lock1 unlock'),\n  () =\u003e console.log('lock1 lock')\n)\n\n// create a promise that is fulfilled when lock1 and lock3 are unlocked\ndoor.promise('lock1 lock3').then(\n  () =\u003e console.log('both lock1 and lock3 unlock'),\n  () =\u003e console.log('both lock1 and lock3 lock')\n)\n```\n\n\n## Installation\n\n```shell\nnpm install doors --save\n```\n\n[![NPM](https://nodei.co/npm/doors.png)](https://nodei.co/npm/doors/)\n\n\n## Question\n\nFor questions and feedback please use our [twitter account](https://twitter.com/bredeleca). For support, bug reports and or feature requests please make sure to read our\n\u003ca href=\"https://github.com/bredele/contributing-guide/blob/master/guidelines.md\" target=\"_blank\"\u003ecommunity guideline\u003c/a\u003e and use the issue list of this repo and make sure it's not present yet in our reporting checklist.\n\n## Contribution\n\ndoors is an open source project and would not exist without its community. If you want to participate please make sure to read our \u003ca href=\"https://github.com/bredele/contributing-guide/blob/master/guidelines.md\" target=\"_blank\"\u003eguideline\u003c/a\u003e before making a pull request. If you have any doors related project, component or other let everyone know in our wiki.\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2016 Olivier Wietrich\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbredele%2Fdoors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbredele%2Fdoors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbredele%2Fdoors/lists"}