Skip to content

Commit

Permalink
docs: better description (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
misbiheyv authored Oct 30, 2024
1 parent 242e637 commit 39fd535
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/core/promise/abortable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,28 @@ export default class AbortablePromise<T = unknown> implements Promise<T> {
}

/**
* Aborts the current promise (the promise will be rejected)
* @param [reason] - abort reason
* Aborts the current promise.
* The promise will be rejected only if it doesn't have any active consumers.
* You can follow the link to see how to get around this behavior.
* @see https://github.com/V4Fire/Core/blob/a0635b1ed2600409b5c14b5f85f0281a4f48ee8c/src/core/promise/abortable/README.md#tied-promises
*
* @param [reason]
*
* @example
* ```js
* const promise1 = new AbortablePromise(...);
* const promise2 = new AbortablePromise(...);
*
* promise1.then((res) => doSomething(res));
* promise2.then((res) => doSomething(res));
* promise2.then((res) => doSomethingElse(res));
*
* // It will be aborted, because it has only 1 consumer
* promise1.abort();
*
* // It won't be aborted, because it has 2 consumers
* promise2.abort();
* ```
*/
abort(reason?: unknown): boolean {
if (!this.isPending || this.aborted || Object.get(reason, [IGNORE]) === true) {
Expand Down

0 comments on commit 39fd535

Please sign in to comment.