Skip to content
Merged
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
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