Skip to content

Instantly share code, notes, and snippets.

@RuiAAPeres
Last active May 9, 2016 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RuiAAPeres/2b6675d4926fd3d833cb6c02caa1cc78 to your computer and use it in GitHub Desktop.
Save RuiAAPeres/2b6675d4926fd3d833cb6c02caa1cc78 to your computer and use it in GitHub Desktop.

There is retain cycle between the Signal (a Signal is created when you start the producer, hence the name: SignalProducer) and the observer, when you use methods of the family start....

You have three ways to break this cycle:

  • You dispose of the SignalProducer (if you notice, you get a Disposable, when you use a start...). You should avoid doing this, as it goes against RAC best practises
  • You have a way to manipulate the SignalProducer. In your case you do have, by sending complete to the Observer.
  • You use methods like take, takeWhile, until, which will terminate the SignalProducer. This is the prefered way.

Regarding the dispatch. Try this in your viewDidLoad:

timer(3, scheduler: QueueScheduler(name: "hello.scheduler")).map { _ in "hello" }.startWithNext { print($0) }

You will notice that although your viewDidLoad is long gone, it will still print "hello".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment