MimiProcessingParameter

public protocol MimiProcessingParameter<Value> : AnyObject

Protocol for a processing parameter.

MimiProcessingParameter represents a parameter in Mimi Processing, providing publishers for value and state changes, and methods for applying and loading values.

  • Name of the parameter.

    Declaration

    Swift

    var name: String { get }
  • A publisher for tracking value changes related to the MimiProcessingParameter.

    Declaration

    Swift

    var valuePublisher: AnyPublisher<Value, Never> { get }
  • Current value of the parameter.

    Declaration

    Swift

    var value: Value { get }
  • A publisher for tracking state changes related to the MimiProcessingParameter.

    This publisher emits values of type MimiProcessingParameterUpdateState to notify subscribers about changes.

    Note

    The publisher never produces errors (Never), making it suitable for representing a continuous stream of application state updates without failure.

    Example usage:

       // Subscribe to changes of the value application state
       let subscription = processingInstance.updateState
            .sink { state in
               print("Processing parameter update state: \(state)")
       }
    
    Declaration

    Swift

    var updateState: AnyPublisher<MimiProcessingParameterUpdateState<Value>, Never> { get }
  • The data source for the parameter, if available.

    Declaration

    Swift

    var dataSource: AnyMimiProcessingParameterDataSource<Value>? { get }
  • Synchronize the applicator with the current parameter value.

    This function attempts to force update the associated MimiProcessingParameterApplicator instance with the current value of the MimiProcessingParameter.

    Declaration

    Swift

    func synchronizeApplicator() async throws
  • Apply a new value to the parameter.

    This will attempt to apply the provided value on the associated applicator if it is out of date. For the application to succeed, success must be reported by the applicator. If the applicator fails to report success, the application fails, and an error is thrown.

    Applications are serialised per parameter: a call made while another apply(_:), load() or synchronizeApplicator() is in flight waits for it to finish, and the applicator is never invoked concurrently for the same parameter. A call made while the task is cancelled throws CancellationError.

    If the calling task is cancelled while the applicator is already running, the call throws CancellationError at once and the applicator’s task is cancelled, but the applicator is not waited for. updateState then stays .applying until the applicator returns, and reports .applied, after value has been updated, or .failed with the applicator’s error. If another apply(_:), load() or synchronizeApplicator() has started on the parameter by then, the state it reported is left alone and only value is updated, provided the applicator still holds that value. value and updateState can therefore change after the call has thrown. With an applicator that never returns, updateState stays .applying until the next operation on the parameter.

    An application that exceeds the applicator’s timeout is followed up in the same way, except that the call throws applyTimeoutExceeded and updateState reports .failed with that error at once. If the applicator returns successfully afterwards, value is updated and updateState reports .applied, under the same conditions as above; if it throws, the reported timeout stands.

    Warning

    These calls are not reentrant. An applicator or data source must not call apply(_:), load() or synchronizeApplicator() on the parameter it is serving and wait for the result: that call waits for the operation that is already in flight and never completes.

    Declaration

    Swift

    func apply(_ value: Value) async throws
    Parameters
    value

    Value to apply.

  • Load the parameter value from its data source and attempt to apply it.

    This function will attempt to load a new parameter value from a data source if available and then apply it on all registered applicators Effectively this will load() and then apply() the value.

    Loads are serialised with applications: a call made while another load() or apply(_:) is in flight waits for it to finish before loading. If the loaded value is already applied by then, the applicator is not invoked again.

    Note

    If a dataSource is unavailable, then this function will throw a dataSourceUndefined error.
    Declaration

    Swift

    func load() async throws