AsyncCallback

japgolly.scalajs.react.callback.AsyncCallback
See theAsyncCallback companion object
final class AsyncCallback[+A] extends AnyVal

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:

A good example is the Ajax 2 demo.

Type parameters

A

The type of data asynchronously produced on success.

Attributes

Companion
object
Graph
Supertypes
class AnyVal
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def *>[B](next: AsyncCallback[B]): AsyncCallback[B]

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.

Attributes

def <*[B](next: AsyncCallback[B]): AsyncCallback[A]

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.

Attributes

inline def <<[B](runBefore: AsyncCallback[B]): AsyncCallback[A]

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.

Attributes

def <<?[B](prev: Option[AsyncCallback[B]]): AsyncCallback[A]

Convenient version of << that accepts an Option

Convenient version of << that accepts an Option

Attributes

inline def <|(t: A => Any): AsyncCallback[A]

Alias for tap.

Alias for tap.

Attributes

def >>[B](runNext: AsyncCallback[B]): AsyncCallback[B]

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.

Attributes

inline def >>=[B](inline g: A => AsyncCallback[B]): AsyncCallback[B]

Alias for flatMap.

Alias for flatMap.

Attributes

def asCallbackToFuture: CallbackTo[Future[A]]
def attempt: AsyncCallback[Either[Throwable, A]]

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.

Attributes

def attemptTry: AsyncCallback[Try[A]]
def completeWith(f: Try[A] => Callback): Callback
inline def debounce(inline delay: Duration): AsyncCallback[A]

Creates an debounce boundary over the underlying computation.

Creates an debounce boundary over the underlying computation.

Save the result of this as a val somewhere because it relies on internal state that must be reused.

Attributes

inline def debounce(inline delay: FiniteDuration): AsyncCallback[A]

Creates an debounce boundary over the underlying computation.

Creates an debounce boundary over the underlying computation.

Save the result of this as a val somewhere because it relies on internal state that must be reused.

Attributes

def debounceMs(delayMs: Long): AsyncCallback[A]

Creates an debounce boundary over the underlying computation.

Creates an debounce boundary over the underlying computation.

Save the result of this as a val somewhere because it relies on internal state that must be reused.

Attributes

def delay(dur: Duration): AsyncCallback[A]
def delay(dur: FiniteDuration): AsyncCallback[A]
def delayMs(milliseconds: Double): AsyncCallback[A]
def dispatch: AsyncCallback[Unit]

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.

Attributes

def distFn: A => AsyncCallback[B]
Extension method from AsyncCallback

Function distribution. See AsyncCallback.liftTraverse(f).id for the dual.

Function distribution. See AsyncCallback.liftTraverse(f).id for the dual.

Attributes

def finallyRun[B](runFinally: AsyncCallback[B]): AsyncCallback[A]

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.

Attributes

inline def finallyRunSync[B](runFinally: CallbackTo[B]): AsyncCallback[A]

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.

Attributes

def flatMap[B](f: A => AsyncCallback[B]): AsyncCallback[B]
def flatMapSync[B](f: A => CallbackTo[B]): AsyncCallback[B]
def flatTap[B](t: A => AsyncCallback[B]): AsyncCallback[A]
def flatTapSync[B](t: A => CallbackTo[B]): AsyncCallback[A]
def flatten[B](using ev: A => AsyncCallback[B]): AsyncCallback[B]
def flattenSync[B](using ev: A => CallbackTo[B]): AsyncCallback[B]

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.

Attributes

inline def fork_: Callback

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.

Attributes

def handleError[AA >: A](f: Throwable => AsyncCallback[AA]): AsyncCallback[AA]
def handleErrorSync[AA >: A](f: Throwable => CallbackTo[AA]): AsyncCallback[AA]
def logAround(message: Any, optionalParams: Any*): AsyncCallback[A]

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.

Attributes

def logDuration(fmt: FiniteDuration => String): AsyncCallback[A]

Log the duration of this callback's execution.

Log the duration of this callback's execution.

Attributes

def logDuration(name: String): AsyncCallback[A]

Log the duration of this callback's execution.

Log the duration of this callback's execution.

Value parameters

name

Prefix to appear the log output.

Attributes

Log the duration of this callback's execution.

Log the duration of this callback's execution.

Attributes

def logResult(msg: A => String): AsyncCallback[A]

Logs the result of this callback as it completes.

Logs the result of this callback as it completes.

Attributes

def logResult(name: String): AsyncCallback[A]

Logs the result of this callback as it completes.

Logs the result of this callback as it completes.

Value parameters

name

Prefix to appear the log output.

Attributes

Logs the result of this callback as it completes.

Logs the result of this callback as it completes.

Attributes

def map[B](f: A => B): AsyncCallback[B]
def maybeHandleError[AA >: A](f: PartialFunction[Throwable, AsyncCallback[AA]]): AsyncCallback[AA]
def maybeHandleErrorSync[AA >: A](f: PartialFunction[Throwable, CallbackTo[AA]]): AsyncCallback[AA]
def memo(): AsyncCallback[A]

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.

Attributes

def race[B](that: AsyncCallback[B]): AsyncCallback[Either[A, B]]

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.

Attributes

inline def rateLimit(inline window: Duration): AsyncCallback[Option[A]]

