ReactiveX/RxSwift

asSingle -> Sequence contains more than one element.

EE-Yat-Ho opened this issue · 5 comments

Short description of the issue:

asSingle does not forwardOn the value entered as next.
When Subject or Observable is changed to asSingle, it does not work properly.

Expected outcome:

It works normally when you change Subject or Observable to asSingle.

Self contained code example that reproduces the issue:

let ps = PublishSubject()
let disposeBag = DisposeBag()

ps.asSingle()
    .subscribe(onSuccess: { string in
        print("❔ onSuccess \(string)")
    }, onFailure: { error in
        print("❔ onFailure \(error)")
    }, onDisposed: {
        print("❔ onDisposed")
    })
    .disposed(by: disposeBag)

ps.onNext("a")
// not thing print
ps.onNext("b")
// print "❔ onFailure Sequence contains more than one element."
// print "❔ onDisposed"

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:

15.1

⚠️ Fields below are optional for general issues or in case those questions aren't related to your issue, but filling them out will increase the chances of getting your issue resolved. ⚠️

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

I would like to add the code below to .next of AsSingleSink.

self.forwardOn(element)
self.forwardOn(.completed)

That is as designed. In your case, use ps.take(1).asSingle()

“completed” is issued when “take” receives the specified number of events.
Great.

Short description of the issue:

asSingle does not forwardOn the value entered as next.

When Subject or Observable is changed to asSingle, it does not work properly.

Expected outcome:

It works normally when you change Subject or Observable to asSingle.

Self contained code example that reproduces the issue:

let ps = PublishSubject()

let disposeBag = DisposeBag()



ps.asSingle()

    .subscribe(onSuccess: { string in

        print("❔ onSuccess \(string)")

    }, onFailure: { error in

        print("❔ onFailure \(error)")

    }, onDisposed: {

        print("❔ onDisposed")

    })

    .disposed(by: disposeBag)



ps.onNext("a")

// not thing print

ps.onNext("b")

// print "❔ onFailure Sequence contains more than one element."

// print "❔ onDisposed"

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:


15.1

⚠️ Fields below are optional for general issues or in case those questions aren't related to your issue, but filling them out will increase the chances of getting your issue resolved. ⚠️

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

@Efebyts I'm not sure why you quoted the original message to this closed topic... Care to elaborate?