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 completes before inner observable #5

Open
veyh opened this issue Oct 20, 2020 · 0 comments
Open

flatMap completes before inner observable #5

veyh opened this issue Oct 20, 2020 · 0 comments

Comments

@veyh
Copy link

veyh commented Oct 20, 2020

Hey, thanks for mentioning this fork in the originial repo. Looks good but I found something off with flatMap. It seems to complete even before the inner observable does. For example

local a = Subject.create()

Observable.of(1)
  :flatMap(function ()
    return a
  end)
  :dump()

prints

onCompleted

which is not what I expected, as the equivalent in rxjs prints nothing:

const { of, Subject } = require("rxjs");
const { flatMap } = require("rxjs/operators");
const a = new Subject;

of(1).pipe(
  flatMap(() => a)
)
.subscribe(
  value => console.log("onNext", value),
  err => console.log("onError", err),
  () => console.log("onCompleted")
);

And if I were to run this

local a = Subject.create()

Observable.of(1)
  :flatMap(function ()
    return a
  end)
  :dump()

a:onNext(555)
a:onCompleted()

the output would still be

onCompleted

whereas in rxjs

const { of, Subject } = require("rxjs");
const { flatMap } = require("rxjs/operators");
const a = new Subject;

of(1).pipe(
  flatMap(() => a)
)
.subscribe(
  value => console.log("onNext", value),
  err => console.log("onError", err),
  () => console.log("onCompleted")
);

a.next(555);
a.complete();

prints

onNext 555
onCompleted

Here's a test you could put in tests/flatMap.lua to further illustrate this

it('completes after inner stream', function ()
  local a = Subject.create()
  local values = {}
  local done = false

  Observable.of(1)
    :flatMap(function ()
      return a
    end)
    :subscribe(
      function (value)
        table.insert(values, value)
      end,

      function (_err)
      end,

      function ()
        done = true
      end
    )

  expect(#values).to.equal(0)

  a:onNext(555)
  expect(#values).to.equal(1) -- fails here
  expect(values[1]).to.equal(555)
  expect(done).to.equal(false)

  a:onCompleted()
  expect(done).to.equal(true)
end)
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

1 participant