11package chrome .interop
22
33import _root_ .fs2 ._
4- import _root_ .fs2 .async . mutable .Queue
5- import cats .effect .{Async , Effect , IO }
4+ import _root_ .fs2 .concurrent .Queue
5+ import cats .effect .{Async , Concurrent , Effect , IO }
66import cats .effect .implicits ._
77import cats .implicits ._
88import chrome .events .bindings .Event
99
10- import scala .concurrent .ExecutionContext
1110import scala .language .higherKinds
1211import scala .scalajs .js
1312
@@ -28,20 +27,18 @@ package object fs2 {
2827 }
2928 }
3029
31- def toStream [F [_]: Effect ]( implicit EC : ExecutionContext ) : Stream [F , T1 ] =
32- toStream(async.unboundedQueue [F , T1 ])
30+ def toStream [F [_]: Effect : Concurrent ] : Stream [F , T1 ] =
31+ toStream(Queue .unbounded [F , T1 ])
3332
34- def toStream [F [_]: Effect ](queue : F [Queue [F , T1 ]]): Stream [F , T1 ] = {
33+ def toStream [F [_]: Effect ](queue : F [Queue [F , T1 ]]): Stream [F , T1 ] =
3534 Stream .bracket {
3635 queue.map { q =>
37- val callback = (t : T1 ) => q.offer1(t).runAsync(_ => IO .unit).unsafeRunAsync(_ => ())
36+ val callback = (t : T1 ) => q.offer1(t).runAsync(_ => IO .unit).unsafeRunSync
3837 event.addListener(callback)
3938 val release = Async [F ].delay(event.removeListener(callback))
4039 (q, release)
4140 }
42- }(_._1.dequeue, _._2)
43- }
44-
41+ }(_._2).flatMap(_._1.dequeue)
4542 }
4643
4744 implicit class Event2FS2Ops [T1 , T2 ](val event : Event [js.Function2 [T1 , T2 , _]])
@@ -59,20 +56,18 @@ package object fs2 {
5956 }
6057 }
6158
62- def toStream [F [_]: Effect ]( implicit EC : ExecutionContext ) : Stream [F , (T1 , T2 )] =
63- toStream(async.unboundedQueue [F , (T1 , T2 )])
59+ def toStream [F [_]: Effect : Concurrent ] : Stream [F , (T1 , T2 )] =
60+ toStream(Queue .unbounded [F , (T1 , T2 )])
6461
65- def toStream [F [_]: Effect ](queue : F [Queue [F , (T1 , T2 )]]): Stream [F , (T1 , T2 )] = {
62+ def toStream [F [_]: Effect ](queue : F [Queue [F , (T1 , T2 )]]): Stream [F , (T1 , T2 )] =
6663 Stream .bracket {
6764 queue.map { q =>
68- val callback = (t1 : T1 , t2 : T2 ) => q.offer1((t1, t2)).runAsync(_ => IO .unit).unsafeRunAsync(_ => ())
65+ val callback = (t1 : T1 , t2 : T2 ) => q.offer1((t1, t2)).runAsync(_ => IO .unit).unsafeRunSync
6966 event.addListener(callback)
7067 val release = Async [F ].delay(event.removeListener(callback))
7168 (q, release)
7269 }
73- }(_._1.dequeue, _._2)
74- }
75-
70+ }(_._2).flatMap(_._1.dequeue)
7671 }
7772
7873 implicit class Event3FS2Ops [T1 , T2 , T3 ](val event : Event [js.Function3 [T1 , T2 , T3 , _]])
@@ -90,19 +85,18 @@ package object fs2 {
9085 }
9186 }
9287
93- def toStream [F [_]: Effect ]( implicit EC : ExecutionContext ) : Stream [F , (T1 , T2 , T3 )] =
94- toStream(async.unboundedQueue [F , (T1 , T2 , T3 )])
88+ def toStream [F [_]: Effect : Concurrent ] : Stream [F , (T1 , T2 , T3 )] =
89+ toStream(Queue .unbounded [F , (T1 , T2 , T3 )])
9590
96- def toStream [F [_]: Effect ](queue : F [Queue [F , (T1 , T2 , T3 )]]): Stream [F , (T1 , T2 , T3 )] = {
91+ def toStream [F [_]: Effect ](queue : F [Queue [F , (T1 , T2 , T3 )]]): Stream [F , (T1 , T2 , T3 )] =
9792 Stream .bracket {
9893 queue.map { q =>
99- val callback = (t1 : T1 , t2 : T2 , t3 : T3 ) => q.offer1((t1, t2, t3)).runAsync(_ => IO .unit).unsafeRunAsync(_ => ())
94+ val callback = (t1 : T1 , t2 : T2 , t3 : T3 ) => q.offer1((t1, t2, t3)).runAsync(_ => IO .unit).unsafeRunSync
10095 event.addListener(callback)
10196 val release = Async [F ].delay(event.removeListener(callback))
10297 (q, release)
10398 }
104- }(_._1.dequeue, _._2)
105- }
99+ }(_._2).flatMap(_._1.dequeue)
106100
107101 }
108102
0 commit comments