Skip to content

Commit

Permalink
Merge pull request #3478 from armanbilge/fix/js-io-runtime-builder-re…
Browse files Browse the repository at this point in the history
…port-failure

Fix `IORuntimeBuilder` `failureReporter` config on JS
  • Loading branch information
djspiewak authored Mar 7, 2023
2 parents 3f8a690 + 776cf05 commit 929d49e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2020-2023 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cats.effect.unsafe

private[unsafe] abstract class IORuntimeBuilderPlatform { self: IORuntimeBuilder =>

protected def platformSpecificBuild: IORuntime = {
val defaultShutdown: () => Unit = () => ()
val (compute, computeShutdown) = customCompute.getOrElse(
(
IORuntime.createBatchingMacrotaskExecutor(reportFailure = failureReporter),
defaultShutdown
)
)
val (blocking, blockingShutdown) = customBlocking.getOrElse((compute, defaultShutdown))
val (scheduler, schedulerShutdown) =
customScheduler.getOrElse((IORuntime.defaultScheduler, defaultShutdown))
val shutdown = () => {
computeShutdown()
blockingShutdown()
schedulerShutdown()
extraShutdownHooks.reverse.foreach(_())
}
val runtimeConfig = customConfig.getOrElse(IORuntimeConfig())

IORuntime.apply(
computeTransform(compute),
blockingTransform(blocking),
scheduler,
shutdown,
runtimeConfig
)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2020-2023 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cats.effect
package unsafe

class IORuntimeBuilderSpec extends BaseSpec with DetectPlatform {

"IORuntimeBuilder" should {
if (isNative) "configure the failure reporter" in pending
else
"configure the failure reporter" in {
var invoked = false
val rt = IORuntime.builder().setFailureReporter(_ => invoked = true).build()
rt.compute.reportFailure(new Exception)
invoked must beTrue
}
}

}

0 comments on commit 929d49e

Please sign in to comment.