A function to be executed later, usually by scalajs-react in response to some kind of event.
The purpose of this class is to lift effects into the type system, and use the compiler to ensure safety around callbacks (without depending on an external library like Cats).
() => Unit
is replaced by Callback
.
Similarly, ReactEvent => Unit
is replaced by ReactEvent => Callback
.
- Type Params
- A
The type of result produced when the callback is invoked.
- Since
0.10.0
- Companion
- object
Value members
Concrete methods
Creates a new callback that returns true
when both this and the given callback return true
.
Creates a new callback that returns true
when both this and the given callback return true
.
Alias for >>
.
Alias for >>
.
Where >>
is often associated with Monads, *>
is often associated with Applicatives.
Sequence actions, discarding the value of the second argument.
Sequence actions, discarding the value of the second argument.
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 a callback to run after this, discarding any value produced by this.
Sequence a callback to run after this, discarding any value produced by this.
Turns this into an AsyncCallback that runs whenever/wherever it's called;
setTimeout
isn't used.
Turns this into an AsyncCallback that runs whenever/wherever it's called;
setTimeout
isn't used.
In order words, this.toAsyncCallback.toCallback
== this
.
Schedules this to run asynchronously (i.e. uses a setTimeout
).
Schedules this to run asynchronously (i.e. uses a setTimeout
).
Exceptions will be handled by the AsyncCallback such that
this.async.toCallback
will never throw an exception.
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.
Run asynchronously after a delay of a given duration.
Run asynchronously after a delay of a given duration.
Run asynchronously after a delay of a given duration.
Run asynchronously after a delay of a given duration.
Run asynchronously after a startInMilliseconds
ms delay.
Run asynchronously after a startInMilliseconds
ms delay.
Function distribution. See CallbackTo.liftTraverse(f).id
for the dual.
Function distribution. See CallbackTo.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.
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.
Convenience-method to run additional code before this callback.
Convenience-method to run additional code before this callback.
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
Returns a CallbackOption that requires the boolean value therein to be true.
Returns a CallbackOption that requires the boolean value therein to be true.
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
.
Executes this callback, on the current thread, right now, blocking until complete. Exceptions will not be thrown, not caught. Use CallbackTo#attempt to catch exceptions.
Executes this callback, on the current thread, right now, blocking until complete. Exceptions will not be thrown, not caught. Use CallbackTo#attempt to catch exceptions.
Typically, callbacks are passed to scalajs-react and you're expected not to call this method yourself. Generally speaking, the only time you should call this method is in some other non-React code's async callback. Inside an AJAX callback is a common example. Even for those cases though, you can avoid calling this by getting direct access instead of callback-based access to your component; see the online WebSockets example: https://japgolly.github.io/scalajs-react/#examples/websockets
While it's technically safe to call CallbackTo#runNow inside the body of another Callback, it's better to just use combinators like CallbackTo#flatMap or even a Scala for-comprehension.
Schedule this callback for repeated execution every interval
milliseconds.
Schedule this callback for repeated execution every interval
milliseconds.
- Value Params
- interval
duration in milliseconds between executions
- Returns
A means to cancel the interval.
Schedule this callback for execution in interval
.
Schedule this callback for execution in interval
.
Note: in most cases delay is a better alternative.
- Returns
A means to cancel the timeout.
Schedule this callback for execution in interval
.
Schedule this callback for execution in interval
.
Note: in most cases delay is a better alternative.
- Returns
A means to cancel the timeout.
Schedule this callback for execution in interval
milliseconds.
Schedule this callback for execution in interval
milliseconds.
Note: in most cases delayMs is a better alternative.
- Value Params
- interval
duration in milliseconds to wait
- Returns
A means to cancel the timeout.
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.
Convenience-method to run additional code after this callback.
Convenience-method to run additional code after this callback.
Negates the callback result (so long as it's boolean).
Negates the callback result (so long as it's boolean).
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.
Creates a new callback that returns true
when either this or the given callback return true
.
Creates a new callback that returns true
when either this or the given callback return true
.
Deprecated methods
Negates the callback result (so long as it's boolean).
Negates the callback result (so long as it's boolean).
- Deprecated