Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run check
- run: npm run check:code
- run: npm test
- run: npm run build --if-present
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## v2.0.0

### Added

- :warning: **[breaking-change]** Add an identifier for each function registration. When using the same identifier, **the new registered function(s) replace(s) the previous one(s)**.

- :warning: **[breaking-change]** Add an identifier for predicates functions to mimic to the same behavior as functions registrations. Several predicate functions can now be passed in a single `if()` with a defined identifier. In the same way, if another `if()` predicate is set with the same identifier, **it will override the previous one**.

- Add `deleteFunctionsWhenJobsStarted` option allowing the deletion of registered functions when the jobs are started.

- Add `debug.logFunctionRegistrations` and `debug.logFunctionExecutions` options allowing functions registrations and executions logs. Don't forget to set `DEBUG=AsyncProcess:*` as an environment variable or in your browser's local storage.

- Keep errors thrown by jobs as is.

Example: If the job is a fetch query and if the response is a 404, the `err` object will be a Response object.

- AsyncProcess instances now accept two more generics, results (`R`) and an error (`E`), allowing to enforce typings of jobs results and jobs exceptions.

## v1.2.0

### Added
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ AsyncProcess.instance('initUsersPage', ['optionalIdentifier'])
.onSuccess(hideSpinner)
// call the `showError` function when the process is done and if it fails
.onError(showError)
// start the async process
// start jobs
.start()
```

Expand All @@ -71,9 +71,9 @@ It's important to note that nothing is happening unless the `start` function is

In order to retrieve the same `AsyncProcess` declarations accross your application, `AsyncProcess` is an unique singleton that saves all instances.

Each instance are referenced via an identifer and optional sub identifiers.
Each instance are referenced via an identifer and optional sub identifiers. There is no inheritance between AsyncProcess instances meaning that an instance with a same identifier but different sub-identifiers are two different instances.

The first identifier can be typed, typically by using an union of different string values, allowing to retrieve your instances in a safe way. Optional sub identifiers can be used for uuid or any arguments that identify your async process more precisely.
The first identifier can be typed, typically by using an union of different string values, allowing to retrieve your instances in a safe way. Optional sub identifiers are generally used by [composite functions](#composition) (`with(...)`) for internal AsyncProcess instances.

### Typed identifiers

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@productive-codebases/async-process",
"version": "1.2.0",
"version": "2.0.0-beta.1",
"description": "Declare, configure and start asynchronous processes with ease.",
"author": "Alexis MINEAUD",
"license": "MIT",
Expand All @@ -12,10 +12,10 @@
"types": "dist/types/index.d.ts",
"scripts": {
"build": "rm -rf dist && mkdir dist && tsc --project tsconfig.build.json",
"check": "tsc --noEmit",
"check:code": "tsc --noEmit",
"lint": "eslint .",
"prepublishOnly": "npm run check && npm run lint && npm t && npm run build",
"test": "jest"
"prepublishOnly": "npm run check:code && npm run lint && npm t && npm run build",
"test": "DEBUG_COLORS=0 DEBUG_HIDE_DATE=true jest"
},
"devDependencies": {
"@types/jest": "^29.2.5",
Expand Down
4 changes: 2 additions & 2 deletions src/AsyncProcess/composers/__tests__/withLogs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('Composers', () => {
const logger = jest.fn()

await getAsyncProcessTestInstance('loadFoo')
.do(() => doSomething())
.do(doSomething)
.compose(withLogs(logger))
.start()

Expand Down Expand Up @@ -65,7 +65,7 @@ describe('Composers', () => {
const logger3 = jest.fn()

await getAsyncProcessTestInstance('loadFoo')
.do(() => doSomething())
.do(doSomething)
.compose(withLogs(logger1))
.compose(withLogs(logger2, 'secondLogger'))
.compose(withLogs(logger3, 'thirdLogger'))
Expand Down
6 changes: 3 additions & 3 deletions src/AsyncProcess/composers/withLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export function withLogs<TIdentifier extends string>(
])
.onStart(() => {
logger('Start %s', asyncProcess.identifier)
})
}, identifier)
.onSuccess(() => {
logger('Success %s', asyncProcess.identifier)
})
}, identifier)
.onError(err => {
logger('Error %s: %o', asyncProcess.identifier, err)
})
}, identifier)
}
}
Loading