Skip to content

Commit 072daa2

Browse files
committed
Do not run async functions with JsBuiltInExecutor
1 parent 732460a commit 072daa2

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

runtime/jsMain/src/kotlinx/benchmark/js/JsBenchmarkDescriptorWithAsync.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,10 @@ class JsBenchmarkDescriptorWithBlackholeParameter<T>(
3131
blackhole: Blackhole,
3232
function: T.(Blackhole) -> Promise<*>
3333
) : this(name, suite, blackhole, function, true)
34+
}
35+
36+
internal val BenchmarkDescriptor<*>.isAsync get() = when (this) {
37+
is JsBenchmarkDescriptorWithNoBlackholeParameter<*> -> async
38+
is JsBenchmarkDescriptorWithBlackholeParameter<*> -> async
39+
else -> error("Unexpected ${this::class.simpleName}")
3440
}

runtime/jsMain/src/kotlinx/benchmark/js/JsBenchmarkExecutor.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,13 @@ class JsBenchmarkExecutor(name: String, @Suppress("UNUSED_PARAMETER") dummy_args
2727
benchmarks.forEach { benchmark ->
2828
val suite = benchmark.suite
2929
val config = BenchmarkConfiguration(runnerConfiguration, suite)
30-
val isAsync = when (benchmark) {
31-
is JsBenchmarkDescriptorWithNoBlackholeParameter -> benchmark.async
32-
is JsBenchmarkDescriptorWithBlackholeParameter -> benchmark.async
33-
else -> error("Unexpected ${benchmark::class.simpleName}")
34-
}
30+
val isAsync = benchmark.isAsync
3531

3632
runWithParameters(suite.parameters, runnerConfiguration.params, suite.defaultParameters) { params ->
3733
val id = id(benchmark.name, params)
3834

3935
val instance = suite.factory() // TODO: should we create instance per bench or per suite?
4036
suite.parametrize(instance, params)
41-
4237
val asynchronous = if (isAsync) {
4338
when(benchmark) {
4439
// Mind asDynamic: this is **not** a regular promise

runtime/jsMain/src/kotlinx/benchmark/js/JsBuiltInExecutor.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ class JsBuiltInExecutor(
1414
private val BenchmarkConfiguration.jsUseBridge: Boolean
1515
get() = "true".equals(advanced["jsUseBridge"], ignoreCase = true)
1616

17+
override fun run(
18+
runnerConfiguration: RunnerConfiguration,
19+
benchmarks: List<BenchmarkDescriptor<Any?>>,
20+
start: () -> Unit,
21+
complete: () -> Unit
22+
) {
23+
if (benchmarks.any { it.isAsync }) {
24+
error("${JsBuiltInExecutor::class.simpleName} does not supports async functions")
25+
}
26+
super.run(runnerConfiguration, benchmarks, start, complete)
27+
}
28+
1729
private fun createJsMeasurerBridge(originalMeasurer: () -> Long): () -> Long {
1830
val bridgeObject = object {
1931
fun invoke(): Long = originalMeasurer.invoke()

0 commit comments

Comments
 (0)