Search code examples
reactivekit

How to model Action in ReactiveKit?


So here's my use case: I have an async task wrapped in a Signal<String, NSError> that effectively executes once, and is no longer relevant (one-shot, essentially).

I'd like to observe or bind the output of this to a text field in my UI, but I can't see a way to do this that doesn't involve hanging on to a reference to the Signal's disposable and manually disposing it myself once the task has completed.

Is there a simpler way of doing this? Ideally there'd be a way to make the Signal release itself when it completes.

I feel like I'm missing something conceptually here.


Solution

  • Signals release their resources once they complete, error out, or if their observer(s) disconnect(s).

    The disposeBag is there to disconnect the observer from the signal, but in your case, it is likely that the signal will have already released all its resources before that happens, because it will complete first.

    In other words, you are overthinking it. The SDK does the right thing without you having to do anything special.