Skip to content

Using Observable toList() after takeWhile() fails in some cases #1451

Closed
@spodila

Description

@spodila

With the latest 0.20.0-RC1 a combination of takeWhile() and toList() on an Observable fails, sometimes.

Here's a unit test that fails:

@Test
    public void testTakeWhile() {
        int[] nums = {1, 2, 3};
        final AtomicInteger count = new AtomicInteger();
        for(final int n: nums) {
            Observable
                    .from(Boolean.TRUE, Boolean.FALSE)
                    .takeWhile(new Func1<Boolean, Boolean>() {
                        @Override
                        public Boolean call(Boolean value) {
                            return value;
                        }
                    })
                    .toList()
                    .doOnNext(new Action1<List<Boolean>>() {
                        @Override
                        public void call(List<Boolean> booleans) {
                            count.incrementAndGet();
                        }
                    })
                    .subscribe();
        }
        assertEquals(nums.length, count.get());
    }

Here's the same unit test that passes with slight modification:

@Test
    public void testTakeWhile() {
        int[] nums = {1, 2, 3};
        final AtomicInteger count = new AtomicInteger();
        for(final int n: nums) {
            Observable
                    .from(Boolean.TRUE, Boolean.FALSE, Boolean.FALSE)
                    .takeWhile(new Func1<Boolean, Boolean>() {
                        @Override
                        public Boolean call(Boolean value) {
                            return value;
                        }
                    })
                    .toList()
                    .doOnNext(new Action1<List<Boolean>>() {
                        @Override
                        public void call(List<Boolean> booleans) {
                            count.incrementAndGet();
                        }
                    })
                    .subscribe();
        }
        assertEquals(nums.length, count.get());
    }

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