Comments (3)
@strokyl I'm not sure what you are expecting but this seems like exactly the documented behavior:
Delays the emission of values by holding new values for a set duration. If no new values arrive during that time the value is emitted, however if a new value is received during the holding period the previous value is discarded and the process is repeated with the new value.
A new value is emitted every 10 milliseconds while the specified duration is 20 milliseconds. So a new value is always emitted before the specified duration and the duration is reset until all of the values have been emitted.
from zio.
Ok sorry, I naively expected debounce to act like debounce in fs2 or throttle of Akka stream.
I was so convinced that debounce must act like fs2 one, that I had to read twice the scaladoc to realize they are in fact totally different.
But if I am not wrong the documentation here is not valid: https://zio.dev/reference/stream/zstream/operations/#debouncing.
Also, what is the equivalent of fs2 debounce ("Debounce the stream with a minimum period of d between each element") in ZIO stream?
/**
* Throttles the chunks of this stream according to the given bandwidth
* parameters using the token bucket algorithm. Allows for burst in the
* processing of elements by allowing the token bucket to accumulate tokens up
* to a `units + burst` threshold. Chunks that do not meet the bandwidth
* constraints are dropped. The weight of each chunk is determined by the
* `costFn` function.
*/
def throttleEnforce(units: => Long, duration: => Duration, burst: => Long = 0)(
costFn: Chunk[A] => Long
)(implicit trace: Trace): ZStream[R, E, A] =
self >>> ZPipeline.throttleEnforce(units, duration, burst)(costFn)
This one I guess?
from zio.
@strokyl The example seems completely accurate. It states:
The ZStream#debounce method debounces the stream with a minimum period of d between each element:
val stream = (
ZStream(1, 2, 3) ++
ZStream.fromZIO(ZIO.sleep(500.millis)) ++ ZStream(4, 5) ++
ZStream.fromZIO(ZIO.sleep(10.millis)) ++
ZStream(6)
).debounce(100.millis) // emit only after a pause of at least 100 ms
// Output: 3, 6
Indeed, there needs to be a minimum period of d
between each element, which is precisely why no element was emitted until the end of the stream in your original example. And the example given correctly illustrates this where 1
and 2
are not emited because 3
is emitted immediately after, 3
is emitted because 4
is not emitted until 500 milliseconds after, which is greater than 100 milliseconds, 4
is not emitted because 5
is emitted immediately after, 5
is not emitted because 6
is emitted 10 milliseconds after, which is less than 100 milliseconds, and 6
is emitted because nothing is emitted within 100 milliseconds after. The comment also accurately describes this and the result is indeed 3, 6
.
It sounds like one of the throttle
variants is what you are looking for.
from zio.
Related Issues (20)
- ZTestRunnerJS failure message is unhelpful
- assertTrue on zio-http Response - Exception occurred while executing macro expansion HOT 2
- ZStream.broadcast hangs when some of the streams are (implicitly) not consumed HOT 7
- zio-test: provide something like `assertAll(tests: Seq[TestResult])` HOT 3
- ZIO Metrics: Unexpected `ZStream.tagged` behavior
- ZPool incorrectly propagates uninterruptible flags to `get` Zio, for dynamically created members
- zio-test: compile error on assertion on zio.Cause HOT 4
- ZStream.ensuring, finalizer may be deferred to channel executor's close and as a result may cause deadlocks HOT 1
- ZLayer scoped doesn't work with multiple type constructors HOT 1
- No test found when an exception is raised in the construction of a provided layer HOT 4
- TestClock manipulation doesn't seem to work right for shared environment HOT 5
- ZStream flatMapPar doesn't respect scope HOT 1
- zio-test + zio-prelude: Need way to "fuzzy compare" with Prelude HOT 2
- ZIO TEST: Using .nn feature breaks reporting on failing assertions with java.lang.StringIndexOutOfBoundsException HOT 5
- Trying to interrupt a fiber in test hangs forever? HOT 2
- zio test 2.0.20 - contains in assertTrue failing compilation HOT 2
- Too big zio-test output when assertion failed on case class instances HOT 10
- 404 after clicking on the ZIO Newsletter button HOT 1
- Layers shared between different test runs when using `zio.test.check` HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zio.