Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only next events are forward to an action's observer #2784

Closed
nmarisi opened this issue Apr 7, 2016 · 1 comment
Closed

Only next events are forward to an action's observer #2784

nmarisi opened this issue Apr 7, 2016 · 1 comment
Labels

Comments

@nmarisi
Copy link

@nmarisi nmarisi commented Apr 7, 2016

As far as I can see, only the next events are forwarded to an action's observer. So for example, completed events are ignored.

Here's an example:

buttonAction = Action<Bool, Void, NoError>() { value in

    return SignalProducer<Void, NoError> { observer, _ in
        dataProvider.addNewTestProduct()

        observer.sendNext()
        observer.sendCompleted()
    }

Observing the events signal:

vm.buttonAction.events.observeCompleted {
    print("observed completed")
}
vm.buttonAction.events.observeNext {
    print("observed next")
}

The print statement for the completed event is never triggered (unless the action is deallocated).

It's clear on Action.swift ( line 119), that this is actually happening:

signal.observe { event in
    observer.action(event.mapError { .ProducerError($0) })
    self.eventsObserver.sendNext(event)
}

Is this intended behaviour? Shouldn't the action be forwarding Completed, Failed and Interrupted events too?

@ikesyo ikesyo added the question label Apr 7, 2016
@ikesyo

This comment has been minimized.

Copy link
Member

@ikesyo ikesyo commented Apr 7, 2016

This is intended behavior. Since the signature is public let events: Signal<Event<Output, Error>, NoError>, you can observe the inner producer's Completed events as follows:

vm.buttonAction.events.observeNext { event in
    switch event {
    case let .Next(value): ... // A Next event from the inner producer
    case .Completed: ... // A Completed event from the inner producer
    default: break
    }
}
@ikesyo ikesyo closed this Apr 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.