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

flatMap(.latest) and delayed inner SignalProducer #749

Closed
TimPapler opened this issue Aug 2, 2019 · 4 comments
Closed

flatMap(.latest) and delayed inner SignalProducer #749

TimPapler opened this issue Aug 2, 2019 · 4 comments

Comments

@TimPapler
Copy link

TimPapler commented Aug 2, 2019

Hello!

The following:

SignalProducer<Int, Never>([ 1, 2, 3, 4 ])
    .flatMap(.latest) { i in
        SignalProducer(value: i)
            .delay(1, on: QueueScheduler.main)
}
    .startWithValues { value in
        print("A", value)
}

Prints nothing 🤔

vs

SignalProducer<Int, Never>([ 1, 2, 3, 4 ])
    .flatMap(.latest) { i in
        SignalProducer.empty
            .delay(1, on: QueueScheduler.main)
            .then(SignalProducer(value: i))
}
    .startWithValues { value in
        print("B", value)
}

prints B 4 🎉

Why is this the case?

@mdiep
Copy link
Contributor

mdiep commented Aug 6, 2019

If you run those exact examples, you won't see the values from the queue scheduler because:

  1. You're not waiting for the value to get send on the main queue
  2. You may be blocking the main queue

The second example will work because the empty completes immediately, which doesn't require a delay and lets the then run immediately.

@TimPapler
Copy link
Author

I made command line tool app with main.swift containing:

import Foundation
import ReactiveSwift

let scheduler = QueueScheduler(qos: .userInitiated)
SignalProducer<Int, Never>([ 1, 2, 3, 4 ])
	.flatMap(.latest) { i in
		SignalProducer(value: i).delay(1, on: scheduler)
	}
	.logEvents()
	.startWithCompleted {
		exit(1)
	}

dispatchMain()

in console i get:

[] starting fileName: /Users/tim/development/Lake2/Carthage/Checkouts/ReactiveSwift/test/main.swift, functionName: test, lineNumber: 17
[] started fileName: /Users/tim/development/Lake2/Carthage/Checkouts/ReactiveSwift/test/main.swift, functionName: test, lineNumber: 17
[] completed fileName: /Users/tim/development/Lake2/Carthage/Checkouts/ReactiveSwift/test/main.swift, functionName: test, lineNumber: 17
[] terminated fileName: /Users/tim/development/Lake2/Carthage/Checkouts/ReactiveSwift/test/main.swift, functionName: test, lineNumber: 17

This prints no value, but does complete. I don't think I am blocking scheduler and I am waiting for values. Sorry for insisting with this 🙈

@mdiep
Copy link
Contributor

mdiep commented Aug 6, 2019

That does seem like it should work. 🤔

@RuiAAPeres
Copy link
Member

Hello. 👋 Thanks for opening this issue. Due to inactivity, we will soft close the issue. If you feel that it should remain open, please let us know. 😄

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

No branches or pull requests

3 participants