Reactivecocoa: Question - How to convert Signal to SignalProducer?

Created on 5 Nov 2015  路  4Comments  路  Source: ReactiveCocoa/ReactiveCocoa

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!

question

Most helpful comment

This is already available in the framework! :)

let producer = SignalProducer(signal: signal)

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

All 4 comments

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

Time for an update! Thanks :+1:

@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?

This is already available in the framework! :)

let producer = SignalProducer(signal: signal)

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sprynmr picture sprynmr  路  3Comments

RuiAAPeres picture RuiAAPeres  路  3Comments

mdiep picture mdiep  路  5Comments

baei2048 picture baei2048  路  3Comments

porridgec picture porridgec  路  3Comments