-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
IORuntimeBuilder
failureReporter
config on JS
- Loading branch information
1 parent
3f8a690
commit 776cf05
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
core/js/src/main/scala/cats/effect/unsafe/IORuntimeBuilderPlatform.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,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 | ||
) | ||
} | ||
|
||
} |
File renamed without changes.
33 changes: 33 additions & 0 deletions
33
tests/shared/src/test/scala/cats/effect/unsafe/IORuntimeBuilderSpec.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,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 | ||
} | ||
} | ||
|
||
} |