Skip to content

Commit 7fca336

Browse files
authored
Merge pull request #10 from scala-native/fix-exceptions-swallowing
Fix swallowing exceptions inside loop
2 parents 16f52a6 + 8eccfb3 commit 7fca336

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ target/
22
*/target/
33
project/project
44
examples/*/target
5-
lowered.hnir
5+
lowered.hnir
6+
.metals
7+
.bloop

core/loop.scala

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,20 @@ object EventLoop extends ExecutionContextExecutor {
4141

4242
private val dispatcher = initDispatcher(loop)
4343

44-
private val bootstrapFuture = Future(run())(scalanative.runtime.ExecutionContext.global)
44+
// Schedule loop execution after main ends
45+
scalanative.runtime.ExecutionContext.global.execute(
46+
new Runnable {
47+
def run(): Unit = {
48+
val returnCode = EventLoop.run()
49+
if(returnCode != 0) {
50+
Zone { implicit z =>
51+
System.err.println(fromCString(uv_err_name(returnCode)))
52+
}
53+
System.exit(returnCode)
54+
}
55+
}
56+
}
57+
)
4558

4659
def execute(runnable: Runnable): Unit = {
4760
taskQueue += runnable
@@ -52,11 +65,12 @@ object EventLoop extends ExecutionContextExecutor {
5265
t.printStackTrace()
5366
}
5467

55-
def run(mode:Int = UV_RUN_DEFAULT):Unit = {
68+
def run(mode:Int = UV_RUN_DEFAULT):Int = {
5669
var continue = 1
5770
while (continue != 0) {
5871
continue = uv_run(loop, mode)
5972
}
73+
continue
6074
}
6175
}
6276

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.13.15
1+
sbt.version=1.3.4

project/plugins.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0-M2")
2-
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.1")
3-
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1")
2+
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.0")
3+
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.8.1")

0 commit comments

Comments
 (0)