{"id":22486528,"url":"https://github.com/subbu963/buzy","last_synced_at":"2025-08-02T19:32:10.531Z","repository":{"id":57191957,"uuid":"102768825","full_name":"subbu963/buzy","owner":"subbu963","description":"Async queue manager for node and browser","archived":false,"fork":false,"pushed_at":"2017-09-24T09:12:27.000Z","size":14,"stargazers_count":23,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-31T17:59:18.991Z","etag":null,"topics":["ajax","javascript","nodejs","promise","promise-library"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/subbu963.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}},"created_at":"2017-09-07T17:56:03.000Z","updated_at":"2023-11-07T12:46:33.000Z","dependencies_parsed_at":"2022-09-01T00:52:14.330Z","dependency_job_id":null,"html_url":"https://github.com/subbu963/buzy","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/subbu963%2Fbuzy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/subbu963%2Fbuzy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/subbu963%2Fbuzy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/subbu963%2Fbuzy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/subbu963","download_url":"https://codeload.github.com/subbu963/buzy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228500110,"owners_count":17930002,"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":["ajax","javascript","nodejs","promise","promise-library"],"created_at":"2024-12-06T17:14:46.727Z","updated_at":"2024-12-06T17:15:55.329Z","avatar_url":"https://github.com/subbu963.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# buzy\nPromise based async queue manager for node and browser.\n\nBuzy is a blackbox into which you push promises and at each point in time you can know if any of the promises are still in pending state(busy state). Optionally you can subscribe for the event bus which will let you know when there is change in the blackbox state\n\nIts particularly useful where you want to know if your system is busy with async activities like ajax calls etc. You can push promises in to the queue and buzy will do the job of letting you know when the state of the system changes.\nUse cases can be:\n1) Show loaders on ajax calls\n2) Check if any of your tasks are pending before closing the browser\nand similar others\n\n## Installation\n```bash\n$ npm install buzy\n```\n\n## Syntax\n```javascript\nnew Buzy(subscribers, buzies);\n```\n- subscribers - array of functions which will be called upon the change when there is a state change or when a promise is resolved/reject(this wont be triggered for buzies dependent on other buzies)\n- buzies - array of buzies to subscribe on to\n\nSubscribers will be called with the following message data structure\n```javascript\n{\n    code: number, // 0 - STATE change, 1 - RESOLVE, 2 - REJECT\n    busy: true/false,\n    promise: promise, //promise which is last resolved/rejected\n    value: value, // value of the resolution\n    error: error // error of the rejection\n}\n```\n\nNew promises can be added with: \n```javascript\nbuzy.addPromise(promise) //single promise\nbuzy.addPromises(promises) //array of promises\n```\nNew subscribers can be added with: \n```javascript\nbuzy.addSubscriber(subscriber) //single subscriber\nbuzy.addSubscribers(subscribers) //array of subscribers\n```\nNew buzies can be added with: \n```javascript\nbuzy.addBuzy(buzy) //single buzy\nbuzy.addBuzies(buzies)//array of buzies\n```\n\nTo check if buzy is busy or not:\n```javascript\nbuzy.isBusy() //true or false\n```\n\n## Examples\n```javascript\nimport Buzy from 'buzy';\n\nconst buzy1 = new Buzy([function(message) {\n  console.log(message);\n   /*\n      Prints the following:\n      {\n          code: 0,\n          busy: true\n      }\n      And after 1000 milliseconds\n      {\n          code: 1,\n          promise: Promise{'done'},\n          value: 'done'\n      }\n      And then\n      {\n          code: 0,\n          busy: false\n      }\n    */\n}]);\nconst buzy2 = new Buzy([function(message) {\n  console.log(message);\n  /*\n    Prints the following:\n    {\n        code: 0,\n        busy: true\n    }\n    And after fetch is complete\n    {\n        code: 1 or 2 based on fetch result,\n        promise: Promise{res from fetch},\n        value: value or error: error based fetch result\n    }\n    And then after buzy1 is done with all the tasks\n    {\n        code: 0,\n        busy: false\n    }\n  */\n}], [buzy1]);\n\nbuzy1.addPromise(new Promise(function(resolve, reject) {\n  setTimeout(function() {\n    resolve('done');\n  }, 1000);\n}))\nbuzy2.addPromise(fetch('http://someurl'));\n```\nCheck [Buzy.test.js](src/Buzy.test.js) for more exmaples\n## To do\n1) Cancellation of requests\n2) Removal of subscribers/buzies\n3) You tell me!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsubbu963%2Fbuzy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsubbu963%2Fbuzy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsubbu963%2Fbuzy/lists"}