File tree Expand file tree Collapse file tree
js/src/main/scala/cats/effect
jvm-native/src/main/scala/cats/effect
jvm/src/main/scala/cats/effect
native/src/main/scala/cats/effect
shared/src/main/scala/cats/effect Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616
1717package cats .effect
1818
19- import cats .effect .metrics .CpuStarvationWarningMetrics
20- import cats .effect .std .Console
2119import cats .effect .tracing .TracingConstants ._
2220
2321import scala .concurrent .CancellationException
Original file line number Diff line number Diff line change 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 { }
Original file line number Diff line number Diff line change 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+
117package 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}
Original file line number Diff line number Diff line change 1616
1717package cats .effect
1818
19- import cats .effect .metrics .{CpuStarvationWarningMetrics , JvmCpuStarvationMetrics }
20- import cats .effect .std .Console
19+ import cats .effect .metrics .JvmCpuStarvationMetrics
2120import cats .effect .tracing .TracingConstants ._
2221import cats .effect .unsafe .UnsafeNonFatal
2322import 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)
Original file line number Diff line number Diff line change 1616
1717package cats .effect
1818
19- import cats .effect .metrics .CpuStarvationWarningMetrics
20- import cats .effect .std .Console
2119import cats .effect .unsafe .UnsafeNonFatal
2220import 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
Original file line number Diff line number Diff line change 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 { }
Original file line number Diff line number Diff line change 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+
117package cats .effect
218
319import 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}
You can’t perform that action at this time.
0 commit comments