Pure asynchronous callback.
You can think of this as being similar to using Future
- you can use it in for-comprehensions the same way -
except AsyncCallback
is pure and doesn't need an ExecutionContext
.
When combining instances, it's good to know which methods are sequential and which are parallel (or at least concurrent).
The following methods are sequential:
The following methods are effectively parallel:
In order to actually run this, or get it into a shape in which in can be run, use one of the following:
- toCallback <-- most common
- asCallbackToFuture
- asCallbackToJsPromise
- unsafeToFuture
- unsafeToJsPromise
A good example is the Ajax 2 demo.
- Type Params
- A
The type of data asynchronously produced on success.
- Companion
- object
Value members
Concrete methods
Start both this and the given callback at once and when both have completed successfully, discard the value produced by this.
Start both this and the given callback at once and when both have completed successfully, discard the value produced by this.
Start both this and the given callback at once and when both have completed successfully, discard the value produced by the given callback.
Start both this and the given callback at once and when both have completed successfully, discard the value produced by the given callback.
Sequence a callback to run before this, discarding any value produced by it.
Sequence a callback to run before this, discarding any value produced by it.
Sequence the argument a callback to run after this, discarding any value produced by this.
Sequence the argument a callback to run after this, discarding any value produced by this.
Wraps this callback in a try-catch and returns either the result or the exception if one occurs.
Wraps this callback in a try-catch and returns either the result or the exception if one occurs.
Runs this async computation in the background.
Runs this async computation in the background.
Unlike fork_ this returns an AsyncCallback[Unit]
instead of a Callback
.
Function distribution. See AsyncCallback.liftTraverse(f).id
for the dual.
Function distribution. See AsyncCallback.liftTraverse(f).id
for the dual.
Wraps this callback in a try-finally
block and runs the given callback in the finally
clause, after the
current callback completes, be it in error or success.
Wraps this callback in a try-finally
block and runs the given callback in the finally
clause, after the
current callback completes, be it in error or success.
Wraps this callback in a try-finally
block and runs the given callback in the finally
clause, after the
current callback completes, be it in error or success.
Wraps this callback in a try-finally
block and runs the given callback in the finally
clause, after the
current callback completes, be it in error or success.
Runs this async computation in the background.
Runs this async computation in the background.
Returns the ability for you to await/join the forked computation.
Runs this async computation in the background.
Runs this async computation in the background.
Unlike fork this returns nothing, meaning this is like fire-and-forget.
Log to the console before this callback starts, and after it completes.
Log to the console before this callback starts, and after it completes.
Does not change the result.
Log the duration of this callback's execution.
Log the duration of this callback's execution.
- Value Params
- name
Prefix to appear the log output.
Logs the result of this callback as it completes.
Logs the result of this callback as it completes.
- Value Params
- name
Prefix to appear the log output.
Return a version of this callback that will only execute once, and reuse the result for all other invocations.
Return a version of this callback that will only execute once, and reuse the result for all other invocations.
Start both this and the given callback at once use the first result to become available, regardless of whether it's a success or failure.
Start both this and the given callback at once use the first result to become available, regardless of whether it's a success or failure.
Limits the number of invocations in a given amount of time.
Limits the number of invocations in a given amount of time.
- Returns
Some if invocation was allowed, None if rejected/rate-limited
Limits the number of invocations in a given amount of time.
Limits the number of invocations in a given amount of time.
- Returns
Some if invocation was allowed, None if rejected/rate-limited
Limits the number of invocations in a given amount of time.
Limits the number of invocations in a given amount of time.
- Returns
Some if invocation was allowed, None if rejected/rate-limited
Limits the number of invocations in a given amount of time.
Limits the number of invocations in a given amount of time.
- Returns
Some if invocation was allowed, None if rejected/rate-limited
Limits the number of invocations in a given amount of time.
Limits the number of invocations in a given amount of time.
- Returns
Some if invocation was allowed, None if rejected/rate-limited
If this completes successfully, discard the result.
If any exception occurs, call printStackTrace
and continue.
If this completes successfully, discard the result.
If any exception occurs, call printStackTrace
and continue.
- Since
2.0.0
Discard the callback's return value, return a given value instead.
Discard the callback's return value, return a given value instead.
ret
, short for return
.
Schedule for repeated execution every x milliseconds.
Schedule for repeated execution every x milliseconds.
Schedule for execution after dur
.
Schedule for execution after dur
.
Note: it most cases delay is a better alternative.
Schedule for execution after dur
.
Schedule for execution after dur
.
Note: it most cases delay is a better alternative.
Schedule for execution after x milliseconds.
Schedule for execution after x milliseconds.
Note: it most cases delayMs is a better alternative.
Returns a synchronous Callback that when run, returns the result on the Right if this AsyncCallback is actually synchronous, else returns a new AsyncCallback on the Left that waits for the async computation to complete.
Returns a synchronous Callback that when run, returns the result on the Right if this AsyncCallback is actually synchronous, else returns a new AsyncCallback on the Left that waits for the async computation to complete.
When the callback result becomes available, perform a given side-effect with it.
When the callback result becomes available, perform a given side-effect with it.
Limit the amount of time you're prepared to wait for a computation.
Limit the amount of time you're prepared to wait for a computation.
Note: there's no built-in concept of cancellation here.
If your procedure doesn't finish in time, this will return None
when the time limit is reached however, the
underlying procedure will become orphaned and continue to run in the background until complete.
Limit the amount of time you're prepared to wait for a computation.
Limit the amount of time you're prepared to wait for a computation.
Note: there's no built-in concept of cancellation here.
If your procedure doesn't finish in time, this will return None
when the time limit is reached however, the
underlying procedure will become orphaned and continue to run in the background until complete.
Limit the amount of time you're prepared to wait for a computation.
Limit the amount of time you're prepared to wait for a computation.
Note: there's no built-in concept of cancellation here.
If your procedure doesn't finish in time, this will return None
when the time limit is reached however, the
underlying procedure will become orphaned and continue to run in the background until complete.
THIS IS VERY CONVENIENT IN UNIT TESTS BUT DO NOT RUN THIS IN PRODUCTION CODE.
THIS IS VERY CONVENIENT IN UNIT TESTS BUT DO NOT RUN THIS IN PRODUCTION CODE.
Executes this now, expecting and returning a synchronous result. If there are any asynchronous computations this will throw an exception.
Discard the value produced by this callback.
Discard the value produced by this callback.
This method allows you to be explicit about the type you're discarding (which may change in future).
Conditional execution of this callback.
Conditional execution of this callback.
- Value Params
- cond
The condition required to be
true
for this callback to execute.
- Returns
Some
result of the callback executed, elseNone
.
Conditional execution of this callback. Discards the result.
Conditional execution of this callback. Discards the result.
- Value Params
- cond
The condition required to be
true
for this callback to execute.