Take(_duration:,scheduler:)

I’m trying to understand this operator, in chapter says it says:

takes elements from the source sequence for the given time period. Once the time interval has passed, the resulting sequence completes.

I tried that bymself in a little example:

let test = PublishSubject<Int>()

test
    .take(5.0, scheduler: MainScheduler.instance)
    .subscribe(onNext: { value in
        print(value)
    }, onError: nil, onCompleted: { 
        print("completed")
    }) { 
        print("disposed")
}

test.onNext(3)

And the result ouput is just “3”.
Isn’t supposed after those 5 seconds to be completed?

The problem was i was trying this in a Playground.

:+1:t3: glad you found what the problem was

This topic was automatically closed after 166 days. New replies are no longer allowed.