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.
- Alphabetic
- By Inheritance
- AsyncCallback
- AnyVal
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- Any
- final def ##: Int
- Definition Classes
- Any
- 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.
- 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.
- 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()
- def <<?[B](prev: Option[AsyncCallback[B]]): AsyncCallback[A]
Convenient version of
<<that accepts an Option - def <|(t: (A) => Any): AsyncCallback[A]
Alias for
tap.Alias for
tap.- Annotations
- @inline()
- final def ==(arg0: Any): Boolean
- Definition Classes
- Any
- def >>[B](runNext: AsyncCallback[B]): AsyncCallback[B]
Sequence the argument a callback to run after this, discarding any value produced by this.
- def >>=[B](g: (A) => AsyncCallback[B]): AsyncCallback[B]
Alias for
flatMap.Alias for
flatMap.- Annotations
- @inline()
- def asCallbackToFuture: CallbackTo[Future[A]]
- def asCallbackToJsPromise: CallbackTo[Promise[A]]
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def attempt: AsyncCallback[Either[Throwable, A]]
Wraps this callback in a try-catch and returns either the result or the exception if one occurs.
- def attemptTry: AsyncCallback[Try[A]]
- val completeWith: ((Try[A]) => Callback) => Callback
- def delay(dur: FiniteDuration): AsyncCallback[A]
- def delay(dur: Duration): AsyncCallback[A]
- def delayMs(milliseconds: Double): AsyncCallback[A]
- def distFn[B, C](implicit ev: <:<[AsyncCallback[A], AsyncCallback[(B) => C]]): (B) => AsyncCallback[C]
Function distribution.
Function distribution. See
AsyncCallback.liftTraverse(f).idfor the dual. - def finallyRun[B](runFinally: AsyncCallback[B]): AsyncCallback[A]
Wraps this callback in a
try-finallyblock and runs the given callback in thefinallyclause, after the current callback completes, be it in error or success. - def finallyRunSync[B](runFinally: CallbackTo[B]): AsyncCallback[A]
Wraps this callback in a
try-finallyblock and runs the given callback in thefinallyclause, after the current callback completes, be it in error or success.Wraps this callback in a
try-finallyblock and runs the given callback in thefinallyclause, after the current callback completes, be it in error or success.- Annotations
- @inline()
- 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](implicit ev: (A) => AsyncCallback[B]): AsyncCallback[B]
- def flattenSync[B](implicit ev: (A) => CallbackTo[B]): AsyncCallback[B]
- def getClass(): Class[_ <: AnyVal]
- Definition Classes
- AnyVal → Any
- def handleError(f: (Throwable) => AsyncCallback[A]): AsyncCallback[A]
- def handleErrorSync(f: (Throwable) => CallbackTo[A]): AsyncCallback[A]
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- 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.
- def logResult: AsyncCallback[A]
Logs the result of this callback as it completes.
- 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.
- def logResult(msg: (A) => String): AsyncCallback[A]
Logs the result of this callback as it completes.
- def map[B](f: (A) => B): AsyncCallback[B]
- def maybeHandleError(f: PartialFunction[Throwable, AsyncCallback[A]]): AsyncCallback[A]
- def maybeHandleErrorSync(f: PartialFunction[Throwable, CallbackTo[A]]): AsyncCallback[A]
- def memo(): AsyncCallback[A]
Return a version of this callback that will only execute once, and reuse the result for all other invocations.
- 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.
- 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 forreturn. - def runNow(): Unit
- def setInterval(dur: FiniteDuration): CallbackTo[SetIntervalResult]
Schedule for repeated execution every
dur.Schedule for repeated execution every
dur.- Annotations
- @inline()
- def setInterval(dur: Duration): CallbackTo[SetIntervalResult]
Schedule for repeated execution every
dur.Schedule for repeated execution every
dur.- Annotations
- @inline()
- def setIntervalMs(milliseconds: Double): CallbackTo[SetIntervalResult]
Schedule for repeated execution every x milliseconds.
Schedule for repeated execution every x milliseconds.
- Annotations
- @inline()
- 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()
- 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()
- 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()
- 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.
- def tap(t: (A) => Any): AsyncCallback[A]
When the callback result becomes available, perform a given side-effect with it.
- def toCallback: Callback
- def toString(): String
- Definition Classes
- Any
- def underlyingRepr: ((Try[A]) => Callback) => Callback
- Annotations
- @inline()
- 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
falsefor this callback to execute.- returns
Someresult of the callback executed, elseNone.
- 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
falsefor the callback to execute.
- 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.
- def unsafeToFuture(): Future[A]
- def unsafeToJsPromise(): Promise[A]
- def void: AsyncCallback[Unit]
Discard the value produced by this callback.
- 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()
- def when(cond: => Boolean): AsyncCallback[Option[A]]
Conditional execution of this callback.
Conditional execution of this callback.
- cond
The condition required to be
truefor this callback to execute.- returns
Someresult of the callback executed, elseNone.
- 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
truefor this callback to execute.
- def widen[B >: A]: AsyncCallback[B]
- def zip[B](that: AsyncCallback[B]): AsyncCallback[(A, B)]
- def zipWith[B, C](that: AsyncCallback[B])(f: (A, B) => C): AsyncCallback[C]
- def |>[B](f: (A) => B): AsyncCallback[B]
Alias for
map.Alias for
map.- Annotations
- @inline()