-
Notifications
You must be signed in to change notification settings - Fork 2
API
Cancellable Promise with extra features
CanceledError class
Kind: static property of CPromise
Refers to the AbortController class (native if available)
Kind: static property of CPromise
AbortControllerEx class
Kind: static property of CPromise
Generic cancellation reason
Kind: static property of CPromise
Cancellation reason for the case when the instance will be disposed
Kind: static property of CPromise
Timeout cancellation reason
Kind: static property of CPromise
React specific canceled reason
Kind: static property of CPromise
async decorator
Kind: static property of CPromise
listen decorator
Kind: static property of CPromise
cancel decorator
Kind: static property of CPromise
cancel decorator
Kind: static property of CPromise
make CPromise function atomic
Kind: static property of CPromise
append done
chain to the resulting promise of the decorated method
Kind: static property of CPromise
timeout decorator
Kind: static property of CPromise
innerWeight decorator
Kind: static property of CPromise
label decorator
Kind: static property of CPromise
label decorator
Kind: static property of CPromise
progress decorator
Kind: static property of CPromise
Kind: static property of CPromise
Creates a new CPromise instance
Kind: inner namespace of CPromise
Extends: Promise
Param | Type | Description |
---|---|---|
[executor] | CPromiseExecutorFn |
promise executor function that will be invoked in the context of the new CPromise instance |
[options] | CPromiseOptions |
-
~CPromise :
object
-
instance
-
.signal :
AbortSignal
-
.isPending ⇒
Boolean
-
.isCanceled ⇒
Boolean
-
.isCaptured ⇒
Boolean
-
.isPaused ⇒
Boolean
-
.isRejected ⇒
Boolean
-
.parent ⇒
CPromise
|null
-
.onCancel(listener) ⇒
CPromise
-
.onPause(listener) ⇒
CPromise
-
.onResume(listener) ⇒
CPromise
-
.onCapture(listener) ⇒
CPromise
- .onDone(listener)
- .onSignal(listener)
-
.totalWeight([weight]) ⇒
Number
|CPromise
-
.innerWeight([weight]) ⇒
Number
|CPromise
-
.progress([value], [data], [scope]) ⇒
Number
|CPromise
-
.propagate(type, data, [scope]) ⇒
CPromise
-
.captureProgress([options]) ⇒
CPromise
-
.scopes([pendingOnly]) ⇒
Array.<CPromise>
-
.timeout([ms]) ⇒
Number
|CPromise
-
.weight([weight]) ⇒
Number
|CPromise
-
.label([label]) ⇒
Number
|CPromise
-
.resolve(value) ⇒
CPromise
-
.reject(err) ⇒
CPromise
-
.pause(data) ⇒
Boolean
-
.resume(data) ⇒
Boolean
- .atomic([type]) ⇒
- .cancel([reason], [forced])
-
.emitSignal(type, [data], [handler], [locator]) ⇒
Boolean
-
.delay(ms) ⇒
CPromise
-
.aggregate([weight]) ⇒
CPromise
-
.then(onFulfilled, [onRejected]) ⇒
CPromise
-
.catch(onRejected, [filter]) ⇒
CPromise
-
.finally(onFinally) ⇒
Promise.<(T|void)>
-
.done(doneHandler) ⇒
CPromise
-
.canceled([onCanceled]) ⇒
CPromise
-
.listen(signal) ⇒
CPromise
-
.on(type, listener, [prepend]) ⇒
CPromise
-
.off(type, listener) ⇒
CPromise
-
.listenersCount(type) ⇒
Number
-
.hasListeners(type) ⇒
Boolean
-
.once(type, listener) ⇒
CPromise
-
.emit(type, ...args) ⇒
CPromise
-
.emitHook(type, ...args) ⇒
Boolean
-
.toString([entireChain]) ⇒
string
-
.signal :
-
static
-
.version ⇒
string
-
.versionNumber ⇒
number
-
.isCanceledError(thing) ⇒
boolean
-
.delay(ms, value, [options]) ⇒
CPromise
-
.all(iterable, [options]) ⇒
CPromise
-
.race(pending) ⇒
CPromise
-
.allSettled(iterable, [options]) ⇒
CPromise
-
.retry(fn, [options]) ⇒
CPromise
-
.resolve([thing], [options]) ⇒
CPromise
-
.promisify(originalFn, [options]) ⇒
function
-
.run(generatorFn, [options]) ⇒
CPromise
- .async([options])
- .listen([signals])
- .cancel([reason], signal)
- .canceled(onCanceledChain)
- .progress(onProgressHandler)
- .ReactComponent(options)
- .timeout(ms)
- .label(str)
- .innerWeight(weight)
- .atomic(atomicType)
- .done(doneHandler)
-
.isPromisifiedFn(fn) ⇒
*
|boolean
-
.isCPromise(thing, [anyVersion]) ⇒
boolean
-
.version ⇒
-
instance
get promise abort signal object
Kind: instance property of CPromise
indicates if the promise is pending
Kind: instance property of CPromise
indicates if the promise is pending
Kind: instance property of CPromise
indicates if the promise progress is captured
Kind: instance property of CPromise
indicates if the promise chain is paused
Kind: instance property of CPromise
indicates if the promise is rejected
Kind: instance property of CPromise
get parent promise
Kind: instance property of CPromise
registers the listener for cancel event
Kind: instance method of CPromise
Param | Type |
---|---|
listener | OnCancelListener |
registers the listener for pause event
Kind: instance method of CPromise
Param | Type |
---|---|
listener | OnPauseListener |
registers the listener for resume event
Kind: instance method of CPromise
Param | Type |
---|---|
listener | OnResumeListener |
registers the listener for capture event
Kind: instance method of CPromise
Param | Type |
---|---|
listener | OnCaptureListener |
registers the listener for done event
Kind: instance method of CPromise
Param | Type |
---|---|
listener | CPDoneListener |
registers the listener for done event
Kind: instance method of CPromise
Param | Type |
---|---|
listener | CPSignalListener |
Set or get the total weight of the inner chains
Kind: instance method of CPromise
Param | Type |
---|---|
[weight] | Number |
Set or get the total weight of the inner chains
Kind: instance method of CPromise
Param | Type |
---|---|
[weight] | Number |
Set promise progress
Kind: instance method of CPromise
Param | Type | Description |
---|---|---|
[value] | Number |
a number between [0, 1] |
[data] | * |
any data to send for progress event listeners |
[scope] | CPromise |
CPromise scope |
emit propagate event that will propagate through each promise scope in the chain (bubbling)
Kind: instance method of CPromise
Param | Type | Default | Description |
---|---|---|---|
type |
String | symbol
|
some type to identify the data kind | |
data | * |
|
some data |
[scope] | CPromise |
|
CPromise scope |
capture initial progress state of the chain
Kind: instance method of CPromise
Param | Type | Description |
---|---|---|
[options] | Object |
|
options.throttle | Number |
set min interval for firing progress event |
options.innerWeight | Number |
set weight of the nested promises |
Returns all parent scopes that are in pending state
Kind: instance method of CPromise
Param | Type | Default |
---|---|---|
[pendingOnly] | boolean |
false |
timeout before the promise will be canceled
Kind: instance method of CPromise
Param | Type | Description |
---|---|---|
[ms] | Number |
timeout in ms |
Sets the promise weight in progress capturing process
Kind: instance method of CPromise
Returns: Number
| CPromise
- returns weight if no arguments were specified
Param | Type | Description |
---|---|---|
[weight] | Number |
any number greater or equal 0 |
Sets the promise label
Kind: instance method of CPromise
Returns: Number
| CPromise
- returns weight if no arguments were specified
Param | Type | Description |
---|---|---|
[label] | String |
any string |
Resolves the promise with given value
Kind: instance method of CPromise
Param |
---|
value |
Rejects the promise with given error
Kind: instance method of CPromise
Param |
---|
err |
Pause promise
Kind: instance method of CPromise
Param | Type |
---|---|
data | * |
Resume promise
Kind: instance method of CPromise
Param | Type |
---|---|
data | * |
Make promise chain atomic (non-cancellable for external signals)
Kind: instance method of CPromise
Returns: CPromise
Param | Type |
---|---|
[type] | AtomicType |
throws the CanceledError that cause promise chain cancellation
Kind: instance method of CPromise
Param | Type | Default |
---|---|---|
[reason] |
String | Error
|
|
[forced] | Boolean |
false |
Emit a signal of the specific type
Kind: instance method of CPromise
Param | Type |
---|---|
type | Signal |
[data] | * |
[handler] | SignalHandler |
[locator] | SignalLocator |
Returns a chain that will be resolved after specified timeout
Kind: instance method of CPromise
Param | Type |
---|---|
ms | Number |
Aggregate promise chain into one promise
Kind: instance method of CPromise
Param | Type | Default |
---|---|---|
[weight] | number |
1 |
returns a CPromise. It takes up to two arguments: callback functions for the success and failure cases of the Promise.
Kind: instance method of CPromise
Param | Type |
---|---|
onFulfilled | onFulfilled |
[onRejected] | onRejected |
Catches rejection with optionally specified Error class
Kind: instance method of CPromise
Param | Type |
---|---|
onRejected | function |
[filter] | Error |
Add handler that will be invoked when promise settled
Kind: instance method of CPromise
Param | Type |
---|---|
onFinally | CPFinallyHandler |
Add a handler that will be called after the promise has been fulfilled, but unlike finally
,
the returned plain value will not be ignored
Kind: instance method of CPromise
Param | Type |
---|---|
doneHandler | CPDoneHandler |
Catches CancelError rejection
Kind: instance method of CPromise
Param | Type |
---|---|
[onCanceled] | function |
Listen for abort signal
Kind: instance method of CPromise
Param | Type |
---|---|
signal | AbortSignal |
adds a new listener
Kind: instance method of CPromise
Param | Type | Default |
---|---|---|
type | EventType |
|
listener | function |
|
[prepend] | Boolean |
false |
removes the listener
Kind: instance method of CPromise
Param | Type |
---|---|
type | EventType |
listener | function |
returns listeners count of the specific event type
Kind: instance method of CPromise
Param | Type |
---|---|
type | EventType |
checks if there are listeners of a specific type
Kind: instance method of CPromise
Param | Type |
---|---|
type |
String | Symbol
|
add 'once' listener
Kind: instance method of CPromise
Param | Type |
---|---|
type | EventType |
listener | function |
emits the event
Kind: instance method of CPromise
Param | Type |
---|---|
type | EventType |
...args |
Emits event as a hook. If some listener return true, this method will immediately return true as the result. Else false will be retuned
Kind: instance method of CPromise
Param | Type |
---|---|
type | EventType |
...args |
Render promise to String
Kind: instance method of CPromise
Param | Type | Default | Description |
---|---|---|---|
[entireChain] | boolean |
false |
render the entire promise chain |
CPromise version string
Kind: static property of CPromise
CPromise version number
Kind: static property of CPromise
Checks if thing is an CanceledError instance
Kind: static method of CPromise
Param |
---|
thing |
Returns a CPromise that will be resolved after specified timeout
Kind: static method of CPromise
Param | Type | Default | Description |
---|---|---|---|
ms | Number |
delay before resolve the promise with specified value | |
value | |||
[options] | object |
||
[options.progressTick] | number |
1000 |
progress timer tick, must be >= 100ms |
Returns a single CPromise that resolves to an array of the results of the input promises. If one fails then other promises will be canceled immediately
Kind: static method of CPromise
Param | Type |
---|---|
iterable |
Iterable | Generator | GeneratorFunction | array
|
[options] | CPAllOptions |
Example
CPromise.all(function*(){
yield axios.get(url1);
yield axios.get(url2);
yield axios.get(url3);
}, {concurrency: 1}).then(console.log)
returns a promise that fulfills or rejects as soon as one of the promises in an iterable fulfills or rejects, with the value or reason from that promise. Other pending promises will be canceled immediately
Kind: static method of CPromise
Param | Type |
---|---|
pending | Iterable |
returns a promise that resolves after all of the given promises have either fulfilled or rejected
Kind: static method of CPromise
Param | Type |
---|---|
iterable |
Iterable | Generator | GeneratorFunction
|
[options] | CPAllOptions |
Retry async operation
Kind: static method of CPromise
Param | Type | Default |
---|---|---|
fn |
CPGeneratorRetryFunction | CPRetryFunction
|
|
[options] | Object |
|
[options.args] | Array |
|
[options.retries] | Number |
|
[options.delayWeight] | Number |
|
[options.delay] |
Number | CPRetryDelayResolver
|
|
[options.scopeArg] | Boolean |
false |
Converts thing to CPromise using the following rules:
- CPromise instance returns as is
- Objects with special method defined with key
Symbol.for('toCPromise')
will be converted using this method The result will be cached for future calls - Thenable wraps into a new CPromise instance, if thenable has the
cancel
method it will be used for canceling - Generator function will be resolved to CPromise
- Array will be resoled via
CPromise.all
, arrays with one element (e.g.[[1000]]
) will be resolved viaCPromise.race
This method returns null if the conversion failed.
Kind: static method of CPromise
Param | Type |
---|---|
[thing] | * |
[options] |
resolveOptionsObject | Boolean
|
Converts callback styled function|GeneratorFn|AsyncFn to CPromise async function
Kind: static method of CPromise
Param | Type |
---|---|
originalFn |
function | GeneratorFunction | AsyncFunction
|
[options] |
PromisifyOptions | function | Boolean
|
Resolves the generator to an CPromise instance
Kind: static method of CPromise
Param | Type | Description |
---|---|---|
generatorFn | GeneratorFunction |
|
[options] | Object |
|
[options.args] | Array |
|
[options.resolveSignatures] | Boolean |
resolve extra signatures (like arrays with CPromise.all) |
[options.scopeArg] | Boolean |
pass the CPromise scope as the first argument to the generator function |
[options.context] | * |
Decorator to make CPromise async function from generator, ECMA async or callback-styled method
Kind: static method of CPromise
Param | Type |
---|---|
[options] | object |
[options.timeout] | number |
[options.label] | string |
[options.innerWeight] | number |
[options.weight] | number |
[options.listen] |
AbortControllerId | AbortController | AbortSignal | Array.<(AbortControllerId|AbortController|AbortSignal)>
|
[options.atomic] | AtomicType |
Decorator to subscribe CPromise async method to the internal or external controller
Kind: static method of CPromise
Param | Type |
---|---|
[signals] |
AbortControllerId | AbortController | AbortSignal | Array.<(AbortControllerId|AbortController|AbortSignal)>
|
Decorator to cancel internal or external abort controller before the decorated function invocation.
Can be used as a plain function by passing a object context with .call
or .apply
methods
Kind: static method of CPromise
Param | Type |
---|---|
[reason] | string |
signal |
AbortControllerId | AbortController
|
Example
el.onclick= ()=> cancel.call(this, reason, 'myControllerId'); - to use the decorator as a plain function
Decorator to add an onCanceled
rejection handler to the resulting promise of the decorated method
Kind: static method of CPromise
Param | Type |
---|---|
onCanceledChain |
function | GeneratorFunction
|
Decorator to subscribe the handler to the onProgress
event of the resulting promise
Kind: static method of CPromise
Param | Type |
---|---|
onProgressHandler | ProgressDecoratorHandler |
Decorate class as React component
Kind: static method of CPromise
Param | Type |
---|---|
options |
boolean | ReactComponentDecoratorOptions
|
Decorator to set timeout for the resulting promise of the decorated function
Kind: static method of CPromise
Param | Type |
---|---|
ms | number |
Decorator to set label for the resulting promise of the decorated function
Kind: static method of CPromise
Param | Type |
---|---|
str | string |
Decorator to set innerWeight for the resulting promise of the decorated function
Kind: static method of CPromise
Param | Type |
---|---|
weight | number |
Decorator to set timeout for the resulting promise of the decorated function
Kind: static method of CPromise
Param | Type |
---|---|
atomicType | AtomicType |
append done
chain to the resulting promise of the decorated method
Kind: static method of CPromise
Param | Type |
---|---|
doneHandler | CPDecoratorDoneHandler |
Returns promisification strategy that was used to the original function
Kind: static method of CPromise
Param | Type |
---|---|
fn | function |
Check whether object is CPromise instance
Kind: static method of CPromise
Param | Type | Default |
---|---|---|
thing | * |
|
[anyVersion] | boolean |
false |
Kind: inner typedef of CPromise
Kind: inner typedef of CPromise
this: CPromise
Param | Type |
---|---|
resolve | function |
reject | function |
scope | CPromise |
Kind: inner typedef of CPromise
Properties
Name | Type | Default | Description |
---|---|---|---|
label | String |
||
timeout | Number |
||
weight | Number |
||
[nativeController] | Boolean |
false |
prefer native AbortController class as the internal signal |
If value is a number it will be considered as the value for timeout option If value is a string it will be considered as a label
Kind: inner typedef of CPromise
Kind: inner typedef of CPromise
Param | Type |
---|---|
reason | CanceledError |
Kind: inner typedef of CPromise
Kind: inner typedef of CPromise
Kind: inner typedef of CPromise
Param | Type |
---|---|
CPromise | scope |
Kind: inner typedef of CPromise
Param | Type |
---|---|
value | * |
isRejected | boolean |
Kind: inner typedef of CPromise
Param | Type |
---|---|
type | Signal |
data | * |
Kind: inner typedef of CPromise
Kind: inner typedef of CPromise
Kind: inner typedef of CPromise
this: {CPromise}
Param | Type |
---|---|
data | * |
type | Signal |
scope | CPromise |
Kind: inner typedef of CPromise
this: {CPromise}
Param | Type |
---|---|
data | * |
type | Signal |
scope | CPromise |
isRoot | Boolean |
Kind: inner typedef of CPromise
this: CPromise
Param | Type |
---|---|
settledValue | * |
isRejected | boolean |
scope | CPromise |
Kind: inner typedef of CPromise
this: CPromise
Param | Type |
---|---|
settledValue | * |
isRejected | boolean |
scope | CPromise |
Kind: inner typedef of CPromise
Properties
Name | Type | Description |
---|---|---|
[concurrency] | number |
limit concurrency of promise being run simultaneously |
[mapper] | function |
function to map each element |
[ignoreResults] | boolean |
do not collect results |
[signatures] | boolean |
use advanced signatures for vales resolving |
Kind: inner typedef of CPromise
Param | Type |
---|---|
attempt | number |
args | array |
Kind: inner typedef of CPromise
Param | Type |
---|---|
scope | CPromise |
attempt | number |
args | array |
Kind: inner typedef of CPromise
Returns: number
- a delay in ms before next attempt
Param | Type |
---|---|
attempt | number |
retries | number |
Kind: inner typedef of CPromise
Properties
Name | Type | Default |
---|---|---|
[resolveSignatures] | Boolean |
true |
[atomic] | AtomicType |
true |
[args] | * |
Kind: inner typedef of CPromise
Param | Type |
---|---|
result | * |
scope | CPromise |
Kind: inner typedef of CPromise
Param | Type | Description |
---|---|---|
originalFn | function |
function to decorate |
options | PromisifyOptions |
Kind: inner typedef of CPromise
Properties
Name | Type | Default | Description |
---|---|---|---|
[multiArgs] | Boolean |
aggregate all passed arguments to an array | |
[finalize] | PromisifyFinalizeFn |
aggregate all passed arguments to an array | |
[fnType] |
"plain" | "generator" | "async"
|
||
[scopeArg] | boolean |
pass the CPromise scope as the first argument to the generator function | |
[decorator] | function |
CPPromisifyDecoratorFn | |
[alignArgs] | boolean |
align passed arguments to function definition for callback-styled function | |
[once] | boolean |
true |
don't promisify already promisified function |
[types] | array.<('plain'|'async'|'generator')> |
function types to promisify |
Kind: inner typedef of CPromise
Kind: inner typedef of CPromise
Param | Type |
---|---|
progress | number |
scope | CPromise |
data | * |
context | object |
Kind: inner typedef of CPromise
Properties
Name | Type | Default |
---|---|---|
[subscribeAll] | boolean |
false |
[bindListeners] | boolean |
true |
[bindMethods] | boolean |
true |
Kind: inner typedef of CPromise
Param | Type |
---|---|
value | * |
isRejected | boolean |
scope | CPromise |
context | object |