Skip to content

Commit 930e965

Browse files
committed
Run prePR
1 parent 7d74b3c commit 930e965

File tree

7 files changed

+91
-51
lines changed

7 files changed

+91
-51
lines changed

core/js/src/main/scala/cats/effect/IOApp.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package cats.effect
1818

19-
import cats.effect.metrics.CpuStarvationWarningMetrics
20-
import cats.effect.std.Console
2119
import cats.effect.tracing.TracingConstants._
2220

2321
import scala.concurrent.CancellationException
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
package cats.effect
1+
/*
2+
* Copyright 2020-2025 Typelevel
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
216

3-
trait IOAppPlatform extends IOAppCommon {
17+
package cats.effect
418

5-
}
19+
trait IOAppPlatform extends IOAppCommon {}
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
1+
/*
2+
* Copyright 2020-2025 Typelevel
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package cats.effect
218

3-
trait IOAppMultiThreaded {
19+
import java.util.concurrent.ArrayBlockingQueue
20+
import java.util.concurrent.atomic.AtomicInteger
421

22+
trait IOAppMultiThreaded {
23+
protected def decrementCountAndPutQueue(
24+
counter: AtomicInteger,
25+
queue: ArrayBlockingQueue[AnyRef])(a: AnyRef): Unit = {
26+
if (counter.decrementAndGet() == 0) {
27+
queue.clear()
28+
}
29+
queue.put(a)
30+
}
531
}

core/jvm/src/main/scala/cats/effect/IOApp.scala

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package cats.effect
1818

19-
import cats.effect.metrics.{CpuStarvationWarningMetrics, JvmCpuStarvationMetrics}
20-
import cats.effect.std.Console
19+
import cats.effect.metrics.JvmCpuStarvationMetrics
2120
import cats.effect.tracing.TracingConstants._
2221
import cats.effect.unsafe.UnsafeNonFatal
2322
import cats.syntax.all._
@@ -407,24 +406,11 @@ trait IOApp extends IOAppPlatform {
407406
}
408407
.surround(ioa)
409408
.unsafeRunFiber(
410-
{
411-
if (counter.decrementAndGet() == 0) {
412-
queue.clear()
413-
}
414-
queue.put(new CancellationException("IOApp main fiber was canceled"))
415-
},
416-
{ t =>
417-
if (counter.decrementAndGet() == 0) {
418-
queue.clear()
419-
}
420-
queue.put(t)
421-
},
422-
{ a =>
423-
if (counter.decrementAndGet() == 0) {
424-
queue.clear()
425-
}
426-
queue.put(a)
427-
}
409+
decrementCountAndPutQueue(counter, queue)(
410+
new CancellationException("IOApp main fiber was canceled")
411+
),
412+
decrementCountAndPutQueue(counter, queue),
413+
decrementCountAndPutQueue(counter, queue)
428414
)(runtime)
429415

430416
if (isStackTracing)

core/native/src/main/scala/cats/effect/IOApp.scala

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package cats.effect
1818

19-
import cats.effect.metrics.CpuStarvationWarningMetrics
20-
import cats.effect.std.Console
2119
import cats.effect.unsafe.UnsafeNonFatal
2220
import cats.syntax.all._
2321

@@ -348,24 +346,11 @@ trait IOApp extends IOAppPlatform {
348346
)
349347
.map(_.merge)
350348
.unsafeRunFiber(
351-
{
352-
if (counter.decrementAndGet() == 0) {
353-
queue.clear()
354-
}
355-
queue.put(new CancellationException("IOApp main fiber was canceled"))
356-
},
357-
{ t =>
358-
if (counter.decrementAndGet() == 0) {
359-
queue.clear()
360-
}
361-
queue.put(t)
362-
},
363-
{ a =>
364-
if (counter.decrementAndGet() == 0) {
365-
queue.clear()
366-
}
367-
queue.put(a)
368-
}
349+
decrementCountAndPutQueue(counter, queue)(
350+
new CancellationException("IOApp main fiber was canceled")
351+
),
352+
decrementCountAndPutQueue(counter, queue),
353+
decrementCountAndPutQueue(counter, queue)
369354
)(runtime)
370355

371356
var done = false
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
package cats.effect
1+
/*
2+
* Copyright 2020-2025 Typelevel
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
216

3-
trait IOAppPlatform extends IOAppCommon with IOAppMultiThreaded {
17+
package cats.effect
418

5-
}
19+
trait IOAppPlatform extends IOAppCommon with IOAppMultiThreaded {}

core/shared/src/main/scala/cats/effect/IOAppCommon.scala

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2020-2025 Typelevel
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package cats.effect
218

319
import cats.effect.metrics.CpuStarvationWarningMetrics
@@ -39,9 +55,10 @@ trait IOAppCommon {
3955
protected def onCpuStarvationWarn(metrics: CpuStarvationWarningMetrics): IO[Unit] =
4056
CpuStarvationCheck.logWarning(metrics)
4157

58+
// Non-main thread check/warning
4259
/**
43-
* Check if running on a non-main thread. Only applicable to JVM where it could occur if run in
44-
* `sbt` with `fork := false`.
60+
* Check if running on a non-main thread. Only applicable to JVM where it could occur if run
61+
* in `sbt` with `fork := false`.
4562
*/
4663
protected def checkRunningOnNonMainThread(): Unit = ()
4764
}

0 commit comments

Comments
 (0)