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

Question - How to convert Signal to SignalProducer? #2539

Closed
danishin opened this issue Nov 5, 2015 · 4 comments
Closed

Question - How to convert Signal to SignalProducer? #2539

danishin opened this issue Nov 5, 2015 · 4 comments
Labels

Comments

@danishin
Copy link

danishin commented Nov 5, 2015

I've recently started to convert from RAC 3 to RAC 4 and found out that takeUntil on SignalProducer now accepts SignalProducer as opposed to Signal in RAC 3.

This is my current method in extension SignalType and it feels pretty hackish:

func toSignalProducer() -> SignalProducer<T, E> {
  return SignalProducer { (sink, _) in
    self.observe(
      next: { t in sendNext(sink, t) },
      completed: { _ in sendCompleted(sink) }
    )
  }
}

Can I improve this? Thanks!

@ikesyo
Copy link
Member

ikesyo commented Nov 5, 2015

There is a takeUntil overload of SignalProducer that takes a Signal from v4.0.0-alpha.2: https://github.com/ReactiveCocoa/ReactiveCocoa/blob/v4.0.0-alpha.2/ReactiveCocoa/Swift/SignalProducer.swift#L557

@ikesyo ikesyo added the question label Nov 5, 2015
@danishin
Copy link
Author

danishin commented Nov 6, 2015

Time for an update! Thanks 👍

@danishin danishin closed this as completed Nov 6, 2015
@danishin
Copy link
Author

danishin commented Nov 6, 2015

@ikesyo Just for curiosity, is my approach of converting Signal to SignalProducer sub-optimal? Can this be done better? I see most interoperability between Signal and SignalProducer comes by lifting Signal's operators to accept SignalProducer (and rightly so). Is converting Signal to SignalProducer frowned upon?

@danishin danishin reopened this Nov 6, 2015
@danishin danishin changed the title Question - How to lift Signal to SignalProducer? Question - How to convert Signal to SignalProducer? Nov 6, 2015
@NachoSoto
Copy link
Member

This is already available in the framework! :)

let producer = SignalProducer(signal: signal)

That essentially creates a producer with no side effects (see #2449)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants