Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thakursaurabh1998/code-harmony
Make your code more readable by making the functions work in harmony with each other.
https://github.com/thakursaurabh1998/code-harmony
asynch callback context harmony promise typescript
Last synced: 14 days ago
JSON representation
Make your code more readable by making the functions work in harmony with each other.
- Host: GitHub
- URL: https://github.com/thakursaurabh1998/code-harmony
- Owner: thakursaurabh1998
- License: mit
- Created: 2020-05-13T22:57:42.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-26T17:29:01.000Z (over 4 years ago)
- Last Synced: 2024-11-17T05:18:08.910Z (about 1 month ago)
- Topics: asynch, callback, context, harmony, promise, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/code-harmony
- Size: 40 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# code-harmony
Make your code more readable by making the functions work in harmony with each other.
- Provides an interface to write code in a more granular format.
- Allows the sharing of resources between various worker functions to reduce duplicate data fetching or generating.## Install
```bash
npm install code-harmony
```## Usage
```js
// this is an example of a context creating function
// can be any asynchronous call which
// resolves with an object containing data
// the data is then populated in the context object
// which is available to the worker functions
function fetchUserData(subscribedData) {
const user = await fetchUserFromDB();
return Promise.resolve({ userId: user.id });
}// this is an example of a worker function
function applyOfferA(subscribedData, context) {
console.log(context) // -> { userId: 1234 }
return Promise.resolve();
}const CodeHarmony = require('code-harmony');
new CodeHarmony(subscribedData)
.context(fetchUserData)
.serially(applyOfferA, applyOfferB)
.parallelly(emailInvoice, smsInvoice)
.finish()
.then() // resolves when all the tasks finishes
.catch(logger.error); // action can be taken on any error here
```## Resources
- [Changelog](https://github.com/thakursaurabh1998/code-harmony/blob/master/CHANGELOG.md)
## License
[MIT License](https://choosealicense.com/licenses/mit/)