# Combine: what are those multicast functions for?

**URL:** <https://forums.swift.org/t/combine-what-are-those-multicast-functions-for/26677>\
**Category:** Using Swift\
**Tags:** combine\
**Created:** [July 6, 2019, 10:48pm UTC](https://forums.swift.org/t/combine-what-are-those-multicast-functions-for/26677 "2019-07-06T22:48:14Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![Tony\_Parker](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tony_parker/32/273_2.png) [@Tony\_Parker](https://forums.swift.org/u/Tony_Parker)\
**Post date:** [July 22, 2019, 10:30pm UTC](https://forums.swift.org/t/combine-what-are-those-multicast-functions-for/26677/12 "2019-07-22T22:30:33Z")

</div>

Hi @DevAndArtist,

I've got that bug in my queue now and I think the behavior you're seeing is about the `PassthroughSubject` and not `flatMap`. `PassthroughSubject` will drop values if the downstream has not made any demand for them. Because `flatMap` with `maxPublishers: .max(1)` will only request one value at a time from upstream, and due to the delay, all values other than the first `1` are dropped.

This works (please forgive my slight reformatting as I adjusted this to fit into my test harness):

```swift
        let something = [1, 2, 3, 4, 5, 6, 7, 8, 9].publisher
            .flatMap(maxPublishers: .max(1)) { value in
                [Int].init(repeating: value, count: value).publisher
                    .flatMap { value in
                        Just(value)
                            .delay(for: .seconds(Double.random(in: 1 ... 4)), scheduler: RunLoop.main)
                    }
            }
            .sink { value in
                print(value)
            }
                
        DispatchQueue.main.asyncAfter(deadline: .now() + 300) {
            something.cancel()
        }
        RunLoop.main.run(until: Date() + 400)

```

or this:

```swift
        let subject = PassthroughSubject<Int, Never>()
        let something = subject
            .buffer(size: 9, prefetch: .byRequest, whenFull: .dropOldest)
            .flatMap(maxPublishers: .max(1)) { value in
                [Int].init(repeating: value, count: value).publisher
                    .flatMap { value in
                        Just(value)
                            .delay(for: .seconds(Double.random(in: 1 ... 4)), scheduler: RunLoop.main)
                    }
            }
            .sink { value in
                print(value)
            }
        
        let c = [1, 2, 3, 4, 5, 6, 7, 8, 9].publisher.subscribe(subject)
        
        DispatchQueue.main.asyncAfter(deadline: .now() + 300) {
            something.cancel()
        }
        RunLoop.main.run(until: Date() + 400)
        c.cancel()

```

I haven't yet checked the rest of the comparison to `concatMap` you put in the bug (thank you for all of that).

---

_[View the full topic](https://forums.swift.org/t/combine-what-are-those-multicast-functions-for/26677)._
