Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use a MacrotaskExecutor for ScalaJS
- Loading branch information
1 parent
93ceb9a
commit 2a1242a
Showing
9 changed files
with
108 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
core/.js/src/test/scala/org/specs2/concurrent/MacrotaskExecutorSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.specs2 | ||
package concurrent | ||
|
||
import scala.concurrent.*, duration.* | ||
import LoopingCode.* | ||
import scala.scalajs.* | ||
import org.scalajs.macrotaskexecutor.MacrotaskExecutor | ||
import specification.core.* | ||
import runner.* | ||
|
||
class MacrotaskExecutorSpec(env: Env) extends Specification: | ||
def is = s2""" | ||
|
||
An example can be timed-out when using ScalaJS $timeoutExample | ||
|
||
""" | ||
|
||
def timeoutExample = | ||
given ExecutionContext = env.executionContext | ||
TextRunner.runFuture(MacrotaskExecutorSpecification())(env).map { output => | ||
output.messages must contain(contain("timeout after 500 milliseconds")) | ||
} | ||
|
||
class MacrotaskExecutorSpecification extends Specification: | ||
def is = args.execute(timeout = 500.millis) ^ s2""" | ||
|
||
An example can be timed-out when using ScalaJS $timeoutExample | ||
|
||
""" | ||
|
||
def timeoutExample = | ||
given ExecutionContext = MacrotaskExecutor | ||
loop.map(_ => ok) | ||
|
||
object LoopingCode: | ||
var cancel = false | ||
|
||
def loop(using executionContext: ExecutionContext): Future[Unit] = | ||
Future(cancel).flatMap(canceled => if canceled then Future.unit else loop) |
40 changes: 40 additions & 0 deletions
40
core/.jvm/src/test/scala/org/specs2/concurrent/MacrotaskExecutorSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.specs2 | ||
package concurrent | ||
|
||
import scala.concurrent.*, duration.* | ||
import LoopingCode.* | ||
import specification.core.* | ||
import runner.* | ||
|
||
class MacrotaskExecutorSpec(env: Env) extends Specification: | ||
def is = s2""" | ||
|
||
This specification is a copy of the coreJS/MacrotaskExecutorSpec to check | ||
if timeouts work ok on the JVM | ||
|
||
An example can be timed-out when using Scala on the $timeoutExample | ||
|
||
""" | ||
|
||
def timeoutExample = | ||
given ExecutionContext = env.executionContext | ||
TextRunner.runFuture(MacrotaskExecutorSpecification())(env).map { output => | ||
output.messages must contain(contain("timeout after 500 milliseconds")) | ||
} | ||
|
||
class MacrotaskExecutorSpecification extends Specification: | ||
def is = args.execute(timeout = 500.millis) ^ s2""" | ||
|
||
An example can be timed-out when using ScalaJS $timeoutExample | ||
|
||
""" | ||
|
||
def timeoutExample = | ||
given ExecutionContext = scala.concurrent.ExecutionContext.Implicits.global | ||
loop.map(_ => ok) | ||
|
||
object LoopingCode: | ||
var cancel = false | ||
|
||
def loop(using executionContext: ExecutionContext): Future[Unit] = | ||
Future(cancel).flatMap(canceled => if canceled then Future.unit else loop) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters