File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
src/test/scala/io/github/makingthematrix/signals3/generators Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 11// based on http://caryrobbins.com/dev/sbt-publishing/
22
3- val _scalaVersion = " 3.3.0-RC3 "
3+ val _scalaVersion = " 3.3.0"
44
55organization := " io.github.makingthematrix"
66sonatypeProfileName := " io.github.makingthematrix"
Original file line number Diff line number Diff line change @@ -126,3 +126,35 @@ class GeneratorSignalSpec extends munit.FunSuite:
126126 assert(timePassed2 - timePassed1 >= 200 , timePassed2)
127127 assert(pausedOn > 0L )
128128 }
129+
130+ test(" Close the generator signal automatically" ) {
131+ import scala .util .Using
132+ val arr = mutable.ArrayBuilder .make[Int ]
133+ Using (GeneratorSignal .counter(200 .millis)) { sig =>
134+ sig.foreach(n => arr.addOne(n))
135+ Thread .sleep(500L )
136+ }
137+ val res1 = arr.result().toSeq
138+ assert(res1.nonEmpty)
139+ // the generator itself is not available here anymore (as it should be)
140+ // so to check if it's closed we wait a little and see if a new value was generated (it shouldn't be)
141+ Thread .sleep(500L )
142+ val res2 = arr.result().toSeq
143+ assertEquals(res1, res2)
144+ }
145+
146+ test(" Close the generator stream automatically" ) {
147+ import scala .util .Using
148+ val arr = mutable.ArrayBuilder .make[Int ]
149+ Using (GeneratorStream .repeat(1 , 200 .millis)) { stream =>
150+ stream.foreach(n => arr.addOne(n))
151+ Thread .sleep(500L )
152+ }
153+ val res1 = arr.result().toSeq
154+ assert(res1.nonEmpty)
155+ // the generator itself is not available here anymore (as it should be)
156+ // so to check if it's closed we wait a little and see if a new value was generated (it shouldn't be)
157+ Thread .sleep(500L )
158+ val res2 = arr.result().toSeq
159+ assertEquals(res1, res2)
160+ }
You can’t perform that action at this time.
0 commit comments