Packages

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: - >>=() / flatMap() - >>() & <<() - flatTap()

The following methods are effectively parallel: - *>() & <*() - race() - zip() & zipWith() - AsyncCallback.traverse et al

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](https://japgolly.github.io/scalajs-react/#examples/ajax-2).

A

The type of data asynchronously produced on success.

Self Type
AsyncCallback[A]
Linear Supertypes
AnyVal, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. AsyncCallback
  2. AnyVal
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    Any
  2. final def ##: Int
    Definition Classes
    Any
  3. 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.

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

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

    Annotations
    @inline()
  6. def <<?[B](prev: Option[AsyncCallback[B]]): AsyncCallback[A]

    Convenient version of << that accepts an Option

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

    Alias for tap.

    Alias for tap.

    Annotations
    @inline()
  8. final def ==(arg0: Any): Boolean
    Definition Classes
    Any
  9. def >>[B](runNext: AsyncCallback[B]): AsyncCallback[B]

    Sequence the argument a callback to run after this, discarding any value produced by this.

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

    Alias for flatMap.

    Alias for flatMap.

    Annotations
    @inline()
  11. def asCallbackToFuture: CallbackTo[Future[A]]
  12. def asCallbackToJsPromise: CallbackTo[Promise[A]]
  13. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  14. def attempt: AsyncCallback[Either[Throwable, A]]

    Wraps this callback in a try-catch and returns either the result or the exception if one occurs.

  15. def attemptTry: AsyncCallback[Try[A]]
  16. def completeWith(f: (Try[A]) => Callback): Callback
  17. def debounce(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.

  18. def debounce(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.

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

  20. def delay(dur: FiniteDuration): AsyncCallback[A]
  21. def delay(dur: Duration): AsyncCallback[A]
  22. def delayMs(milliseconds: Double): AsyncCallback[A]
  23. 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.

  24. def distFn[B, C](implicit ev: <:<[AsyncCallback[A], AsyncCallback[(B) => C]]): (B) => AsyncCallback[C]

    Function distribution.

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

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

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

    Annotations
    @inline()
  27. def flatMap[B](f: (A) => AsyncCallback[B]): AsyncCallback[B]
  28. def flatMapSync[B](f: (A) => CallbackTo[B]): AsyncCallback[B]
  29. def flatTap[B](t: (A) => AsyncCallback[B]): AsyncCallback[A]
  30. def flatTapSync[B](t: (A) => CallbackTo[B]): AsyncCallback[A]
  31. def flatten[B](implicit ev: (A) => AsyncCallback[B]): AsyncCallback[B]
  32. def flattenSync[B](implicit ev: (A) => CallbackTo[B]): AsyncCallback[B]
  33. def fork: CallbackTo[Forked[A]]

    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.

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

  35. def getClass(): Class[_ <: AnyVal]
    Definition Classes
    AnyVal → Any
  36. def handleError[AA >: A](f: (Throwable) => AsyncCallback[AA]): AsyncCallback[AA]
  37. def handleErrorSync[AA >: A](f: (Throwable) => CallbackTo[AA]): AsyncCallback[AA]
  38. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  39. 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.

  40. def logDuration: AsyncCallback[A]

    Log the duration of this callback's execution.

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

    Log the duration of this callback's execution.

    Log the duration of this callback's execution.

    name

    Prefix to appear the log output.

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

    Log the duration of this callback's execution.

  43. def logResult: AsyncCallback[A]

    Logs the result of this callback as it completes.

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

    Logs the result of this callback as it completes.

    Logs the result of this callback as it completes.

    name

    Prefix to appear the log output.

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

    Logs the result of this callback as it completes.

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

    Return a version of this callback that will only execute once, and reuse the result for all other invocations.

  50. def onCancel(f: AsyncCallback[Unit]): AsyncCallback[A]
  51. 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.

  52. def rateLimit(window: FiniteDuration, 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.

    returns

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

  53. def rateLimit(window: Duration, 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.

    returns

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

  54. def rateLimit(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.

    returns

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

  55. def rateLimit(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.

    returns

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

  56. def rateLimitMs(windowMs: Long, maxPerWindow: Int = 1): 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.

    returns

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

  57. def reset: AsyncCallback[Unit]

    If this completes successfully, discard the result.

    If this completes successfully, discard the result. If any exception occurs, call printStackTrace and continue.

    Since

    2.0.0

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

  59. def runNow(): Unit
  60. def setInterval(dur: FiniteDuration): CallbackTo[SetIntervalResult]

    Schedule for repeated execution every dur.

    Schedule for repeated execution every dur.

    Annotations
    @inline()
  61. def setInterval(dur: Duration): CallbackTo[SetIntervalResult]

    Schedule for repeated execution every dur.

    Schedule for repeated execution every dur.

    Annotations
    @inline()
  62. def setIntervalMs(milliseconds: Double): CallbackTo[SetIntervalResult]

    Schedule for repeated execution every x milliseconds.

    Schedule for repeated execution every x milliseconds.

    Annotations
    @inline()
  63. def setTimeout(dur: FiniteDuration): CallbackTo[SetTimeoutResult]

    Schedule for execution after dur.

    Schedule for execution after dur.

    Note: it most cases delay() is a better alternative.

    Annotations
    @inline()
  64. def setTimeout(dur: Duration): CallbackTo[SetTimeoutResult]

    Schedule for execution after dur.

    Schedule for execution after dur.

    Note: it most cases delay() is a better alternative.

    Annotations
    @inline()
  65. def setTimeoutMs(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.

    Annotations
    @inline()
  66. 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.

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

    When the callback result becomes available, perform a given side-effect with it.

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

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

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

  71. def toCallback: Callback
  72. def toString(): String
    Definition Classes
    Any
  73. val underlyingRepr: UnderlyingRepr[A]
  74. def unless(cond: => Boolean): AsyncCallback[Option[A]]

    Conditional execution of this callback.

    Conditional execution of this callback. Reverse of when().

    cond

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

    returns

    Some result of the callback executed, else None.

  75. def unless_(cond: => Boolean): AsyncCallback[Unit]

    Conditional execution of this callback.

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

    cond

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

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

  77. def unsafeToFuture(): Future[A]
  78. def unsafeToJsPromise(): Promise[A]
  79. def void: AsyncCallback[Unit]

    Discard the value produced by this callback.

  80. def voidExplicit[B](implicit 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).

    Annotations
    @inline()
  81. def when(cond: => Boolean): AsyncCallback[Option[A]]

    Conditional execution of this callback.

    Conditional execution of this callback.

    cond

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

    returns

    Some result of the callback executed, else None.

  82. def when_(cond: => Boolean): AsyncCallback[Unit]

    Conditional execution of this callback.

    Conditional execution of this callback. Discards the result.

    cond

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

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

    Record the duration of this callback's execution.

  84. def withFilter(f: (A) => Boolean): AsyncCallback[A]
  85. def zip[B](that: AsyncCallback[B]): AsyncCallback[(A, B)]
  86. def zipWith[B, C](that: AsyncCallback[B])(f: (A, B) => C): AsyncCallback[C]
  87. def |>[B](f: (A) => B): AsyncCallback[B]

    Alias for map.

    Alias for map.

    Annotations
    @inline()

Inherited from AnyVal

Inherited from Any

Ungrouped