Throttle Function Not Delaying Stream as Expected
describe("String to Stream", () => {
it("should split a string into words and emit each word every second", async () => {
const input = "This is an example string."
const words = input.split(" ")
const collected: string[] = []
const program = pipe(
Stream.fromIterable(words),
Stream.throttle({ cost: () => 1, units: 1, duration: Duration.seconds(1) }),
Stream.tap((word) => Effect.sync(() => {
collected.push(word)
})),
Stream.runDrain
)
await Effect.runPromise(program)
expect(collected).toEqual(words)
})
})describe("String to Stream", () => {
it("should split a string into words and emit each word every second", async () => {
const input = "This is an example string."
const words = input.split(" ")
const collected: string[] = []
const program = pipe(
Stream.fromIterable(words),
Stream.throttle({ cost: () => 1, units: 1, duration: Duration.seconds(1) }),
Stream.tap((word) => Effect.sync(() => {
collected.push(word)
})),
Stream.runDrain
)
await Effect.runPromise(program)
expect(collected).toEqual(words)
})
})anybody know why this resolves instantly instead of spending 5 seconds?