Limits the number of invocations in a given amount of time.

Limits the number of invocations in a given amount of time.

Attributes

Returns

Some if invocation was allowed, None if rejected/rate-limited

inline def rateLimit(inline window: FiniteDuration): AsyncCallback[Option[A]]

Limits the number of invocations in a given amount of time.

Limits the number of invocations in a given amount of time.

Attributes

Returns

Some if invocation was allowed, None if rejected/rate-limited

inline def rateLimit(inline window: Duration, inline maxPerWindow: Int): AsyncCallback[Option[A]]

Limits the number of invocations in a given amount of time.

Limits the number of invocations in a given amount of time.

Attributes

Returns

Some if invocation was allowed, None if rejected/rate-limited

inline def rateLimit(inline window: FiniteDuration, inline maxPerWindow: Int): AsyncCallback[Option[A]]

Limits the number of invocations in a given amount of time.

Limits the number of invocations in a given amount of time.

Attributes

Returns

Some if invocation was allowed, None if rejected/rate-limited

def rateLimitMs(windowMs: Long, maxPerWindow: Int): AsyncCallback[Option[A]]

Limits the number of invocations in a given amount of time.

Limits the number of invocations in a given amount of time.

Attributes

Returns

Some if invocation was allowed, None if rejected/rate-limited

def reset: AsyncCallback[Unit]

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.

Attributes

Since

2.0.0

def ret[B](b: B): AsyncCallback[B]

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.

Attributes

def runNow(): Unit
inline def setInterval(inline dur: Duration): CallbackTo[SetIntervalResult]

Schedule for repeated execution every dur.

Schedule for repeated execution every dur.

Attributes

inline def setInterval(inline dur: FiniteDuration): CallbackTo[SetIntervalResult]

Schedule for repeated execution every dur.

Schedule for repeated execution every dur.

Attributes

inline def setIntervalMs(inline milliseconds: Double): CallbackTo[SetIntervalResult]

Schedule for repeated execution every x milliseconds.

Schedule for repeated execution every x milliseconds.

Attributes

inline def setTimeout(inline dur: Duration): CallbackTo[SetTimeoutResult]

Schedule for execution after dur.

Schedule for execution after dur.

Note: it most cases delay is a better alternative.

Attributes

inline def setTimeout(inline dur: FiniteDuration): CallbackTo[SetTimeoutResult]

Schedule for execution after dur.

Schedule for execution after dur.

Note: it most cases delay is a better alternative.

Attributes

inline def setTimeoutMs(inline milliseconds: Double): CallbackTo[SetTimeoutResult]

Schedule for execution after x milliseconds.

Schedule for execution after x milliseconds.

Note: it most cases delayMs is a better alternative.

Attributes

def sync: CallbackTo[Either[AsyncCallback[A], A]]

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.

Attributes

def tap(t: A => Any): AsyncCallback[A]

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.

Attributes

def timeout(limit: Duration): AsyncCallback[Option[A]]

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.

Attributes

def timeout(limit: FiniteDuration): AsyncCallback[Option[A]]

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.

Attributes

def timeoutMs(milliseconds: Double): AsyncCallback[Option[A]]

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.

Attributes

inline def unless(inline cond: Boolean): AsyncCallback[Option[A]]

Conditional execution of this callback. Reverse of when.

Conditional execution of this callback. Reverse of when.

Value parameters

cond

The condition required to be false for this callback to execute.

Attributes

Returns

Some result of the callback executed, else None.

inline def unless_(inline cond: Boolean): AsyncCallback[Unit]

Conditional execution of this callback. Discards the result. Reverse of when_.

Conditional execution of this callback. Discards the result. Reverse of when_.

Value parameters

cond

The condition required to be false for the callback to execute.

Attributes

def unsafeRunNowSync(): A

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.

Attributes

def unsafeToFuture(): Future[A]
def unsafeToJsPromise(): Promise[A]
def void: AsyncCallback[Unit]

Discard the value produced by this callback.

Discard the value produced by this callback.

Attributes

inline def voidExplicit[B](using inline ev: A <:< B): AsyncCallback[Unit]

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).

Attributes

def when(cond: => Boolean): AsyncCallback[Option[A]]

Conditional execution of this callback.

Conditional execution of this callback.

Value parameters

cond

The condition required to be true for this callback to execute.

Attributes

Returns

Some result of the callback executed, else None.

inline def when_(inline cond: Boolean): AsyncCallback[Unit]

Conditional execution of this callback. Discards the result.

Conditional execution of this callback. Discards the result.

Value parameters

cond

The condition required to be true for this callback to execute.

Attributes

def withDuration[B](f: (A, FiniteDuration) => AsyncCallback[B]): AsyncCallback[B]

Record the duration of this callback's execution.

Record the duration of this callback's execution.

Attributes

def withFilter(f: A => Boolean): AsyncCallback[A]
def zip[B](that: AsyncCallback[B]): AsyncCallback[(A, B)]
def zipWith[B, C](that: AsyncCallback[B])(f: (A, B) => C): AsyncCallback[C]
inline def |>[B](f: A => B): AsyncCallback[B]

Alias for map.

Alias for map.

Attributes

Concrete fields

val underlyingRepr: () => A