File tree Expand file tree Collapse file tree 7 files changed +91
-51
lines changed
js/src/main/scala/cats/effect
jvm/src/main/scala/cats/effect
jvm-native/src/main/scala/cats/effect
native/src/main/scala/cats/effect
shared/src/main/scala/cats/effect Expand file tree Collapse file tree 7 files changed +91
-51
lines changed Original file line number Diff line number Diff line change 16
16
17
17
package cats .effect
18
18
19
- import cats .effect .metrics .CpuStarvationWarningMetrics
20
- import cats .effect .std .Console
21
19
import cats .effect .tracing .TracingConstants ._
22
20
23
21
import 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
+ */
2
16
3
- trait IOAppPlatform extends IOAppCommon {
17
+ package cats . effect
4
18
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
+
1
17
package cats .effect
2
18
3
- trait IOAppMultiThreaded {
19
+ import java .util .concurrent .ArrayBlockingQueue
20
+ import java .util .concurrent .atomic .AtomicInteger
4
21
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
+ }
5
31
}
Original file line number Diff line number Diff line change 16
16
17
17
package cats .effect
18
18
19
- import cats .effect .metrics .{CpuStarvationWarningMetrics , JvmCpuStarvationMetrics }
20
- import cats .effect .std .Console
19
+ import cats .effect .metrics .JvmCpuStarvationMetrics
21
20
import cats .effect .tracing .TracingConstants ._
22
21
import cats .effect .unsafe .UnsafeNonFatal
23
22
import cats .syntax .all ._
@@ -407,24 +406,11 @@ trait IOApp extends IOAppPlatform {
407
406
}
408
407
.surround(ioa)
409
408
.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)
428
414
)(runtime)
429
415
430
416
if (isStackTracing)
Original file line number Diff line number Diff line change 16
16
17
17
package cats .effect
18
18
19
- import cats .effect .metrics .CpuStarvationWarningMetrics
20
- import cats .effect .std .Console
21
19
import cats .effect .unsafe .UnsafeNonFatal
22
20
import cats .syntax .all ._
23
21
@@ -348,24 +346,11 @@ trait IOApp extends IOAppPlatform {
348
346
)
349
347
.map(_.merge)
350
348
.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)
369
354
)(runtime)
370
355
371
356
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
+ */
2
16
3
- trait IOAppPlatform extends IOAppCommon with IOAppMultiThreaded {
17
+ package cats . effect
4
18
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
+
1
17
package cats .effect
2
18
3
19
import cats .effect .metrics .CpuStarvationWarningMetrics
@@ -39,9 +55,10 @@ trait IOAppCommon {
39
55
protected def onCpuStarvationWarn (metrics : CpuStarvationWarningMetrics ): IO [Unit ] =
40
56
CpuStarvationCheck .logWarning(metrics)
41
57
58
+ // Non-main thread check/warning
42
59
/**
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`.
45
62
*/
46
63
protected def checkRunningOnNonMainThread (): Unit = ()
47
64
}
You can’t perform that action at this time.
0 commit comments