Skip to content

Commit e5d40eb

Browse files
committed
Add cc to the rest of jvm impl
1 parent 5c16bc3 commit e5d40eb

File tree

7 files changed

+29
-15
lines changed

7 files changed

+29
-15
lines changed

jvm/src/main/scala/PosixLikeIO/PIO.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package PosixLikeIO
22

3+
import language.experimental.captureChecking
4+
35
import gears.async.Scheduler
46
import gears.async.default.given
57
import gears.async.{Async, Future}

jvm/src/main/scala/PosixLikeIO/examples/clientAndServerUDP.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package PosixLikeIO.examples
22

3+
import language.experimental.captureChecking
4+
35
import gears.async.AsyncOperations.*
46
import gears.async.default.given
57
import gears.async.{Async, Future}
@@ -13,7 +15,7 @@ import PosixLikeIO.{PIOHelper, SocketUDP}
1315

1416
@main def clientAndServerUDP(): Unit =
1517
given ExecutionContext = ExecutionContext.global
16-
Async.blocking:
18+
Async.blocking: spawn ?=>
1719
val server = Future:
1820
PIOHelper.withSocketUDP(8134): serverSocket =>
1921
val got: DatagramPacket = serverSocket.receive().awaitResult.get
@@ -22,7 +24,7 @@ import PosixLikeIO.{PIOHelper, SocketUDP}
2224
serverSocket.send(ByteBuffer.wrap(responseMessage), got.getAddress.toString.substring(1), got.getPort)
2325
sleep(50)
2426

25-
def client(value: Int): Future[Unit] =
27+
def client(value: Int): Future[Unit]^{spawn} =
2628
Future:
2729
PIOHelper.withSocketUDP(): clientSocket =>
2830
val data: Array[Byte] = value.toString.getBytes

jvm/src/main/scala/PosixLikeIO/examples/readAndWriteFile.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package PosixLikeIO.examples
22

3+
import language.experimental.captureChecking
4+
35
import gears.async.Async
46
import gears.async.default.given
57

jvm/src/main/scala/PosixLikeIO/examples/readWholeFile.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package PosixLikeIO.examples
22

3+
import language.experimental.captureChecking
4+
35
import gears.async.Async
46
import gears.async.default.given
57

jvm/src/main/scala/async/DefaultSupport.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package gears.async.default
22

3+
import language.experimental.captureChecking
4+
35
import gears.async._
46

57
given AsyncOperations = JvmAsyncOperations

jvm/src/main/scala/measurements/measureTimes.scala

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package measurements
22

3+
import language.experimental.captureChecking
4+
35
import gears.async.default.given
46
import gears.async.{Async, BufferedChannel, ChannelMultiplexer, Future, SyncChannel}
57

@@ -65,9 +67,12 @@ def measureIterations[T](action: () => T): Int =
6567

6668
val c1: Double = measureIterations: () =>
6769
Async.blocking:
68-
Async.race(Future { Thread.sleep(10) }, Future { Thread.sleep(100) }, Future { Thread.sleep(50) }).await
69-
Async.race(Future { Thread.sleep(50) }, Future { Thread.sleep(10) }, Future { Thread.sleep(100) }).await
70-
Async.race(Future { Thread.sleep(100) }, Future { Thread.sleep(50) }, Future { Thread.sleep(10) }).await
70+
val r1 = Async.race(Future { Thread.sleep(10) }, Future { Thread.sleep(100) }, Future { Thread.sleep(50) })
71+
r1.await
72+
val r2 = Async.race(Future { Thread.sleep(50) }, Future { Thread.sleep(10) }, Future { Thread.sleep(100) })
73+
r2.await
74+
val r3 = Async.race(Future { Thread.sleep(100) }, Future { Thread.sleep(50) }, Future { Thread.sleep(10) })
75+
r3.await
7176

7277
val c2: Double = measureIterations: () =>
7378
Async.blocking:
@@ -95,11 +100,11 @@ def measureIterations[T](action: () => T): Int =
95100
println("Non-raced futures per second: " + c2_per_second_adjusted)
96101
println("Overhead: " + (c2_per_second_adjusted / c1_per_second_adjusted))
97102

98-
/* Linux
103+
/* Linux
99104
Raced futures awaited per second: 15.590345727332032
100105
Non-raced futures per second: 15.597976831457009
101106
Overhead: 1.0004894762604013
102-
*/
107+
*/
103108

104109
@main def measureRaceOverheadVsJava(): Unit =
105110
given ExecutionContext = ExecutionContext.global
@@ -148,11 +153,11 @@ def measureIterations[T](action: () => T): Int =
148153
println("Java threads awaited per second: " + c2_per_second_adjusted)
149154
println("Overhead: " + (c2_per_second_adjusted / c1_per_second_adjusted))
150155

151-
/* Linux
156+
/* Linux
152157
Raced futures awaited per second: 15.411487529449996
153158
Java threads awaited per second: 15.671210243700953
154159
Overhead: 1.0168525402726147
155-
*/
160+
*/
156161

157162
@main def channelsVsJava(): Unit =
158163
given ExecutionContext = ExecutionContext.global
@@ -305,13 +310,13 @@ def measureIterations[T](action: () => T): Int =
305310
Thread.sleep(500)
306311
println("ChannelMultiplexer over BufferedChannels sends per second: " + cmOverBufferedSendsPerSecond)
307312

308-
/* Linux
313+
/* Linux
309314
Java "channel" sends per second: 8691652
310315
SyncChannel sends per second: 319371.0
311316
BufferedChannel sends per second: 308286.0
312317
ChannelMultiplexer over SyncChannels sends per second: 155737.0
313318
ChannelMultiplexer over BufferedChannels sends per second: 151995.0
314-
*/
319+
*/
315320

316321
/** Warmup for 10 seconds and benchmark for 60 seconds.
317322
*/
@@ -490,7 +495,7 @@ def measureRunTimes[T](action: () => T): TimeMeasurementResult =
490495
dataAlmostJson.append("}")
491496
println(dataAlmostJson.toString)
492497

493-
/* Linux
498+
/* Linux
494499
{
495500
"File writing": {
496501
@@ -506,5 +511,4 @@ def measureRunTimes[T](action: () => T): TimeMeasurementResult =
506511
"Java Files.write": [18.96376850600001, 0.20493288428568684],
507512
},
508513
},
509-
}
510-
*/
514+
} */

shared/src/main/scala/async/Async.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ object Async:
191191
* @see
192192
* [[Source!.awaitResult awaitResult]] for non-unwrapping await.
193193
*/
194-
inline def await(using Async): T = src.awaitResult.get
194+
def await(using Async): T = src.awaitResult.get
195195
extension [E, T](src: Source[Either[E, T]]^)
196196
/** Waits for an item to arrive from the source, then automatically unwraps it. Suspends until an item returns.
197197
* @see

0 commit comments

Comments
 (0)