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

.share() inconsistent in behavior #1242

Closed
5 of 17 tasks
nightfall708 opened this issue May 8, 2017 · 6 comments
Closed
5 of 17 tasks

.share() inconsistent in behavior #1242

nightfall708 opened this issue May 8, 2017 · 6 comments

Comments

@nightfall708
Copy link

nightfall708 commented May 8, 2017

Hi guys, I want to discuss this scenario, regarding share() operator.
For this code:

let s = numbers1.scan(0) { prev, input in
    print("Scan")
    return prev+input
}.share()

s.subscribe(onNext: { x in
        print("\(x)")
    }, onCompleted: {
        print("-------------")
    })

s.subscribe(onNext: { x in
    print("\(x)")
}, onCompleted: nil)

This input ("A"):

let numbers1 = Observable<Int>.create { observer in
    let start = getStartNumber()
    observer.onNext(start)
    observer.onNext(start+1)
    observer.onNext(start+2)
    observer.onCompleted()
    return Disposables.create()
}

Will result with:

Scan
1
Scan
3
Scan
6
-------------
Scan
Scan
Scan

However this input ("B"):

let numbers1 = Observable.from([1,2,3])

Will result with this:

Scan
1
Scan
3
Scan
6
-------------

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

3.2.0

Platform/Environment

  • iOS
  • macOS
  • tvOS
  • watchOS
  • playgrounds

How easy is to reproduce? (chances of successful reproduce after running the self contained code)

  • easy, 100% repro
  • sometimes, 10%-100%
  • hard, 2% - 10%
  • extremely hard, %0 - 2%

Xcode version:

  8.3.2

Installation method:

  • CocoaPods
  • Carthage
  • Git submodules

I have multiple versions of Xcode installed:
(so we can know if this is a potential cause of your issue)

  • yes (which ones)
  • no

Level of RxSwift knowledge:
(this is so we can understand your level of knowledge
and formulate the response in an appropriate manner)

  • just starting
  • I have a small code base
  • I have a significant code base
@kzaher
Copy link
Member

kzaher commented May 9, 2017

Hi @switchawk ,

This is a dupe of #1111 and #1155.

This is next thing to solve on my list. The problem isn't in us changing it in this repo.

Problem is figuring out how will we keep consistent this behavior with other implementations. I'll need to open issues in RxJs and RxJava repos probably.

But yes, we'll improve this.

@kzaher
Copy link
Member

kzaher commented May 9, 2017

If you want a temporary workaround for this, just add subscribeOn(CurrentThreadScheduler.instance) in front of share.

let s = numbers1.scan(0) { prev, input in
        print("Scan")
        return prev+input
}.subscribeOn(CurrentThreadScheduler.instance).share()

@RafaelPlantard
Copy link

Any news @kzaher?

@kzaher
Copy link
Member

kzaher commented May 16, 2017

Hi @RafaelPlantard ,

this is the next thing on my list. I'm on a business trip in China until the end of this week. I will only do CRs until I return from the trip.

It's little hard to do a lot of things in parallel :)

@RafaelPlantard
Copy link

Thanks @kzaher

@kzaher
Copy link
Member

kzaher commented May 29, 2017

Hi guys,

As far as I can tell, #1275 should fix this. Let me know if it doesn't.

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