Class/Object

japgolly.scalajs.react

AsyncCallback

Related Docs: object AsyncCallback | package react

Permalink

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.

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

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    Any
  3. def *>[B](next: AsyncCallback[B]): AsyncCallback[B]

    Permalink

    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]

    Permalink

    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]

    Permalink

    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]

    Permalink

    Convenient version of << that accepts an Option

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

    Permalink

    Alias for tap.

    Alias for tap.

    Annotations
    @inline()
  8. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  9. def >>[B](runNext: AsyncCallback[B]): AsyncCallback[B]

    Permalink

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

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

    Permalink

    Alias for flatMap.

    Alias for flatMap.

    Annotations
    @inline()
  11. def asCallbackToFuture: CallbackTo[Future[A]]

    Permalink
  12. def asCallbackToJsPromise: CallbackTo[Promise[A]]

    Permalink
  13. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  14. def attempt: AsyncCallback[Either[Throwable, A]]

    Permalink

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

  15. def attemptTry: AsyncCallback[Try[A]]

    Permalink
  16. val completeWith: ((Try[A]) ⇒ Callback) ⇒ Callback

    Permalink
  17. def delay(dur: FiniteDuration): AsyncCallback[A]

    Permalink
  18. def delayMs(milliseconds: Double): AsyncCallback[A]

    Permalink
  19. def distFn[B, C](implicit ev: <:<[AsyncCallback[A], AsyncCallback[(B) ⇒ C]]): (B) ⇒ AsyncCallback[C]

    Permalink

    Function distribution.

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

  20. def flatMap[B](f: (A) ⇒ AsyncCallback[B]): AsyncCallback[B]

    Permalink
  21. def flatTap[B](t: (A) ⇒ AsyncCallback[B]): AsyncCallback[A]

    Permalink
  22. def flatten[B](implicit ev: (A) ⇒ AsyncCallback[B]): AsyncCallback[B]

    Permalink
  23. def getClass(): Class[_ <: AnyVal]

    Permalink
    Definition Classes
    AnyVal → Any
  24. def handleError(f: (Throwable) ⇒ AsyncCallback[A]): AsyncCallback[A]

    Permalink
  25. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  26. def logAround(message: Any, optionalParams: Any*): AsyncCallback[A]

    Permalink

    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.

  27. def logResult: AsyncCallback[A]

    Permalink

    Logs the result of this callback as it completes.

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

    Permalink

    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.

  29. def logResult(msg: (A) ⇒ String): AsyncCallback[A]

    Permalink

    Logs the result of this callback as it completes.

  30. def map[B](f: (A) ⇒ B): AsyncCallback[B]

    Permalink
  31. def maybeHandleError(f: PartialFunction[Throwable, AsyncCallback[A]]): AsyncCallback[A]

    Permalink
  32. def memo(): AsyncCallback[A]

    Permalink

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

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

    Permalink

    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.

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

    Permalink

    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.

  35. def tap(t: (A) ⇒ Any): AsyncCallback[A]

    Permalink

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

  36. def toCallback: Callback

    Permalink
  37. def toString(): String

    Permalink
    Definition Classes
    Any
  38. def unless(cond: ⇒ Boolean): AsyncCallback[Option[A]]

    Permalink

    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.

  39. def unless_(cond: ⇒ Boolean): AsyncCallback[Unit]

    Permalink

    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.

  40. def unsafeToFuture(): Future[A]

    Permalink
  41. def unsafeToJsPromise(): Promise[A]

    Permalink
  42. def void: AsyncCallback[Unit]

    Permalink

    Discard the value produced by this callback.

  43. def voidExplicit[B](implicit ev: <:<[A, B]): AsyncCallback[Unit]

    Permalink

    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()
  44. def when(cond: ⇒ Boolean): AsyncCallback[Option[A]]

    Permalink

    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.

  45. def when_(cond: ⇒ Boolean): AsyncCallback[Unit]

    Permalink

    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.

  46. def widen[B >: A]: AsyncCallback[B]

    Permalink
  47. def zip[B](that: AsyncCallback[B]): AsyncCallback[(A, B)]

    Permalink
  48. def zipWith[B, C](that: AsyncCallback[B])(f: (A, B) ⇒ C): AsyncCallback[C]

    Permalink
  49. def |>[B](f: (A) ⇒ B): AsyncCallback[B]

    Permalink

    Alias for map.

    Alias for map.

    Annotations
    @inline()

Inherited from AnyVal

Inherited from Any

Ungrouped