{"id":16861602,"url":"https://github.com/apoorvsaxena/async-resolver","last_synced_at":"2025-07-30T11:05:24.191Z","repository":{"id":52111686,"uuid":"137572294","full_name":"ApoorvSaxena/async-resolver","owner":"ApoorvSaxena","description":"⚖️ Asynchronously resolve subscribed decisions in pub-sub architecture in pure JS","archived":false,"fork":false,"pushed_at":"2022-12-08T19:13:41.000Z","size":137,"stargazers_count":16,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-15T14:32:38.260Z","etag":null,"topics":["async","decision-making","javascript","pubsub","resolver"],"latest_commit_sha":null,"homepage":"","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/ApoorvSaxena.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":"2018-06-16T10:23:41.000Z","updated_at":"2024-05-18T18:43:07.000Z","dependencies_parsed_at":"2023-01-25T17:45:59.020Z","dependency_job_id":null,"html_url":"https://github.com/ApoorvSaxena/async-resolver","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApoorvSaxena%2Fasync-resolver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApoorvSaxena%2Fasync-resolver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApoorvSaxena%2Fasync-resolver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApoorvSaxena%2Fasync-resolver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ApoorvSaxena","download_url":"https://codeload.github.com/ApoorvSaxena/async-resolver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245131139,"owners_count":20565780,"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":["async","decision-making","javascript","pubsub","resolver"],"created_at":"2024-10-13T14:32:39.152Z","updated_at":"2025-03-23T16:32:42.707Z","avatar_url":"https://github.com/ApoorvSaxena.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# async-resolver [![Build Status](https://travis-ci.org/ApoorvSaxena/async-resolver.svg?branch=master)](https://travis-ci.org/ApoorvSaxena/async-resolver) [![Coverage Status](https://coveralls.io/repos/github/ApoorvSaxena/async-resolver/badge.svg?branch=master)](https://coveralls.io/github/ApoorvSaxena/async-resolver?branch=master) [![dependencies Status](https://david-dm.org/ApoorvSaxena/async-resolver/status.svg)](https://david-dm.org/ApoorvSaxena/async-resolver)\n\n\u003ch1 align=\"center\"\u003e\n\t\u003cimg src=\"async-resolver-logo.png\" align=\"center\"\u003e\n\u003c/h1\u003e\n\nAsyncResolver.js implements a PubSub architecture where subscribers of events are decision makers (return promise when they receive an event) and after publishing an event, publisher gets the decision of the subscribers. Supports both Node and browser.\n\n### Where to use?\n\nThere are situations where we want to maintain distinct subscribers of an event, though want to act on the basis of how subscribers react. AsyncResolver.js is the solution for this need, it's an amalgamation of pub sub architecture and promises to provide decision making capability in asynchronous environment.\n\u003e For example: Let's consider a case where there are several components on a webpage, whose state can be changed by the user and we make every component to subscribe as listener to listen to a page transition so that we can check if a user is trying to move without saving data.\n\n\u003e Now, when an individual clicks on a link, we publish an event mentioning of the transition of the user from the page, though we want to ask every listener (or component) if user has made any changes to their state and is moving without saving them. In case there are any unsaved changes in any of the component, then we cancel the transition and instead dispay an information dialog to the user asking him to save information before proceeding further.\n\n## Install\n\n```sh\n### NPM\nnpm install async-resolver\n\n### Yarn\nyarn add async-resolver\n```\n\n\n## Usage\n\n```js\nconst AsyncResolver = require('async-resolver');\nlet resolver = new AsyncResolver();\n\nresolver.subscribe('locationChange', () =\u003e {\n\t// custom logic\n    return Promise.resolve();\n});\n\nresolver.subscribe('locationChange', () =\u003e {\n\t// custom logic\n    return Promise.reject();\n});\n\nresolver\n\t.publish('locationChange', {\n\t\tpromiseMethod: 'any'\n\t})\n\t.then(() =\u003e console.log('location change allowed'))\n\t.catch(() =\u003e console.log('location change denied'))\n```\n\n## API\n\n### AsyncResolver()\n\nReturns `AsyncResolver` function that can be instantiated.\n\n### subscribe(eventName, callback)\n\nAllows subscribing to the event and executing the callback when an event is published.\n\n#### eventName\n\nType: `string`\n\nEvent published.\n\n#### callback\n\nType: `function`\n\nCallback to be executed when the publish event is received.\n\n### publish(eventName, options)\n\nReturns a promise, that defines the decision of subscribers.\n\n#### eventName\n\nType: `string`\n\nEvent published.\n\n#### options\n\nType: `object`\n\nOptions to be passed while publishing to an event.\n\n##### options.promiseMethod\n\nType: `string`\n\nMethod to be applied at the collection of promises such as `all`, `any` etc. Here's [list of methods](http://bluebirdjs.com/docs/api/collections.html) supported by Promise collection.\n\n## License\n\nMIT © [Apoorv Saxena](https://apoorv.pro/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapoorvsaxena%2Fasync-resolver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapoorvsaxena%2Fasync-resolver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapoorvsaxena%2Fasync-resolver/lists"}