Skip to content

append does not dispose the second signal #274

Description

@ioninks

Consider the following example:

let periodic = SafeSignal<Int>(sequence: 0..., interval: 1.0)
  .map(String.init)
  .debug("periodic")

let initial = SafeSignal(just: "0")

initial.append(periodic)
  .prefix(maxLength: 3)
  .debug("final")
  .observeNext { _ in }
  .dispose(in: bag)

If we run it, here is what will be printed out:

[final] started
[final] next(0)
[periodic] started
[periodic] next(0)
[final] next(0)
[periodic] next(1)
[final] next(1)
[final] finished
[final] disposed
[periodic] next(2)
[periodic] next(3)
[periodic] next(4)
[periodic] next(5)
...

So as you can see the periodic signal was not disposed and keeps producing elements.

Furthermore, if we replace append(periodic) with merge(with: periodic) it is disposed correctly:

[final] started
[final] next(0)
[periodic] started
[periodic] next(0)
[final] next(0)
[periodic] next(1)
[final] next(1)
[periodic] disposed
[final] finished
[final] disposed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions