Interface WritableSignal<T>

Type Parameters:
T - the signal value type
All Superinterfaces:
Signal<T>
All Known Implementing Classes:
NumberSignal, ReferenceSignal, ValueSignal

public interface WritableSignal<T> extends Signal<T>
A signal to which a new value can be directly written.
  • Method Details

    • value

      SignalOperation<T> value(T value)
      Sets the value of this signal. The result of the returned operation will be resolved with the previous value at the time when this operation was confirmed.
      Parameters:
      value - the value to set
      Returns:
      an operation containing the eventual result
    • replace

      SignalOperation<Void> replace(T expectedValue, T newValue)
      Sets the value of this signal if and only if the signal has the expected value at the time when the operation is confirmed. This is the signal counterpart to AtomicReference.compareAndSet(Object, Object). The result of the returned operation will be resolved as successful if the expected value was present and resolved as unsuccessful if any other value was present when the operation is processed.
      Parameters:
      expectedValue - the expected value
      newValue - the new value
      Returns:
      an operation containing the eventual result
    • update

      CancelableOperation<T> update(UnaryOperator<T> updater)
      Updates the signal value based on the given callback. The callback receives the current signal value and returns the new value to use. If the original value has changed by the time this change is confirmed, then the returned value is ignored and the callback is run again with the new value as input. This process is repeated until cancelled or until the update succeeds without conflicting changes.

      The process can be cancelled through the returned operation instance. Note that canceling will only prevent further retries but the change will still be made if the currently running attempt succeeds.

      The result of the returned operation will be resolved with the previous value at the time when a successful update operation was confirmed.

      Update operations cannot participate in transactions since any retry would occur after the original transaction has already been committed. For this reason, the whole operation completely bypasses all transaction handling.

      Parameters:
      updater - the value update callback, not null
      Returns:
      an operation containing the eventual result
    • asReadonly

      default Signal<T> asReadonly()
      Wraps this signal to not accept changes.

      This signal will keep its current configuration and changes applied through this instance will be visible through the wrapped instance.

      Returns:
      the new readonly signal, not null