diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..5ace4600a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 466df9346..0fc3557b3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,22 +2,22 @@ name: build on: pull_request: - branches: [ 'series/*' ] + branches: ['series/*', 'main'] push: - branches: [ 'series/*' ] - tags: [ "v[0-9]+*" ] + branches: ['series/*', 'main'] + tags: ["v[0-9]+*"] jobs: jvm-tests: name: JVM / scala ${{ matrix.scala }}, jdk ${{ matrix.java }} - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: - java: [ 11, 17, 21, 25 ] + java: [ 17, 21, 25 ] # WARN: build.sbt depends on this key path, as scalaVersion and # crossScalaVersions is determined from it - scala: [ 2.13.18, 3.3.7 ] + scala: [ 2.13.18, 3.8.2 ] env: CI: true @@ -26,8 +26,8 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-java@v4 with: + java-version: "${{ matrix.java }}" distribution: temurin - java-version: ${{ matrix.java }} - uses: sbt/setup-sbt@v1 - name: Cache ivy2 @@ -56,17 +56,24 @@ jobs: PLATFORM: ${{ matrix.java }} SBT_COMMAND: ci-jvm + - name: sbt reactiveTests/test + run: ./.github/scripts/exec-sbt-command + env: + SCALA_VERSION: ${{ matrix.scala }} + PLATFORM: ${{ matrix.java }} + SBT_COMMAND: "reactiveTests/test" + js-tests: name: JS / scala ${{ matrix.scala }}, jdk ${{ matrix.java }} - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: # WARN: build.sbt depends on this key path, as scalaVersion and # crossScalaVersions is determined from it include: - - { java: 11, scala: 2.13.18 } - - { java: 11, scala: 3.3.7 } + - { java: 17, scala: 2.13.18 } + - { java: 17, scala: 3.8.2 } env: CI: true @@ -75,8 +82,8 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-java@v4 with: + java-version: "${{ matrix.java }}" distribution: temurin - java-version: ${{ matrix.java }} - uses: sbt/setup-sbt@v1 - name: Cache ivy2 @@ -101,7 +108,7 @@ jobs: - name: Setup NodeJS uses: actions/setup-node@v4 with: - node-version: 14 + node-version: 20 - name: sbt ci-js run: | @@ -113,20 +120,24 @@ jobs: mima: name: Mima / scala ${{ matrix.scala }}, jdk ${{ matrix.java }} - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 + + env: + CI: true + strategy: fail-fast: false matrix: include: - - { java: 11, scala: 2.13.18 } - - { java: 11, scala: 3.3.7 } + - { java: 17, scala: 2.13.18 } + - { java: 17, scala: 3.8.2 } steps: - uses: actions/checkout@v4 - uses: actions/setup-java@v4 with: + java-version: "${{ matrix.java }}" distribution: temurin - java-version: ${{ matrix.java }} - uses: sbt/setup-sbt@v1 - name: Cache ivy2 @@ -155,23 +166,74 @@ jobs: SCALA_VERSION: ${{ matrix.scala }} SBT_COMMAND: mimaReportBinaryIssues + scalafmt: + name: Scalafmt / scala ${{ matrix.scala }}, jdk ${{ matrix.java }} + runs-on: ubuntu-22.04 + + env: + CI: true + + strategy: + fail-fast: false + matrix: + include: + - { java: 17, scala: 2.13.18 } + - { java: 17, scala: 3.8.2 } + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + java-version: "${{ matrix.java }}" + distribution: temurin + - uses: sbt/setup-sbt@v1 + + - name: Cache ivy2 + uses: actions/cache@v4 + with: + path: ~/.ivy2/cache + key: ${{ runner.os }}-sbt-ivy-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }} + + - name: Cache coursier (linux) + if: contains(runner.os, 'linux') + uses: actions/cache@v4 + with: + path: ~/.cache/coursier/v1 + key: ${{ runner.os }}-sbt-coursier-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }} + + - name: Cache sbt + uses: actions/cache@v4 + with: + path: ~/.sbt + key: ${{ runner.os }}-sbt-cache-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }} + + - name: sbt scalafmtCheckAll + run: | + ./.github/scripts/exec-sbt-command + env: + SCALA_VERSION: ${{ matrix.scala }} + SBT_COMMAND: "scalafmtCheckAll scalafmtSbtCheck" + unidoc: name: Unidoc / scala ${{ matrix.scala }}, jdk ${{ matrix.java }} - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 + + env: + CI: true + strategy: fail-fast: false matrix: include: - - { java: 11, scala: 2.13.18 } - # TODO: enable this after it works! - # - { java: 11, scala: 3.3.5 } + - { java: 17, scala: 2.13.18 } + - { java: 17, scala: 3.8.2 } steps: - uses: actions/checkout@v4 - uses: actions/setup-java@v4 with: + java-version: "${{ matrix.java }}" distribution: temurin - java-version: ${{ matrix.java }} - uses: sbt/setup-sbt@v1 - name: Cache ivy2 @@ -202,19 +264,24 @@ jobs: all_tests: name: All Tests - needs: [ jvm-tests, js-tests, mima, unidoc ] - runs-on: ubuntu-latest + if: always() + needs: [ jvm-tests, js-tests, mima, scalafmt, unidoc ] + runs-on: ubuntu-22.04 steps: - - name: Ack - run: | - echo "All done." + - name: Validate required tests + uses: re-actors/alls-green@release/v1 + with: + jobs: ${{ toJSON(needs) }} publish: name: Publish to Sonatype - if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/series/3.x') + if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/series/3.x-avs') needs: [ all_tests ] - runs-on: ubuntu-latest + env: + CI: true + + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 with: @@ -222,8 +289,8 @@ jobs: - uses: actions/setup-java@v4 with: + java-version: 17 distribution: temurin - java-version: 11 - uses: sbt/setup-sbt@v1 - name: Install GnuPG2 diff --git a/.github/workflows/manual-publish.yml b/.github/workflows/manual-publish.yml index 694b017cf..291c88b5d 100644 --- a/.github/workflows/manual-publish.yml +++ b/.github/workflows/manual-publish.yml @@ -6,7 +6,7 @@ on: ref_to_publish: description: 'Ref (branch or tag)' required: true - default: 'refs/heads/series/3.x' + default: 'refs/heads/main' stable_version: description: 'Stable version? (true=staging, false=snapshot)' required: true @@ -16,7 +16,10 @@ jobs: publish: name: Publish to Sonatype (Request) - runs-on: ubuntu-latest + env: + CI: true + + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 with: @@ -25,8 +28,8 @@ jobs: - uses: actions/setup-java@v4 with: + java-version: 17 distribution: temurin - java-version: 11 - uses: sbt/setup-sbt@v1 - name: Install GnuPG2 diff --git a/.gitignore b/.gitignore index d5899b7e7..3ed8919c3 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,9 @@ TAGS .tags .metals .bloop +.bsp metals.sbt .vscode .bsp -.planning/ +*.sublime* +.sisyphus/ diff --git a/.scala-steward.conf b/.scala-steward.conf index 8083f8414..7200b4799 100644 --- a/.scala-steward.conf +++ b/.scala-steward.conf @@ -1,6 +1,6 @@ pullRequests.frequency = "7 days" -updates.pin = [ - { groupId = "org.typelevel", artifactId="cats-effect", version = "2." }, - { groupId = "org.typelevel", artifactId="cats-effect-laws", version = "2." }, -] +#updates.pin = [ +# { groupId = "org.typelevel", artifactId="cats-effect", version = "2." }, +# { groupId = "org.typelevel", artifactId="cats-effect-laws", version = "2." }, +#] diff --git a/.scalafmt.conf b/.scalafmt.conf index e40e7acdc..12c9ed666 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -10,7 +10,7 @@ align.tokens = [ ] fileOverride { - "glob:**/src/main/scala_3.0/**" { + "glob:**/src/main/scala-3*/**" { runner.dialect = scala3 }, "glob:**/*.sbt" { diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 000000000..c662b5f52 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,15 @@ +# Agent Instructions for Monix + +This file contains mandatory rules for AI agents (Copilot, Claude, Cursor, etc.) working on this repository. +**Any violation is a CI-breaking mistake!** + +--- + +## Code rules + +- Never workaround the compiler, make an effort to solve errors in an idiomatic way: + - Avoid `asInstanceOf` downcasting, unless there's no other way (e.g., untagged union types in Scala 3). + - `@nowarn` annotations, or other ways for supressing warnings/errors, are not permitted without the user's consent. + - We fix warnings, we don't ignore them. +- Use package imports, instead of fully qualified names. +- Make an effort to write idiomatic, yet performant Scala code. diff --git a/CHANGES.md b/CHANGES.md index 1a82057d4..57125f9b8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,19 @@ +## Version 3.5.0 (Mar 31, 2026) + +This release updates Monix 3.x support baselines for modern JVM and Scala toolchains. + +Breaking changes: + +- JDK `17` is now the minimum supported runtime and build target. +- JDK `21` is now part of the validated support matrix. +- Scala `2.12` support is dropped. +- Scala `3` is upgraded to `3.8.2`. +- Legacy `sun.misc.Unsafe`-based internals were removed in favor of JDK `VarHandle`-based implementations. + +This release was made possible by the work and feedback of: + +- Alexandru Nedelcu (@alexandru) + ## Version 3.4.1 (May 7, 2022) This is a minor bug-fixing release for the 3.x series. @@ -1531,7 +1547,7 @@ Bug fixes: Build: - enabled the Scala - [Migration Manager](https://github.com/typesafehub/migration-manager) + [Migration Manager](https://github.com/lightbend/mima) (MiMa) in `build.sbt` to check for backwards compatibility problems - [Issue #322](https://github.com/monix/monix/issues/322): Switch projects which use `CrossVersion.full/"org.scala-lang"` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cbb32eba2..be02012b4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,7 @@ The Monix project welcomes contributions from anybody wishing to participate. All code or documentation that is provided must be licensed with Apache 2.0 -(see LICENSE.txt). +(see `LICENSE.txt`). ## Code of Conduct diff --git a/README.md b/README.md index f2aed5c8b..cfec51e39 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,17 @@ Asynchronous, Reactive Programming for Scala and [Scala.js](http://www.scala-js.org/). -[![Build](https://github.com/monix/monix/workflows/build/badge.svg?branch=series/3.x)](https://github.com/monix/monix/actions?query=branch%3Aseries%2F3.x+workflow%3Abuild) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/monix/monix) - -- [Overview](#overview) -- [Usage](#usage) - - [Library dependency (sbt)](#library-dependency-sbt) - - [Sub-projects](#sub-projects) -- [Documentation](#documentation) -- [Contributing](#contributing) -- [Adopters](#adopters) -- [License](#license) +[![build](https://github.com/monix/monix/actions/workflows/build.yml/badge.svg)](https://github.com/monix/monix/actions/workflows/build.yml) [![monix Scala version support](https://index.scala-lang.org/monix/monix/monix/latest-by-scala-version.svg)](https://index.scala-lang.org/monix/monix/monix) + +- [Monix](#monix) + - [Overview](#overview) + - [Usage](#usage) + - [Library dependency (sbt)](#library-dependency-sbt) + - [Sub-projects](#sub-projects) + - [Documentation](#documentation) + - [Contributing](#contributing) + - [Adopters](#adopters) + - [License](#license) ## Overview @@ -57,10 +58,15 @@ a project exemplifying Monix used both on the server and on the client. ### Library dependency (sbt) +Compatibility baseline: + +- JDK `17` minimum (`21` validated) +- Scala `2.13.18` and Scala `3.8.2` + For the stable release (compatible with Cats, and Cats-Effect 2.x): ```scala -libraryDependencies += "io.monix" %% "monix" % "3.4.1" +libraryDependencies += "io.monix" %% "monix" % "x.y.z" ``` ### Sub-projects @@ -99,7 +105,7 @@ See: API Documentation: - [Current](https://monix.io/api/current/) -- [3.3](https://monix.io/api/3.3/) +- [3.4](https://monix.io/api/3.4/) - [2.3](https://monix.io/api/2.3/) - [1.2](https://monix.io/api/1.2/) @@ -132,16 +138,19 @@ If you'd like to donate in order to help with ongoing maintenance: Here's a (non-exhaustive) list of companies that use Monix in production. Don't see yours? Submit a PR ❤️ - +- [PITS Global Data Recovery Services](https://www.pitsdatarecovery.net/) - [Abacus](https://abacusfi.com) - [Agoda](https://www.agoda.com) +- [AVSystem](https://www.avsystem.com) - [commercetools](https://commercetools.com) - [Coya](https://www.coya.com/) +- [DigitalGenius](https://digitalgenius.com/) - [E.ON Connecting Energies](https://www.eon.com/) - [eBay Inc.](https://www.ebay.com) - [Eloquentix](http://eloquentix.com/) - [Hypefactors](https://www.hypefactors.com) - [Iterators](https://www.iteratorshq.com) +- [Netflix](https://netflix.com) - [Sony Electronics](https://www.sony.com) - [Tinkoff](https://tinkoff.ru) - [Zalando](https://www.zalando.com) @@ -150,4 +159,4 @@ Submit a PR ❤️ ## License All code in this repository is licensed under the Apache License, -Version 2.0. See [LICENCE.txt](./LICENSE.txt). +Version 2.0. See [LICENSE](./LICENSE.txt). diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/ArrayStackBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/ArrayStackBenchmark.scala index a2cad2728..0aeb2ac98 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/ArrayStackBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/ArrayStackBenchmark.scala @@ -23,19 +23,19 @@ import monix.execution.internal.collection.ArrayStack import org.openjdk.jmh.annotations._ /** To do comparative benchmarks between versions: - * - * benchmarks/run-benchmark ArrayStackBenchmark - * - * This will generate results in `benchmarks/results`. - * - * Or to run the benchmark from within SBT: - * - * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.ArrayStackBenchmark - * - * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". - * Please note that benchmarks should be usually executed at least in - * 10 iterations (as a rule of thumb), but more is better. - */ + * + * benchmarks/run-benchmark ArrayStackBenchmark + * + * This will generate results in `benchmarks/results`. + * + * Or to run the benchmark from within SBT: + * + * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.ArrayStackBenchmark + * + * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". + * Please note that benchmarks should be usually executed at least in + * 10 iterations (as a rule of thumb), but more is better. + */ @State(Scope.Thread) @BenchmarkMode(Array(Mode.Throughput)) @OutputTimeUnit(TimeUnit.SECONDS) @@ -68,4 +68,4 @@ class ArrayStackBenchmark { sum } } - */ \ No newline at end of file + */ diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/ChunkedEvalFilterMapSumBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/ChunkedEvalFilterMapSumBenchmark.scala index 7ed724c42..d99d79b71 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/ChunkedEvalFilterMapSumBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/ChunkedEvalFilterMapSumBenchmark.scala @@ -18,17 +18,17 @@ package monix.benchmarks import akka.actor.ActorSystem -import akka.stream.scaladsl.{Keep, RunnableGraph, Sink => AkkaSink, Source => AkkaSource} -import fs2.{Stream => FS2Stream} -import monix.eval.{Task => MonixTask} -import monix.reactive.{Observable => MonixObservable} +import akka.stream.scaladsl.{ Keep, RunnableGraph, Sink => AkkaSink, Source => AkkaSource } +import fs2.{ Stream => FS2Stream } +import monix.eval.{ Task => MonixTask } +import monix.reactive.{ Observable => MonixObservable } import org.openjdk.jmh.annotations._ -import zio.stream.{Stream => ZStream} -import zio.{Chunk, UIO} +import zio.stream.{ Stream => ZStream } +import zio.{ Chunk, UIO } import java.util.concurrent.TimeUnit import scala.concurrent.duration.Duration -import scala.concurrent.{Await, Future} +import scala.concurrent.{ Await, Future } /** * Benchmark designed to execute these operations: @@ -94,7 +94,7 @@ class ChunkedEvalFilterMapSumBenchmark { @Benchmark def fs2Stream = { - val stream = FS2Stream(allElements: _*) + val stream = FS2Stream(allElements*) .chunkN(chunkSize) .evalMap[MonixTask, Int](chunk => MonixTask(sumIntScala(chunk.iterator))) .filter(_ > 0) @@ -107,7 +107,7 @@ class ChunkedEvalFilterMapSumBenchmark { @Benchmark def fs2StreamPreChunked = { - val stream = FS2Stream(fs2Chunks: _*) + val stream = FS2Stream(fs2Chunks*) .evalMap[MonixTask, Int](chunk => MonixTask(sumIntScala(chunk.iterator))) .filter(_ > 0) .map(_.toLong) @@ -146,7 +146,7 @@ class ChunkedEvalFilterMapSumBenchmark { @Benchmark def zioStreamPreChunked = { val stream = ZStream - .fromChunks(zioChunks: _*) + .fromChunks(zioChunks*) .mapChunksM(chunk => UIO(Chunk.single(sumIntScala(chunk)))) .filter(_ > 0) .map(_.toLong) diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/ChunkedMapFilterSumBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/ChunkedMapFilterSumBenchmark.scala index 511796c25..b666137b4 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/ChunkedMapFilterSumBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/ChunkedMapFilterSumBenchmark.scala @@ -18,18 +18,18 @@ package monix.benchmarks import akka.actor.ActorSystem -import akka.stream.scaladsl.{Keep, Sink => AkkaSink, Source => AkkaSource} -import fs2.{Stream => FS2Stream} +import akka.stream.scaladsl.{ Keep, Sink => AkkaSink, Source => AkkaSource } +import fs2.{ Stream => FS2Stream } import monix.benchmarks import monix.execution.Ack.Continue import monix.reactive.Observable import monix.reactive.observers.Subscriber import org.openjdk.jmh.annotations._ -import zio.stream.{Stream => ZStream} +import zio.stream.{ Stream => ZStream } import java.util.concurrent.TimeUnit import scala.concurrent.duration.Duration -import scala.concurrent.{Await, Promise} +import scala.concurrent.{ Await, Promise } /** To do comparative benchmarks between versions: * @@ -119,7 +119,7 @@ class ChunkedMapFilterSumBenchmark { @Benchmark def fs2Stream(): Int = { - val stream = FS2Stream(fs2Chunks: _*) + val stream = FS2Stream(fs2Chunks*) .flatMap(FS2Stream.chunk) .map(_ + 1) .filter(_ % 2 == 0) @@ -132,7 +132,7 @@ class ChunkedMapFilterSumBenchmark { @Benchmark def zioStream(): Int = { val stream = ZStream - .fromChunks(zioChunks: _*) + .fromChunks(zioChunks*) .map(_ + 1) .filter(_ % 2 == 0) .runSum @@ -154,7 +154,7 @@ class ChunkedMapFilterSumBenchmark { val p = Promise[Int]() stream.unsafeSubscribeFn(new Subscriber.Sync[Int] { val scheduler = benchmarks.scheduler - private[this] var sum: Int = 0 + private var sum: Int = 0 def onError(ex: Throwable): Unit = p.failure(ex) diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/CoevalDeepBindBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/CoevalDeepBindBenchmark.scala index 8bdc6677e..3cdc4740e 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/CoevalDeepBindBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/CoevalDeepBindBenchmark.scala @@ -57,7 +57,7 @@ class CoevalDeepBindBenchmark { def loop(i: Int): Coeval[Int] = for { j <- Coeval.pure(i) - _ <- if(j > size) Coeval.pure(j) else loop(j + 1) + _ <- if (j > size) Coeval.pure(j) else loop(j + 1) } yield j loop(0).value() @@ -68,7 +68,7 @@ class CoevalDeepBindBenchmark { def loop(i: Int): Coeval[Int] = for { j <- Coeval(i) - _ <- if(j > size) Coeval(j) else loop(j + 1) + _ <- if (j > size) Coeval(j) else loop(j + 1) } yield j loop(0).value() diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/CoevalMapCallsBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/CoevalMapCallsBenchmark.scala index 227bb4672..02cde315a 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/CoevalMapCallsBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/CoevalMapCallsBenchmark.scala @@ -78,4 +78,4 @@ object CoevalMapCallsBenchmark { } sum } -} \ No newline at end of file +} diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/MapParallelObservableBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/MapParallelObservableBenchmark.scala index 96004e214..beb160c3c 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/MapParallelObservableBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/MapParallelObservableBenchmark.scala @@ -27,7 +27,7 @@ import monix.reactive.observers.Subscriber import org.openjdk.jmh.annotations._ import scala.concurrent.duration._ -import scala.concurrent.{Await, Promise} +import scala.concurrent.{ Await, Promise } /** To do comparative benchmarks between versions: * @@ -65,13 +65,13 @@ class MapParallelObservableBenchmark { @Benchmark def mapOrdered(): Long = { - val stream = Observable.range(0, size.toLong).mapParallelOrdered(parallelism)(x => Task.eval(x + 1)) + val stream = Observable.range(0, size.toLong).mapParallelOrdered(parallelism)(x => Task.eval(x + 1)) sum(stream) } @Benchmark def mapUnordered(): Long = { - val stream = Observable.range(0, size.toLong).mapParallelUnordered(parallelism)(x => Task.eval(x + 1)) + val stream = Observable.range(0, size.toLong).mapParallelUnordered(parallelism)(x => Task.eval(x + 1)) sum(stream) } @@ -79,7 +79,7 @@ class MapParallelObservableBenchmark { val p = Promise[Long]() stream.unsafeSubscribeFn(new Subscriber.Sync[Long] { val scheduler = global - private[this] var sum: Long = 0 + private var sum: Long = 0 def onError(ex: Throwable): Unit = { p.failure(ex) diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableConcatMapBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableConcatMapBenchmark.scala index 93c34044b..ad331e525 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableConcatMapBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableConcatMapBenchmark.scala @@ -25,7 +25,7 @@ import monix.reactive.Observable import monix.reactive.observers.Subscriber import org.openjdk.jmh.annotations._ import scala.concurrent.duration._ -import scala.concurrent.{Await, Promise} +import scala.concurrent.{ Await, Promise } /** To do comparative benchmarks between versions: * @@ -78,7 +78,7 @@ class ObservableConcatMapBenchmark { val p = Promise[Long]() stream.unsafeSubscribeFn(new Subscriber.Sync[Long] { val scheduler = global - private[this] var sum: Long = 0 + private var sum: Long = 0 def onError(ex: Throwable): Unit = { p.failure(ex) diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMapAccumulateBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMapAccumulateBenchmark.scala index 6250a7eb6..36126930e 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMapAccumulateBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMapAccumulateBenchmark.scala @@ -19,10 +19,10 @@ package monix.benchmarks import java.util.concurrent.TimeUnit -import fs2.{Stream => FS2Stream} +import fs2.{ Stream => FS2Stream } import monix.reactive.Observable import org.openjdk.jmh.annotations._ -import zio.stream.{Stream => ZStream} +import zio.stream.{ Stream => ZStream } /** To do comparative benchmarks between versions: * @@ -49,9 +49,10 @@ class ObservableMapAccumulateBenchmark { def monixObservable() = { Observable .fromIterable(0 until n) - .mapAccumulate(0) { case (acc, i) => - val added = acc + i - (added, added) + .mapAccumulate(0) { + case (acc, i) => + val added = acc + i + (added, added) } .completedL .runSyncUnsafe() @@ -61,9 +62,10 @@ class ObservableMapAccumulateBenchmark { def fs2Stream() = { FS2Stream .emits(0 until n) - .mapAccumulate(0) { case (acc, i) => - val added = acc + i - (added, added) + .mapAccumulate(0) { + case (acc, i) => + val added = acc + i + (added, added) } .compile .drain @@ -73,9 +75,10 @@ class ObservableMapAccumulateBenchmark { def zioStream() = { val stream = ZStream .fromIterable(0 until n) - .mapAccum(0) { case (acc, i) => - val added = acc + i - (added, added) + .mapAccum(0) { + case (acc, i) => + val added = acc + i + (added, added) } .runDrain diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMapTaskBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMapTaskBenchmark.scala index e05ab9e22..87bc96a5c 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMapTaskBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMapTaskBenchmark.scala @@ -31,19 +31,19 @@ import scala.concurrent.duration._ import scala.concurrent.{Await, Promise} /** To do comparative benchmarks between versions: - * - * benchmarks/run-benchmark ObservableMapTaskBenchmark - * - * This will generate results in `benchmarks/results`. - * - * Or to run the benchmark from within SBT: - * - * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.ObservableMapTaskBenchmark - * - * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". - * Please note that benchmarks should be usually executed at least in - * 10 iterations (as a rule of thumb), but more is better. - */ + * + * benchmarks/run-benchmark ObservableMapTaskBenchmark + * + * This will generate results in `benchmarks/results`. + * + * Or to run the benchmark from within SBT: + * + * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.ObservableMapTaskBenchmark + * + * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". + * Please note that benchmarks should be usually executed at least in + * 10 iterations (as a rule of thumb), but more is better. + */ @State(Scope.Thread) @BenchmarkMode(Array(Mode.Throughput)) @OutputTimeUnit(TimeUnit.SECONDS) @@ -63,7 +63,7 @@ class ObservableMapTaskBenchmark { val p = Promise[Long]() stream.unsafeSubscribeFn(new Subscriber.Sync[Long] { val scheduler = global - private[this] var sum: Long = 0 + private var sum: Long = 0 def onError(ex: Throwable): Unit = p.failure(ex) @@ -77,4 +77,4 @@ class ObservableMapTaskBenchmark { Await.result(p.future, Duration.Inf) } } -*/ \ No newline at end of file + */ diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMergeBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMergeBenchmark.scala index 9a8dbd863..52db6c230 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMergeBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/ObservableMergeBenchmark.scala @@ -20,15 +20,15 @@ package monix.benchmarks import java.util.concurrent.TimeUnit import akka.actor.ActorSystem -import akka.stream.scaladsl.{Keep, Sink => AkkaSink, Source => AkkaSource} -import fs2.{Stream => FS2Stream} -import monix.eval.{Task => MonixTask} +import akka.stream.scaladsl.{ Keep, Sink => AkkaSink, Source => AkkaSource } +import fs2.{ Stream => FS2Stream } +import monix.eval.{ Task => MonixTask } import monix.reactive.Observable import org.openjdk.jmh.annotations._ import zio.ZIO -import zio.stream.{Stream => ZStream} +import zio.stream.{ Stream => ZStream } -import scala.concurrent.{Await, Future} +import scala.concurrent.{ Await, Future } import scala.concurrent.duration.Duration import scala.util.Try diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskAttemptBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskAttemptBenchmark.scala index 487411be8..5f5b56d5e 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskAttemptBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskAttemptBenchmark.scala @@ -25,19 +25,19 @@ import scala.concurrent.Await import scala.concurrent.duration.Duration /** To do comparative benchmarks between versions: - * - * benchmarks/run-benchmark TaskAttemptBenchmark - * - * This will generate results in `benchmarks/results`. - * - * Or to run the benchmark from within SBT: - * - * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.TaskAttemptBenchmark - * - * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". - * Please note that benchmarks should be usually executed at least in - * 10 iterations (as a rule of thumb), but more is better. - */ + * + * benchmarks/run-benchmark TaskAttemptBenchmark + * + * This will generate results in `benchmarks/results`. + * + * Or to run the benchmark from within SBT: + * + * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.TaskAttemptBenchmark + * + * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". + * Please note that benchmarks should be usually executed at least in + * 10 iterations (as a rule of thumb), but more is better. + */ @State(Scope.Thread) @BenchmarkMode(Array(Mode.Throughput)) @OutputTimeUnit(TimeUnit.SECONDS) @@ -71,4 +71,4 @@ class TaskAttemptBenchmark { Await.result(loop(0).runAsync, Duration.Inf) } } -*/ \ No newline at end of file + */ diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskDeepBindBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskDeepBindBenchmark.scala index 4287d04b2..6b6a63e06 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskDeepBindBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskDeepBindBenchmark.scala @@ -25,19 +25,19 @@ import scala.concurrent.Await import scala.concurrent.duration.Duration /** To do comparative benchmarks between versions: - * - * benchmarks/run-benchmark TaskDeepBindBenchmark - * - * This will generate results in `benchmarks/results`. - * - * Or to run the benchmark from within SBT: - * - * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.TaskDeepBindBenchmark - * - * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". - * Please note that benchmarks should be usually executed at least in - * 10 iterations (as a rule of thumb), but more is better. - */ + * + * benchmarks/run-benchmark TaskDeepBindBenchmark + * + * This will generate results in `benchmarks/results`. + * + * Or to run the benchmark from within SBT: + * + * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.TaskDeepBindBenchmark + * + * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". + * Please note that benchmarks should be usually executed at least in + * 10 iterations (as a rule of thumb), but more is better. + */ @State(Scope.Thread) @BenchmarkMode(Array(Mode.Throughput)) @OutputTimeUnit(TimeUnit.SECONDS) @@ -78,4 +78,4 @@ class TaskDeepBindBenchmark { Await.result(loop(0).runAsync, Duration.Inf) } } -*/ \ No newline at end of file + */ diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskHandleErrorBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskHandleErrorBenchmark.scala index 035f5291b..c36f59b76 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskHandleErrorBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskHandleErrorBenchmark.scala @@ -25,19 +25,19 @@ import scala.concurrent.Await import scala.concurrent.duration.Duration /** To do comparative benchmarks between versions: - * - * benchmarks/run-benchmark TaskHandleErrorBenchmark - * - * This will generate results in `benchmarks/results`. - * - * Or to run the benchmark from within SBT: - * - * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.TaskHandleErrorBenchmark - * - * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". - * Please note that benchmarks should be usually executed at least in - * 10 iterations (as a rule of thumb), but more is better. - */ + * + * benchmarks/run-benchmark TaskHandleErrorBenchmark + * + * This will generate results in `benchmarks/results`. + * + * Or to run the benchmark from within SBT: + * + * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.TaskHandleErrorBenchmark + * + * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". + * Please note that benchmarks should be usually executed at least in + * 10 iterations (as a rule of thumb), but more is better. + */ @State(Scope.Thread) @BenchmarkMode(Array(Mode.Throughput)) @OutputTimeUnit(TimeUnit.SECONDS) @@ -74,4 +74,4 @@ class TaskHandleErrorBenchmark { Await.result(loop(0).runAsync, Duration.Inf) } } -*/ \ No newline at end of file + */ diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskMapCallsBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskMapCallsBenchmark.scala index 5f2d0014f..f8ab70891 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskMapCallsBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskMapCallsBenchmark.scala @@ -25,19 +25,19 @@ import scala.concurrent.Await import scala.concurrent.duration.Duration /** To do comparative benchmarks between versions: - * - * benchmarks/run-benchmark TaskMapCallsBenchmark - * - * This will generate results in `benchmarks/results`. - * - * Or to run the benchmark from within SBT: - * - * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.TaskMapCallsBenchmark - * - * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". - * Please note that benchmarks should be usually executed at least in - * 10 iterations (as a rule of thumb), but more is better. - */ + * + * benchmarks/run-benchmark TaskMapCallsBenchmark + * + * This will generate results in `benchmarks/results`. + * + * Or to run the benchmark from within SBT: + * + * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.TaskMapCallsBenchmark + * + * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". + * Please note that benchmarks should be usually executed at least in + * 10 iterations (as a rule of thumb), but more is better. + */ @State(Scope.Thread) @BenchmarkMode(Array(Mode.Throughput)) @OutputTimeUnit(TimeUnit.SECONDS) @@ -71,4 +71,4 @@ object TaskMapCallsBenchmark { sum } } -*/ \ No newline at end of file + */ diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskMapStreamBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskMapStreamBenchmark.scala index a5b1d0be0..1d78babb6 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskMapStreamBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskMapStreamBenchmark.scala @@ -27,19 +27,19 @@ import scala.concurrent.Await import scala.concurrent.duration.Duration /** To do comparative benchmarks between versions: - * - * benchmarks/run-benchmark TaskMapStreamBenchmark - * - * This will generate results in `benchmarks/results`. - * - * Or to run the benchmark from within SBT: - * - * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.TaskMapStreamBenchmark - * - * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". - * Please note that benchmarks should be usually executed at least in - * 10 iterations (as a rule of thumb), but more is better. - */ + * + * benchmarks/run-benchmark TaskMapStreamBenchmark + * + * This will generate results in `benchmarks/results`. + * + * Or to run the benchmark from within SBT: + * + * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.TaskMapStreamBenchmark + * + * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". + * Please note that benchmarks should be usually executed at least in + * 10 iterations (as a rule of thumb), but more is better. + */ @State(Scope.Thread) @BenchmarkMode(Array(Mode.Throughput)) @OutputTimeUnit(TimeUnit.SECONDS) @@ -92,4 +92,4 @@ object TaskMapStreamBenchmark { Task.pure(acc) } } - */ \ No newline at end of file + */ diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskSequenceBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskSequenceBenchmark.scala index 23c536a2e..15084f9eb 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskSequenceBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskSequenceBenchmark.scala @@ -92,7 +92,6 @@ class TaskSequenceBenchmark { result.runSyncUnsafe() } - @Benchmark def monixParSequence(): Long = { val tasks = (0 until count).map(_ => Task.eval(1)).toList @@ -100,7 +99,6 @@ class TaskSequenceBenchmark { result.runSyncUnsafe() } - @Benchmark def monixParSequenceUnordered(): Long = { val tasks = (0 until count).map(_ => Task.eval(1)).toList @@ -143,4 +141,4 @@ class TaskSequenceBenchmark { Await.result(f, Duration.Inf) } -} \ No newline at end of file +} diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskShallowBindBenchmark.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskShallowBindBenchmark.scala index e5cea724d..880214e6b 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/TaskShallowBindBenchmark.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/TaskShallowBindBenchmark.scala @@ -27,19 +27,19 @@ import scala.concurrent.Await import scala.concurrent.duration.Duration /** To do comparative benchmarks between versions: - * - * benchmarks/run-benchmark TaskShallowBindBenchmark - * - * This will generate results in `benchmarks/results`. - * - * Or to run the benchmark from within SBT: - * - * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.TaskShallowBindBenchmark - * - * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". - * Please note that benchmarks should be usually executed at least in - * 10 iterations (as a rule of thumb), but more is better. - */ + * + * benchmarks/run-benchmark TaskShallowBindBenchmark + * + * This will generate results in `benchmarks/results`. + * + * Or to run the benchmark from within SBT: + * + * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.TaskShallowBindBenchmark + * + * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". + * Please note that benchmarks should be usually executed at least in + * 10 iterations (as a rule of thumb), but more is better. + */ @State(Scope.Thread) @BenchmarkMode(Array(Mode.Throughput)) @OutputTimeUnit(TimeUnit.SECONDS) @@ -79,4 +79,4 @@ class TaskShallowBindBenchmark { Await.result(task.runToFuture, Duration.Inf) } } -*/ \ No newline at end of file + */ diff --git a/benchmarks/shared/src/main/scala/monix/benchmarks/package.scala b/benchmarks/shared/src/main/scala/monix/benchmarks/package.scala index b3ca039a9..6837f174e 100644 --- a/benchmarks/shared/src/main/scala/monix/benchmarks/package.scala +++ b/benchmarks/shared/src/main/scala/monix/benchmarks/package.scala @@ -17,12 +17,12 @@ package monix -import cats.effect.{ContextShift, IO} +import cats.effect.{ ContextShift, IO } import monix.execution.ExecutionModel.SynchronousExecution import monix.execution.Scheduler import monix.execution.Scheduler.Implicits.global import zio.BootstrapRuntime -import zio.internal.{Platform, Tracing} +import zio.internal.{ Platform, Tracing } import scala.concurrent.ExecutionContext diff --git a/benchmarks/vnext/src/main/scala/monix/benchmarks/AsyncQueueBenchmark.scala b/benchmarks/vnext/src/main/scala/monix/benchmarks/AsyncQueueBenchmark.scala index 15d3c7063..671c9d19a 100644 --- a/benchmarks/vnext/src/main/scala/monix/benchmarks/AsyncQueueBenchmark.scala +++ b/benchmarks/vnext/src/main/scala/monix/benchmarks/AsyncQueueBenchmark.scala @@ -18,11 +18,11 @@ package monix.benchmarks import java.util.concurrent.TimeUnit -import monix.execution.ChannelType.{MPMC, SPMC, SPSC} -import monix.execution.{AsyncQueue, CancelableFuture, ChannelType, BufferCapacity} +import monix.execution.ChannelType.{ MPMC, SPMC, SPSC } +import monix.execution.{ AsyncQueue, BufferCapacity, CancelableFuture, ChannelType } import org.openjdk.jmh.annotations._ import scala.concurrent.duration.Duration -import scala.concurrent.{Await, Future} +import scala.concurrent.{ Await, Future } /** To do comparative benchmarks between versions: * @@ -93,4 +93,3 @@ class AsyncQueueBenchmark { Await.result(r, Duration.Inf) } } - diff --git a/benchmarks/vnext/src/main/scala/monix/benchmarks/ObservableIteratorBenchmark.scala b/benchmarks/vnext/src/main/scala/monix/benchmarks/ObservableIteratorBenchmark.scala index 36d31d1e1..214b565d6 100644 --- a/benchmarks/vnext/src/main/scala/monix/benchmarks/ObservableIteratorBenchmark.scala +++ b/benchmarks/vnext/src/main/scala/monix/benchmarks/ObservableIteratorBenchmark.scala @@ -27,7 +27,7 @@ import org.openjdk.jmh.annotations._ import scala.collection.immutable.IndexedSeq import scala.concurrent.duration.Duration -import scala.concurrent.{Await, Promise} +import scala.concurrent.{ Await, Promise } /** To do comparative benchmarks between versions: * @@ -86,7 +86,7 @@ class ObservableIteratorBenchmark { val p = Promise[Int]() stream.unsafeSubscribeFn(new Subscriber.Sync[Int] { val scheduler = benchmarks.scheduler - private[this] var sum: Int = 0 + private var sum: Int = 0 def onError(ex: Throwable): Unit = p.failure(ex) diff --git a/benchmarks/vnext/src/main/scala/monix/benchmarks/TaskShiftBenchmark.scala b/benchmarks/vnext/src/main/scala/monix/benchmarks/TaskShiftBenchmark.scala index da576a660..1f302202f 100644 --- a/benchmarks/vnext/src/main/scala/monix/benchmarks/TaskShiftBenchmark.scala +++ b/benchmarks/vnext/src/main/scala/monix/benchmarks/TaskShiftBenchmark.scala @@ -146,4 +146,4 @@ object TaskShiftBenchmark { val trampolinedShift2: Task[Unit] = Task.Async((_, cb) => cb.onSuccess(())) -} \ No newline at end of file +} diff --git a/benchmarks/vprev/src/main/scala/monix/benchmarks/AsyncQueueBenchmark.scala b/benchmarks/vprev/src/main/scala/monix/benchmarks/AsyncQueueBenchmark.scala index cdbb9fec9..c2555256f 100644 --- a/benchmarks/vprev/src/main/scala/monix/benchmarks/AsyncQueueBenchmark.scala +++ b/benchmarks/vprev/src/main/scala/monix/benchmarks/AsyncQueueBenchmark.scala @@ -22,7 +22,7 @@ import monix.execution.CancelableFuture import monix.execution.AsyncQueue import org.openjdk.jmh.annotations._ import scala.concurrent.duration.Duration -import scala.concurrent.{Await, Future} +import scala.concurrent.{ Await, Future } /** To do comparative benchmarks between versions: * @@ -92,4 +92,3 @@ class AsyncQueueBenchmark { Await.result(r, Duration.Inf) } } - diff --git a/benchmarks/vprev/src/main/scala/monix/benchmarks/TaskShiftBenchmark.scala b/benchmarks/vprev/src/main/scala/monix/benchmarks/TaskShiftBenchmark.scala index 7f8fe311a..b3cbc9f77 100644 --- a/benchmarks/vprev/src/main/scala/monix/benchmarks/TaskShiftBenchmark.scala +++ b/benchmarks/vprev/src/main/scala/monix/benchmarks/TaskShiftBenchmark.scala @@ -27,19 +27,19 @@ import scala.concurrent.Await import scala.concurrent.duration.Duration /** To do comparative benchmarks between versions: - * - * benchmarks/run-benchmark TaskShiftBenchmark - * - * This will generate results in `benchmarks/results`. - * - * Or to run the benchmark from within SBT: - * - * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.TaskShiftBenchmark - * - * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". - * Please note that benchmarks should be usually executed at least in - * 10 iterations (as a rule of thumb), but more is better. - */ + * + * benchmarks/run-benchmark TaskShiftBenchmark + * + * This will generate results in `benchmarks/results`. + * + * Or to run the benchmark from within SBT: + * + * jmh:run -i 10 -wi 10 -f 2 -t 1 monix.benchmarks.TaskShiftBenchmark + * + * Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". + * Please note that benchmarks should be usually executed at least in + * 10 iterations (as a rule of thumb), but more is better. + */ @State(Scope.Thread) @BenchmarkMode(Array(Mode.Throughput)) @OutputTimeUnit(TimeUnit.SECONDS) @@ -155,4 +155,4 @@ object TaskShiftBenchmark { ctx.scheduler.executeTrampolined(() => cb.onSuccess(())) } } - */ \ No newline at end of file + */ diff --git a/build.sbt b/build.sbt index 6e2e02ed5..1bbb7929d 100644 --- a/build.sbt +++ b/build.sbt @@ -1,10 +1,14 @@ import MonixBuildUtils.* +import com.github.sbt.git.SbtGit.GitKeys.useConsoleForROGit +import com.typesafe.tools.mima.core.ProblemFilter import org.typelevel.scalacoptions.ScalacOptions import sbt.Keys.version -import sbt.{Def, Global, Tags} +import sbt.{ Def, Global, Tags } import scala.collection.immutable.SortedSet +ThisBuild / useConsoleForROGit := true + val benchmarkProjects = List( "benchmarksPrev", "benchmarksNext" @@ -15,30 +19,44 @@ val jvmTests = List( "tracingTests" ).map(_ + "/test").mkString(" ;") -addCommandAlias("ci-all", ";ci-jvm ;ci-js ;ci-meta") -addCommandAlias("ci-js", ";clean ;coreJS/Test/compile ;coreJS/test ;coreJS/package") -addCommandAlias("ci-jvm", ";clean ;coreJVM/Test/compile ;coreJVM/test ;coreJVM/package ;tracingTests/test") -addCommandAlias("ci-meta", ";mimaReportBinaryIssues ;unidoc") -addCommandAlias("ci-release", ";+publishSigned ;sonatypeBundleRelease") +addCommandAlias( + "ci-all", + ";ci-jvm ;ci-js ;ci-meta" +) +addCommandAlias( + "ci-js", + ";clean ;coreJS/Test/compile ;coreJS/test ;coreJS/package" +) +addCommandAlias( + "ci-jvm", + ";clean ;coreJVM/Test/compile ;coreJVM/test ;coreJVM/package ;tracingTests/test" +) +addCommandAlias( + "ci-meta", + ";mimaReportBinaryIssues ;unidoc" +) +addCommandAlias( + "ci-release", + ";+publishSigned ;sonatypeBundleRelease" +) // ------------------------------------------------------------------------------------------------ // Dependencies - Versions -val cats_Version = "2.7.0" +val cats_Version = "2.13.0" val catsEffect_Version = "2.5.5" val fs2_Version = "2.5.11" val jcTools_Version = "4.0.5" val reactiveStreams_Version = "1.0.4" -val macrotaskExecutor_Version = "1.0.0" +val macrotaskExecutor_Version = "1.1.1" val minitest_Version = "2.9.6" val implicitBox_Version = "0.3.4" val kindProjector_Version = "0.13.4" val betterMonadicFor_Version = "0.3.1" -val silencer_Version = "1.7.19" -val scalaCompat_Version = "2.7.0" +val scalaCompat_Version = "2.14.0" // The Monix version with which we must keep binary compatibility. -// https://github.com/typesafehub/migration-manager/wiki/Sbt-plugin +// https://github.com/lightbend/mima#sbt val monixSeries = "3.4.0" // ------------------------------------------------------------------------------------------------ @@ -98,10 +116,6 @@ lazy val scalaCollectionCompatLib = lazy val betterMonadicForCompilerPlugin = "com.olegpy" %% "better-monadic-for" % betterMonadicFor_Version -/** [[https://github.com/ghik/silencer]] */ -lazy val silencerCompilerPlugin = - ("com.github.ghik" % "silencer-plugin" % silencer_Version).cross(CrossVersion.full) - lazy val macroDependencies = Seq( libraryDependencies ++= ( @@ -156,10 +170,15 @@ lazy val isDotty = } } -lazy val sharedSettings = pgpSettings ++ Seq( +lazy val isCI = { + sys.env.getOrElse("SBT_PROFILE", "").contains("ci") || + sys.env.get("CI").exists(v => v == "true" || v == "1" || v == "yes") +} + +lazy val sharedSettings = pgpSettings ++ Def.settings( organization := "io.monix", // Value extracted from .github/workflows/build.yml - scalaVersion := crossScalaVersionsFromBuildYaml.value.head.value, + scalaVersion := crossScalaVersionsFromBuildYaml.value.flatMap(_.filterPrefix("2.13.")).head.value, // Value extracted from .github/workflows/build.yml crossScalaVersions := crossScalaVersionsFromBuildYaml.value.toIndexedSeq.map(_.value), gitHubTreeTagOrHash := { @@ -169,69 +188,72 @@ lazy val sharedSettings = pgpSettings ++ Seq( else ver }, - /* + // Enable this to debug warnings... Compile / scalacOptions ++= { CrossVersion.partialVersion(scalaVersion.value) match { - case Some((2, 13)) => Seq("-Wconf:any:warning-verbose") - case _ => Seq.empty + case Some((2, 13)) => + Seq( + "-Xfatal-warnings", + "-Xsource:3-cross", + // These break binary backwards compatibility, enabled by -Xsource:3, so disabling them + "-Xsource-features:-case-apply-copy-access,-case-companion-function,-infer-override", + // Silence various warnings that are false positives or intentional patterns + // "-Wconf:cat=other-pure-statement:silent,cat=lint-constant:silent,cat=unused-privates:silent,cat=unused-locals:silent,cat=unused-params:silent,cat=unused-imports:silent,cat=w-flag-numeric-widen:silent,any:warning-verbose", + // @nowarn statements for Scala 3 will generate unused-nowarn for Scala 2.13 + "-Wconf:cat=unused-nowarn:s", + // Disabling via -Xsource-features will generate these warnings + "-Wconf:cat=scala3-migration:s", + ) + case Some((3, _)) => + Seq( + "-Werror", + "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s" + ) + case _ => + Seq.empty } }, - */ - - // Disabled from the sbt-tpolecat set - Compile / scalacOptions --= Seq( - "-Wunused:privates", - "-Ywarn-unused:privates", - "-Wunused:implicits", - "-Ywarn-unused:implicits", - "-Wunused:imports", - "-Ywarn-unused:imports", - "-Wunused:explicits", - "-Ywarn-unused:params", - "-Wunused:params", - "-Xlint:infer-any", - "-Wnonunit-statement", - ), - // Disabled from tpolecat for test compilation: - // -Wunused:patvars triggers on for-comprehension loop vars in tests (pre-existing pattern) - // -Xlint:constant triggers on intentional overflow tests (e.g. Long.MaxValue + 1) - Test / scalacOptions --= { + Test / scalacOptions ++= { CrossVersion.partialVersion(scalaVersion.value) match { - case Some((2, 13)) => Seq("-Wunused:patvars", "-Xlint:constant") - case Some((2, 12)) => Seq("-Ywarn-unused:patvars") - case _ => Seq.empty + case Some((2, 13)) => Seq( + // Silence various warnings in tests + "-Wconf:cat=other-pure-statement:silent,cat=lint-constant:silent,cat=unused-privates:silent,cat=unused-locals:silent,cat=unused-params:silent,cat=unused-imports:silent,cat=w-flag-numeric-widen:silent" + ) + case Some((3, _)) => + Seq( + // Scala 3.8.x surfaces a very large warning volume in legacy tests and doctests. + // Keep -Werror for main sources, but silence test warnings to preserve CI signal. + "-Wconf:any:silent" + ) + case _ => + Seq.empty } }, + // Turning off fatal warnings for doc generation Compile / doc / tpolecatExcludeOptions ++= ScalacOptions.defaultConsoleExclude, - // Silence "unused @nowarn" —Thread#getId on JDK11 - Compile / scalacOptions ++= Seq("-Wconf:cat=unused-nowarn:s"), - // Silence everything in auto-generated files - scalacOptions ++= { - if (isDotty.value) - Seq.empty - else - Seq("-P:silencer:pathFilters=.*[/]src_managed[/].*") - }, - scalacOptions --= { - if (isDotty.value) - // tpolecat uses -Werror in Scala 3; disable fatal warnings - // so that pre-existing value-discard and similar patterns don't break Scala 3 builds - Seq("-Werror") - else - Seq() + + // Turn off annoyances in tests + Test / tpolecatExcludeOptions ++= { + Set( + ScalacOptions.lintInferAny, + ScalacOptions.warnUnusedImplicits, + ScalacOptions.warnUnusedExplicits, + ScalacOptions.warnUnusedParams, + ScalacOptions.warnUnusedNoWarn, + ) }, // Syntax improvements, linting, etc. libraryDependencies ++= { if (isDotty.value) Seq() - else + else { Seq( compilerPlugin(kindProjectorCompilerPlugin), - compilerPlugin(betterMonadicForCompilerPlugin), - compilerPlugin(silencerCompilerPlugin) + compilerPlugin(betterMonadicForCompilerPlugin) ) + } }, libraryDependencies ++= Seq( scalaCollectionCompatLib.value % "provided;optional" @@ -247,12 +269,13 @@ lazy val sharedSettings = pgpSettings ++ Seq( "-sourcepath", file(".").getAbsolutePath.replaceAll("[.]$", "") ), - // Without this setting, the outcome of a test-suite will be printed all at - // once, instead of line by line, as tests are being completed - Test / logBuffered := false, + // // Tries disabling parallel execution in tests (in the same project / task) + Test / logBuffered := isCI, Test / parallelExecution := false, + Test / testForkedParallel := false, + // https://github.com/sbt/sbt/issues/2654 incOptions := incOptions.value.withLogRecompileOnMacro(false), // -- Settings meant for deployment on oss.sonatype.org @@ -268,7 +291,8 @@ lazy val sharedSettings = pgpSettings ++ Seq( pomIncludeRepository := { _ => false }, // removes optional dependencies licenses := Seq("APL2" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")), homepage := Some(url("https://monix.io")), - headerLicense := Some(HeaderLicense.Custom("""|Copyright (c) 2014-2021 by The Monix Project Developers. + headerLicense := Some(HeaderLicense.Custom(""" + |Copyright (c) 2014-2022 Monix Contributors. |See the project homepage at: https://monix.io | |Licensed under the Apache License, Version 2.0 (the "License"); @@ -281,7 +305,7 @@ lazy val sharedSettings = pgpSettings ++ Seq( |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.""".stripMargin)), + |limitations under the License.""".trim.stripMargin)), scmInfo := Some( ScmInfo( url("https://github.com/monix/monix"), @@ -298,28 +322,37 @@ lazy val sharedSettings = pgpSettings ++ Seq( ) ) -lazy val sharedSourcesSettings = Seq( - Compile / unmanagedSourceDirectories += { - baseDirectory.value.getParentFile / "shared" / "src" / "main" / "scala" - }, - Test / unmanagedSourceDirectories += { - baseDirectory.value.getParentFile / "shared" / "src" / "test" / "scala" - } -) - def scalaPartV = Def.setting(CrossVersion.partialVersion(scalaVersion.value)) -lazy val crossVersionSourcesSettings: Seq[Setting[_]] = - Seq(Compile, Test).map { sc => +lazy val extraSourceSettings = { + val shared = Seq( + Compile / unmanagedSourceDirectories += { + baseDirectory.value.getParentFile / "shared" / "src" / "main" / "scala" + }, + Test / unmanagedSourceDirectories += { + baseDirectory.value.getParentFile / "shared" / "src" / "test" / "scala" + } + ) + + val perVersion = Seq(Compile, Test).map { sc => (sc / unmanagedSourceDirectories) ++= { (sc / unmanagedSourceDirectories).value.flatMap { dir => - scalaPartV.value match { - case Some((3, _)) => Seq(new File(dir.getPath + "_3.0")) - case _ => Seq(new File(dir.getPath + "_2.13+"), new File(dir.getPath + "_3.0-")) - } + if (dir.getPath().endsWith("scala")) + scalaPartV.value.toList.flatMap { + case (major, minor) => + Seq( + new File(s"${dir.getPath}-$major"), + new File(s"${dir.getPath}-$major.$minor"), + ) + } + else + Seq.empty } } } + shared ++ perVersion +} + lazy val doNotPublishArtifactSettings = Seq( publishArtifact := false, Compile / packageDoc / publishArtifact := false, @@ -337,6 +370,9 @@ lazy val assemblyShadeSettings = Seq( // otherwise, there's a cyclic dependency between packageBin and assembly assembly / fullClasspath := (Runtime / managedClasspath).value, // in dependent projects, use assembled and shaded jar + // Note: exportJars must be false during assembly, but true for dependent projects + // With sbt-assembly 2.x we need to ensure exportJars is false during the assembly task + assembly / exportJars := false, exportJars := true, // do not include scala dependency in pom autoScalaLibrary := false, @@ -348,7 +384,15 @@ lazy val assemblyShadeSettings = Seq( lazy val unidocSettings = Seq( ScalaUnidoc / unidoc / unidocProjectFilter := - inProjects(executionJVM, catnapJVM, evalJVM, tailJVM, reactiveJVM), + inProjects( + executionAtomicJVM, + executionJVM, + catnapJVM, + evalJVM, + tailJVM, + reactiveJVM, + ), + // Exclude monix.*.internal from ScalaDoc ScalaUnidoc / unidoc / sources ~= (_.filterNot { file => // Exclude all internal Java files from documentation @@ -386,19 +430,10 @@ lazy val sharedJSSettings = Seq( } ) -def mimaSettings(projectName: String) = Seq( +def mimaSettings(projectName: String, exclusions: Seq[ProblemFilter]) = Seq( + ThisBuild / mimaFailOnNoPrevious := false, mimaPreviousArtifacts := Set("io.monix" %% projectName % monixSeries), - mimaBinaryIssueFilters ++= MimaFilters.changesFor_3_0_1, - mimaBinaryIssueFilters ++= MimaFilters.changesFor_3_2_0, - mimaBinaryIssueFilters ++= MimaFilters.changesFor_3_3_0, - mimaBinaryIssueFilters ++= MimaFilters.changesFor_3_4_0, - mimaBinaryIssueFilters ++= MimaFilters.changesFor_avs -) - -lazy val doctestTestSettings = Seq( - doctestTestFramework := DoctestTestFramework.Minitest, - doctestIgnoreRegex := Some(s".*TaskApp.scala|.*reactive.internal.(builders|operators|rstreams).*"), - doctestOnlyCodeBlocksMode := true + mimaBinaryIssueFilters ++= exclusions ) // ------------------------------------------------------------------------------------------------ @@ -414,6 +449,7 @@ def baseSettingsAndPlugins(publishArtifacts: Boolean): Project ⇒ Project = .enablePlugins(AutomateHeaderPlugin) .settings(sharedSettings) .settings(if (publishArtifacts) Seq.empty else doNotPublishArtifactSettings) + .settings(scalafmtOnCompile := !isCI) .settings( filterOutMultipleDependenciesFromGeneratedPomXml( "groupId" -> "org.scoverage".r :: Nil, @@ -428,22 +464,19 @@ def monixSubModule( ): Project => Project = pr => { pr.configure(baseSettingsAndPlugins(publishArtifacts = publishArtifacts)) .enablePlugins(ReproducibleBuildsPlugin) - .settings(sharedSourcesSettings) - .settings(crossVersionSourcesSettings) + .settings(extraSourceSettings) .settings(name := projectName) } def jvmModule( projectName: String, - withMimaChecks: Boolean, - withDocTests: Boolean, - publishArtifacts: Boolean + publishArtifacts: Boolean, + withMimaChecks: Option[Seq[ProblemFilter]] ): Project => Project = pr => { pr.configure(monixSubModule(projectName, publishArtifacts = publishArtifacts)) .settings(testDependencies) - .settings(if (withDocTests) doctestTestSettings else Seq.empty) - .settings(if (withMimaChecks) mimaSettings(projectName) else Seq.empty) + .settings(withMimaChecks.toSeq.flatMap(mimaSettings(projectName, _))) } def jsProfile(projectName: String, publishArtifacts: Boolean): Project => Project = @@ -456,18 +489,16 @@ def jsProfile(projectName: String, publishArtifacts: Boolean): Project => Projec def crossModule( projectName: String, - withMimaChecks: Boolean = true, - withDocTests: Boolean = true, - publishArtifacts: Boolean = true, - crossSettings: Seq[sbt.Def.SettingsDefinition] = Nil + withMimaChecks: Option[Seq[ProblemFilter]], + publishArtifacts: Boolean, + crossSettings: Seq[sbt.Def.SettingsDefinition] ): MonixCrossModule = { MonixCrossModule( jvm = jvmModule( projectName = projectName, - withMimaChecks = withMimaChecks, - withDocTests = withDocTests, - publishArtifacts = publishArtifacts + publishArtifacts = publishArtifacts, + withMimaChecks = withMimaChecks ).andThen(_.settings(crossSettings: _*)), js = jsProfile( projectName = projectName, @@ -519,9 +550,9 @@ lazy val monix = project lazy val coreProfile = crossModule( - projectName = "monix", - withMimaChecks = false, - withDocTests = false, + projectName = "monix", + withMimaChecks = None, + publishArtifacts = true, crossSettings = Seq( description := "Root project for Monix, a library for asynchronous programming in Scala. See: https://monix.io" ) @@ -547,9 +578,8 @@ lazy val executionShadedJCTools = project .configure( jvmModule( projectName = "monix-internal-jctools", - withMimaChecks = false, - withDocTests = false, - publishArtifacts = true + publishArtifacts = true, + withMimaChecks = None ) ) .settings(assemblyShadeSettings) @@ -565,13 +595,35 @@ lazy val executionShadedJCTools = project ) ) +// -------------------------------------------- +// monix-execution-atomic + +lazy val executionAtomicProfile = + crossModule( + projectName = "monix-execution-atomic", + withMimaChecks = None, + publishArtifacts = true, + crossSettings = Seq( + description := "Sub-module of Monix, exposing low-level atomic references. See: https://monix.io", + ) + ) + +lazy val executionAtomicJVM = project.in(file("monix-execution/atomic/jvm")) + .configure(executionAtomicProfile.jvm) + .settings(macroDependencies) + +lazy val executionAtomicJS = project.in(file("monix-execution/atomic/js")) + .configure(executionAtomicProfile.js) + .settings(macroDependencies) + // -------------------------------------------- // monix-execution lazy val executionProfile = crossModule( - projectName = "monix-execution", - withDocTests = false, + projectName = "monix-execution", + withMimaChecks = Some(MimaFilters.MonixExecution.all), + publishArtifacts = true, crossSettings = Seq( description := "Sub-module of Monix, exposing low-level primitives for dealing with async execution. See: https://monix.io", libraryDependencies += implicitBoxLib.value @@ -581,22 +633,26 @@ lazy val executionProfile = lazy val executionJVM = project .in(file("monix-execution/jvm")) .configure(executionProfile.jvm) - .settings(macroDependencies) .dependsOn(executionShadedJCTools) + .aggregate(executionAtomicJVM) + .dependsOn(executionAtomicJVM) .settings(libraryDependencies += reactiveStreamsLib) lazy val executionJS = project .in(file("monix-execution/js")) .configure(executionProfile.js) - .settings(macroDependencies) .settings(libraryDependencies += macrotaskExecutorLib.value) + .aggregate(executionAtomicJS) + .dependsOn(executionAtomicJS) // -------------------------------------------- // monix-catnap lazy val catnapProfile = crossModule( - projectName = "monix-catnap", + projectName = "monix-catnap", + withMimaChecks = Some(MimaFilters.MonixCatnap.all), + publishArtifacts = true, crossSettings = Seq( description := "Sub-module of Monix, exposing pure abstractions built on top of the Cats-Effect type classes. See: https://monix.io", libraryDependencies += catsEffectLib.value @@ -618,7 +674,9 @@ lazy val catnapJS = project lazy val evalProfile = crossModule( - projectName = "monix-eval", + projectName = "monix-eval", + withMimaChecks = Some(MimaFilters.MonixEval.all), + publishArtifacts = true, crossSettings = Seq( description := "Sub-module of Monix, exposing Task and Coeval, for suspending side-effects. See: https://monix.io" ) @@ -641,7 +699,9 @@ lazy val evalJS = project lazy val tailProfile = crossModule( - projectName = "monix-tail", + projectName = "monix-tail", + withMimaChecks = Some(MimaFilters.MonixTail.all), + publishArtifacts = true, crossSettings = Seq( description := "Sub-module of Monix, exposing Iterant for purely functional pull based streaming. See: https://monix.io" ) @@ -664,7 +724,9 @@ lazy val tailJS = project lazy val reactiveProfile = crossModule( - projectName = "monix-reactive", + projectName = "monix-reactive", + withMimaChecks = Some(MimaFilters.MonixReactive.all), + publishArtifacts = true, crossSettings = Seq( description := "Sub-module of Monix, exposing the Observable pattern for modeling of reactive streams. See: https://monix.io" ) @@ -686,13 +748,13 @@ lazy val reactiveJS = project lazy val javaJVM = project .in(file("monix-java")) .configure( - jvmModule( + monixSubModule( projectName = "monix-java", - withMimaChecks = true, - withDocTests = true, publishArtifacts = true ) ) + .settings(testDependencies) + .settings(mimaSettings("monix-java", MimaFilters.MonixJava.all)) .dependsOn(executionJVM % "provided->compile; test->test") .dependsOn(evalJVM % "provided->compile; test->test") @@ -710,7 +772,8 @@ lazy val reactiveTests = project .dependsOn(reactiveJVM, tailJVM) .settings( libraryDependencies ++= Seq( - reactiveStreamsTCKLib % Test + reactiveStreamsTCKLib % Test, + "org.scalatestplus" %% "testng-7-5" % "3.2.12.0" % Test, ) ) diff --git a/monix-catnap/js/src/main/scala/monix/catnap/internal/FutureLiftForPlatform.scala b/monix-catnap/js/src/main/scala/monix/catnap/internal/FutureLiftForPlatform.scala index fa235fe9b..fa0d4a7fd 100644 --- a/monix-catnap/js/src/main/scala/monix/catnap/internal/FutureLiftForPlatform.scala +++ b/monix-catnap/js/src/main/scala/monix/catnap/internal/FutureLiftForPlatform.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-catnap/jvm/src/main/scala/monix/catnap/internal/FutureLiftForPlatform.scala b/monix-catnap/jvm/src/main/scala/monix/catnap/internal/FutureLiftForPlatform.scala index 4b337cf9b..2318e3e7b 100644 --- a/monix-catnap/jvm/src/main/scala/monix/catnap/internal/FutureLiftForPlatform.scala +++ b/monix-catnap/jvm/src/main/scala/monix/catnap/internal/FutureLiftForPlatform.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,9 +18,9 @@ package monix.catnap package internal -import java.util.concurrent.{CancellationException, CompletableFuture, CompletionException} +import java.util.concurrent.{ CancellationException, CompletableFuture, CompletionException } import java.util.function.BiFunction -import cats.effect.{Async, Concurrent} +import cats.effect.{ Async, Concurrent } private[catnap] abstract class FutureLiftForPlatform { /** @@ -51,7 +51,8 @@ private[catnap] abstract class FutureLiftForPlatform { * and [[javaCompletableToAsync]]. */ def javaCompletableToConcurrentOrAsync[F[_], A](fa: F[CompletableFuture[A]])( - implicit F: Concurrent[F] OrElse Async[F]): F[A] = { + implicit F: OrElse[Concurrent[F], Async[F]] + ): F[A] = { F.unify match { case ref: Concurrent[F] @unchecked => javaCompletableToConcurrent(fa)(ref) @@ -65,7 +66,8 @@ private[catnap] abstract class FutureLiftForPlatform { * or `Async` data type. */ implicit def javaCompletableLiftForConcurrentOrAsync[F[_]]( - implicit F: Concurrent[F] OrElse Async[F]): FutureLift[F, CompletableFuture] = { + implicit F: OrElse[Concurrent[F], Async[F]] + ): FutureLift[F, CompletableFuture] = { F.unify match { case ref: Concurrent[F] @unchecked => diff --git a/monix-catnap/jvm/src/test/scala/monix/catnap/CatsEffectIssue380Suite.scala b/monix-catnap/jvm/src/test/scala/monix/catnap/CatsEffectIssue380Suite.scala index 0e3e06b6e..c10049fa7 100644 --- a/monix-catnap/jvm/src/test/scala/monix/catnap/CatsEffectIssue380Suite.scala +++ b/monix-catnap/jvm/src/test/scala/monix/catnap/CatsEffectIssue380Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ import minitest.SimpleTestSuite import cats.effect.IO import cats.implicits._ import monix.execution.atomic.Atomic -import scala.concurrent.{CancellationException, ExecutionContext} +import scala.concurrent.{ CancellationException, ExecutionContext } import scala.concurrent.duration._ object CatsEffectIssue380Suite extends SimpleTestSuite { @@ -50,7 +50,7 @@ object CatsEffectIssue380Suite extends SimpleTestSuite { val dt = 10.seconds assert(task.unsafeRunTimed(dt).nonEmpty, s"timed-out after $dt") } finally { - cancelLoop := true + cancelLoop.set(true) } } } finally { @@ -82,7 +82,7 @@ object CatsEffectIssue380Suite extends SimpleTestSuite { val dt = 10.seconds assert(task.unsafeRunTimed(dt).nonEmpty, s"timed-out after $dt") } finally { - cancelLoop := true + cancelLoop.set(true) } } } finally { diff --git a/monix-catnap/jvm/src/test/scala/monix/catnap/ConcurrentChannelJVMSuite.scala b/monix-catnap/jvm/src/test/scala/monix/catnap/ConcurrentChannelJVMSuite.scala index d5a055060..70cc77eed 100644 --- a/monix-catnap/jvm/src/test/scala/monix/catnap/ConcurrentChannelJVMSuite.scala +++ b/monix-catnap/jvm/src/test/scala/monix/catnap/ConcurrentChannelJVMSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.catnap import cats.effect.IO import monix.execution.BufferCapacity.Bounded -import monix.execution.{BufferCapacity, Scheduler} +import monix.execution.{ BufferCapacity, Scheduler } import monix.execution.schedulers.SchedulerService import scala.concurrent.duration._ diff --git a/monix-catnap/jvm/src/test/scala/monix/catnap/ConcurrentQueueJVMSuite.scala b/monix-catnap/jvm/src/test/scala/monix/catnap/ConcurrentQueueJVMSuite.scala index 27b4fcc4c..be46a6bce 100644 --- a/monix-catnap/jvm/src/test/scala/monix/catnap/ConcurrentQueueJVMSuite.scala +++ b/monix-catnap/jvm/src/test/scala/monix/catnap/ConcurrentQueueJVMSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-catnap/jvm/src/test/scala/monix/catnap/FutureLiftJava8Suite.scala b/monix-catnap/jvm/src/test/scala/monix/catnap/FutureLiftJava8Suite.scala index 5dcd39e9e..d15582156 100644 --- a/monix-catnap/jvm/src/test/scala/monix/catnap/FutureLiftJava8Suite.scala +++ b/monix-catnap/jvm/src/test/scala/monix/catnap/FutureLiftJava8Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,13 +18,13 @@ package monix.catnap import java.util.concurrent.CompletableFuture -import cats.effect.{Async, Concurrent, ContextShift, IO} +import cats.effect.{ Async, Concurrent, ContextShift, IO } import minitest.TestSuite import monix.catnap.syntax._ import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler import scala.concurrent.Promise -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object FutureLiftJava8Suite extends TestSuite[TestScheduler] { def setup() = TestScheduler() @@ -94,7 +94,8 @@ object FutureLiftJava8Suite extends TestSuite[TestScheduler] { val p = Promise[Int]() val cancel = convertConcurrent(IO(future)).unsafeRunCancelable(r => - p.complete(r match { case Right(a) => Success(a); case Left(e) => Failure(e) })) + p.complete(r match { case Right(a) => Success(a); case Left(e) => Failure(e) }) + ) s.tick() assertEquals(p.future.value, None) diff --git a/monix-catnap/jvm/src/test/scala/monix/catnap/MVarJVMSuite.scala b/monix-catnap/jvm/src/test/scala/monix/catnap/MVarJVMSuite.scala index 0e6ce88de..e2756e8d5 100644 --- a/monix-catnap/jvm/src/test/scala/monix/catnap/MVarJVMSuite.scala +++ b/monix-catnap/jvm/src/test/scala/monix/catnap/MVarJVMSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ import cats.implicits._ import cats.effect._ import cats.effect.concurrent.Deferred import minitest.TestSuite -import monix.execution.{Scheduler, TestUtils} +import monix.execution.{ Scheduler, TestUtils } import monix.execution.schedulers.SchedulerService import scala.concurrent.CancellationException diff --git a/monix-catnap/jvm/src/test/scala/monix/catnap/SemaphoreJVMSuite.scala b/monix-catnap/jvm/src/test/scala/monix/catnap/SemaphoreJVMSuite.scala index 61ba921d2..696c9d7a2 100644 --- a/monix-catnap/jvm/src/test/scala/monix/catnap/SemaphoreJVMSuite.scala +++ b/monix-catnap/jvm/src/test/scala/monix/catnap/SemaphoreJVMSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,10 +20,10 @@ package monix.catnap import java.util.concurrent.atomic.AtomicBoolean import cats.effect.concurrent.Deferred -import cats.effect.{ContextShift, IO, Timer} +import cats.effect.{ ContextShift, IO, Timer } import cats.implicits._ import minitest.TestSuite -import monix.execution.{Scheduler, TestUtils} +import monix.execution.{ Scheduler, TestUtils } import monix.execution.schedulers.SchedulerService import scala.concurrent.CancellationException diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/CancelableF.scala b/monix-catnap/shared/src/main/scala/monix/catnap/CancelableF.scala index cb203177e..2beaf94ff 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/CancelableF.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/CancelableF.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,8 +18,7 @@ package monix.catnap import cats.Applicative -import cats.effect.{CancelToken, Sync} -import cats.syntax.either._ +import cats.effect.{ CancelToken, Sync } import monix.catnap.cancelables.BooleanCancelableF import monix.execution.annotations.UnsafeBecauseImpure import monix.execution.exceptions.CompositeException @@ -42,10 +41,6 @@ trait CancelableF[F[_]] { } object CancelableF { - - // ensure import cats.syntax.either._ is used - private val dummy = ().asRight - /** * Given a token that does not guarantee idempotency, wraps it * in a [[CancelableF]] value that guarantees the given token @@ -90,7 +85,11 @@ object CancelableF { * cancelling everything when `cancel` gets evaluated. */ def collection[F[_]](refs: CancelableF[F]*)(implicit F: Sync[F]): CancelableF[F] = - wrap[F](cancelAll(refs: _*)) + wrap[F](cancelAllSeq(refs)) + + private def cancelAllSeq[F[_]](seq: Seq[CancelableF[F]])(implicit F: Sync[F]): CancelToken[F] = + if (seq.isEmpty) F.unit + else F.defer(new CancelAllFrame[F](seq.iterator.map(_.cancel))(F).loop) /** Given a collection of cancelables, creates a token that * on evaluation will cancel them all. @@ -138,7 +137,7 @@ object CancelableF { private final class CancelAllFrame[F[_]](cursor: Iterator[CancelToken[F]])(implicit F: Sync[F]) extends (Either[Throwable, Unit] => F[Unit]) { - private[this] val errors = ListBuffer.empty[Throwable] + private val errors = ListBuffer.empty[Throwable] def loop: CancelToken[F] = { if (cursor.hasNext) { diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/ChannelF.scala b/monix-catnap/shared/src/main/scala/monix/catnap/ChannelF.scala index 44557eb94..7f7626283 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/ChannelF.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/ChannelF.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/CircuitBreaker.scala b/monix-catnap/shared/src/main/scala/monix/catnap/CircuitBreaker.scala index e4135d17f..ebb02a2ee 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/CircuitBreaker.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/CircuitBreaker.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,12 +17,12 @@ package monix.catnap -import cats.effect.{Async, Clock, Concurrent, ExitCase, Sync} +import cats.effect.{ Async, Clock, Concurrent, ExitCase, Sync } import cats.implicits._ import monix.execution.CancelablePromise import monix.execution.annotations.UnsafeBecauseImpure import monix.execution.atomic.PaddingStrategy.NoPadding -import monix.execution.atomic.{Atomic, AtomicAny, PaddingStrategy} +import monix.execution.atomic.{ Atomic, AtomicAny, PaddingStrategy } import monix.execution.exceptions.ExecutionRejectedException import monix.execution.internal.Constants import scala.annotation.tailrec @@ -203,7 +203,8 @@ final class CircuitBreaker[F[_]] private ( onRejected: F[Unit], onClosed: F[Unit], onHalfOpen: F[Unit], - onOpen: F[Unit])(implicit F: Sync[F], clock: Clock[F]) { + onOpen: F[Unit] +)(implicit F: Sync[F], clock: Clock[F]) { require(_maxFailures >= 0, "maxFailures >= 0") require(_exponentialBackoffFactor >= 1, "exponentialBackoffFactor >= 1") @@ -211,7 +212,7 @@ final class CircuitBreaker[F[_]] private ( require(_maxResetTimeout > Duration.Zero, "maxResetTimeout > 0") import monix.catnap.CircuitBreaker._ - private[this] val stateRef = _stateRef + private val stateRef = _stateRef /** * The maximum count for allowed failures before opening the circuit breaker. @@ -268,7 +269,7 @@ final class CircuitBreaker[F[_]] private ( * be cancelable, to properly dispose of the registered * listener in case of cancellation. */ - def awaitClose(implicit F: Concurrent[F] OrElse Async[F]): F[Unit] = { + def awaitClose(implicit F: OrElse[Concurrent[F], Async[F]]): F[Unit] = { val F0 = F.unify F0.defer { stateRef.get() match { @@ -285,7 +286,7 @@ final class CircuitBreaker[F[_]] private ( /** Function for counting failures in the `Closed` state, * triggering the `Open` state if necessary. */ - private[this] val maybeMarkOrResetFailures: (Either[Throwable, Any] => F[Any]) = { + private val maybeMarkOrResetFailures: (Either[Throwable, Any] => F[Any]) = { // Reschedule logic, for retries that come after a `Clock` query // and that can no longer be tail-recursive def reschedule[A](exit: Either[Throwable, A]): F[A] = @@ -357,7 +358,8 @@ final class CircuitBreaker[F[_]] private ( task: F[A], resetTimeout: FiniteDuration, await: CancelablePromise[Unit], - lastStartedAt: Timestamp): F[A] = + lastStartedAt: Timestamp + ): F[A] = F.bracketCase(onHalfOpen)(_ => task) { (_, exit) => exit match { case ExitCase.Canceled => @@ -417,7 +419,8 @@ final class CircuitBreaker[F[_]] private ( ExecutionRejectedException( "Rejected because the CircuitBreaker is in the Open state, " + s"attempting to close in $expiresInMillis millis" - )) + ) + ) } } } @@ -429,7 +432,8 @@ final class CircuitBreaker[F[_]] private ( F.raiseError( ExecutionRejectedException( "Rejected because the CircuitBreaker is in the HalfOpen state" - )) + ) + ) } } @@ -457,7 +461,8 @@ final class CircuitBreaker[F[_]] private ( onRejected = onRejected, onClosed = onClosed, onHalfOpen = onHalfOpen, - onOpen = onOpen) + onOpen = onOpen + ) } /** Returns a new circuit breaker that wraps the state of the source @@ -484,7 +489,8 @@ final class CircuitBreaker[F[_]] private ( onRejected = onRejected, onClosed = onClosed, onHalfOpen = onHalfOpen, - onOpen = onOpen) + onOpen = onOpen + ) } /** Returns a new circuit breaker that wraps the state of the source @@ -512,7 +518,8 @@ final class CircuitBreaker[F[_]] private ( onRejected = onRejected, onClosed = onClosed, onHalfOpen = onHalfOpen, - onOpen = onOpen) + onOpen = onOpen + ) } /** Returns a new circuit breaker that wraps the state of the source @@ -539,7 +546,8 @@ final class CircuitBreaker[F[_]] private ( onRejected = onRejected, onClosed = onClosed, onHalfOpen = onHalfOpen, - onOpen = onOpen) + onOpen = onOpen + ) } } @@ -706,7 +714,8 @@ object CircuitBreaker extends CircuitBreakerDocs { onHalfOpen = onHalfOpen, onOpen = onOpen, padding = padding - )) + ) + ) } /** Unsafe builder, an alternative to [[of CircuitBreaker[F].of]] for @@ -747,7 +756,8 @@ object CircuitBreaker extends CircuitBreakerDocs { onRejected = onRejected, onClosed = onClosed, onHalfOpen = onHalfOpen, - onOpen = onOpen)(F, clock) + onOpen = onOpen + )(F, clock) } } @@ -812,8 +822,8 @@ object CircuitBreaker extends CircuitBreakerDocs { final class Open private ( val startedAt: Timestamp, val resetTimeout: FiniteDuration, - private[catnap] val awaitClose: CancelablePromise[Unit]) - extends State { + private[catnap] val awaitClose: CancelablePromise[Unit] + ) extends State { /** The timestamp in milliseconds since the epoch, specifying * when the `Open` state is to transition to [[HalfOpen]]. @@ -826,8 +836,8 @@ object CircuitBreaker extends CircuitBreakerDocs { override def equals(other: Any): Boolean = other match { case that: Open => startedAt == that.startedAt && - resetTimeout == that.resetTimeout && - awaitClose == that.awaitClose + resetTimeout == that.resetTimeout && + awaitClose == that.awaitClose case _ => false } @@ -843,7 +853,8 @@ object CircuitBreaker extends CircuitBreakerDocs { private[catnap] def apply( startedAt: Timestamp, resetTimeout: FiniteDuration, - awaitClose: CancelablePromise[Unit]): Open = + awaitClose: CancelablePromise[Unit] + ): Open = new Open(startedAt, resetTimeout, awaitClose) /** Implements the pattern matching protocol. */ @@ -883,13 +894,13 @@ object CircuitBreaker extends CircuitBreakerDocs { */ final class HalfOpen private ( val resetTimeout: FiniteDuration, - private[catnap] val awaitClose: CancelablePromise[Unit]) - extends State { + private[catnap] val awaitClose: CancelablePromise[Unit] + ) extends State { override def equals(other: Any): Boolean = other match { case that: HalfOpen => resetTimeout == that.resetTimeout && - awaitClose == that.awaitClose + awaitClose == that.awaitClose case _ => false } diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/ConcurrentChannel.scala b/monix-catnap/shared/src/main/scala/monix/catnap/ConcurrentChannel.scala index 13a82091c..e2d1aa826 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/ConcurrentChannel.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/ConcurrentChannel.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,18 +18,18 @@ package monix.catnap import cats.implicits._ -import cats.effect.{Concurrent, ContextShift, Resource} +import cats.effect.{ Concurrent, ContextShift, Resource } import monix.catnap.internal.QueueHelpers -import monix.execution.BufferCapacity.{Bounded, Unbounded} -import monix.execution.ChannelType.{MultiConsumer, MultiProducer} -import monix.execution.annotations.{UnsafeBecauseImpure, UnsafeProtocol} +import monix.execution.BufferCapacity.{ Bounded, Unbounded } +import monix.execution.ChannelType.{ MultiConsumer, MultiProducer } +import monix.execution.annotations.{ UnsafeBecauseImpure, UnsafeProtocol } import monix.execution.atomic.AtomicAny import monix.execution.atomic.PaddingStrategy.LeftRight128 -import monix.execution.internal.collection.{LowLevelConcurrentQueue => LowLevelQueue} -import monix.execution.internal.{Constants, Platform} -import monix.execution.{CancelablePromise, ChannelType} +import monix.execution.internal.collection.{ LowLevelConcurrentQueue => LowLevelQueue } +import monix.execution.internal.{ Constants, Platform } +import monix.execution.{ CancelablePromise, ChannelType } -import scala.annotation.{switch, tailrec} +import scala.annotation.{ switch, tailrec } import scala.collection.mutable.ArrayBuffer /** @@ -401,7 +401,7 @@ final class ConcurrentChannel[F[_], E, A] private ( * created consumer */ def consume: Resource[F, ConsumerF[F, E, A]] = consumeRef - private[this] val consumeRef = consumeWithConfig(defaultConsumerConfig) + private val consumeRef = consumeWithConfig(defaultConsumerConfig) /** Version of [[consume]] that allows for fine tuning the underlying * buffer used. @@ -497,8 +497,8 @@ final class ConcurrentChannel[F[_], E, A] private ( helpers.stopF } - private[this] val helpers = new Helpers[F] - private[this] val isFinished = () => + private val helpers = new Helpers[F] + private val isFinished = () => state.get() match { case Halt(e) => Some(e) case _ => None @@ -640,8 +640,7 @@ object ConcurrentChannel { private object State { def empty[F[_], E, A]: State[F, E, A] = emptyRef.asInstanceOf[State[F, E, A]] - private[this] val emptyRef = - Connected[cats.Id, Any, Any](Set.empty, null) + private val emptyRef = Connected[cats.Id, Any, Any](Set.empty, null) } private type Ack = Int @@ -677,7 +676,7 @@ object ConcurrentChannel { triggerBroadcastR(refs, f, helpers.unitTest, F.unit, F.unit) } - private[this] def triggerBroadcastR[F[_], E, A, R]( + private def triggerBroadcastR[F[_], E, A, R]( refs: Array[ChanProducer[F, E, A]], f: ChanProducer[F, E, A] => F[R], canContinue: R => Boolean, @@ -717,10 +716,10 @@ object ConcurrentChannel { consumersAwait: AtomicAny[CancelablePromise[Unit]], isFinished: () => Option[E], helpers: Helpers[F] - )(implicit F: Concurrent[F], cs: ContextShift[F]) { + )(implicit F: Concurrent[F]) { @tailrec - private[this] def notifyConsumers(): Unit = { + private def notifyConsumers(): Unit = { // N.B. in case the queue is single-producer, this is a full memory fence // meant to prevent the re-ordering of `queue.offer` with `consumersAwait.get` queue.fenceOffer() @@ -777,7 +776,8 @@ object ConcurrentChannel { if (!hasCapacity) { assert(producersAwait ne null, "producersAwait ne null (Bug!)") val offerWait = F.asyncF[Ack](cb => - helpers.sleepThenRepeat(producersAwait, () => tryPushToOurQueue(elem), pushFilter, pushManyMap, cb)) + helpers.sleepThenRepeat(producersAwait, () => tryPushToOurQueue(elem), pushFilter, pushManyMap, cb) + ) offerWait.flatMap { case Continue => loop(cursor) case Stop => helpers.stopF @@ -796,11 +796,12 @@ object ConcurrentChannel { producersAwait: AtomicAny[CancelablePromise[Unit]], consumersAwait: AtomicAny[CancelablePromise[Unit]], isFinished: () => Option[E], - helpers: Helpers[F])(implicit F: Concurrent[F], cs: ContextShift[F]) + helpers: Helpers[F] + )(implicit F: Concurrent[F]) extends ConsumerF[F, E, A] { @tailrec - private[this] def notifyProducers(): Unit = + private def notifyProducers(): Unit = if (producersAwait ne null) { // N.B. in case this isn't a multi-consumer queue, this generates a // full memory fence in order to prevent the re-ordering of queue.poll() @@ -819,7 +820,7 @@ object ConcurrentChannel { } def pull: F[Either[E, A]] = pullRef - private[this] val pullRef: F[Either[E, A]] = { + private val pullRef: F[Either[E, A]] = { def end(e: E): Either[E, A] = { // Ensures a memory barrier (if needed for the queue's type) that prevents // the reordering of queue.poll with the previous state.get, from the @@ -857,7 +858,8 @@ object ConcurrentChannel { pullFilter, pullMap.asInstanceOf[Either[E, A] => Either[E, A]], cb - )) + ) + ) case value => F.pure(value) } @@ -921,7 +923,8 @@ object ConcurrentChannel { pullFilter, pullMap.asInstanceOf[Either[E, Seq[A]] => Either[E, Seq[A]]], cb - )) + ) + ) } } } diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/ConcurrentQueue.scala b/monix-catnap/shared/src/main/scala/monix/catnap/ConcurrentQueue.scala index 2feb5054e..1012f97dd 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/ConcurrentQueue.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/ConcurrentQueue.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,17 +17,17 @@ package monix.catnap -import cats.effect.{Concurrent, ContextShift} +import cats.effect.{ Concurrent, ContextShift } import cats.implicits._ import monix.catnap.internal.QueueHelpers -import monix.execution.BufferCapacity.{Bounded, Unbounded} +import monix.execution.BufferCapacity.{ Bounded, Unbounded } import monix.execution.ChannelType.MPMC -import monix.execution.annotations.{UnsafeBecauseImpure, UnsafeProtocol} +import monix.execution.annotations.{ UnsafeBecauseImpure, UnsafeProtocol } import monix.execution.atomic.AtomicAny import monix.execution.atomic.PaddingStrategy.LeftRight128 import monix.execution.internal.Constants -import monix.execution.internal.collection.{LowLevelConcurrentQueue => LowLevelQueue} -import monix.execution.{BufferCapacity, CancelablePromise, ChannelType} +import monix.execution.internal.collection.{ LowLevelConcurrentQueue => LowLevelQueue } +import monix.execution.{ BufferCapacity, CancelablePromise, ChannelType } import scala.annotation.tailrec import scala.collection.mutable.ArrayBuffer @@ -197,19 +197,18 @@ final class ConcurrentQueue[F[_], A] private ( */ @UnsafeProtocol def tryPoll: F[Option[A]] = tryPollRef - private[this] val tryPollRef = - F.delay(Option(tryPollUnsafe())) + private val tryPollRef = F.delay(Option(tryPollUnsafe())) /** Fetches a value from the queue, or if the queue is empty it awaits - * asynchronously until a value is made available. - * - * @return a task that when evaluated, will eventually complete - * after the value has been successfully pushed in the queue - */ + * asynchronously until a value is made available. + * + * @return a task that when evaluated, will eventually complete + * after the value has been successfully pushed in the queue + */ def poll: F[A] = pollRef - private[this] val pollRef = F.defer[A] { + private val pollRef = F.defer[A] { val happy = tryPollUnsafe() - //noinspection ForwardReference + // noinspection ForwardReference if (happy != null) F.pure(happy) else @@ -271,8 +270,8 @@ final class ConcurrentQueue[F[_], A] private ( * so it must be called from the same thread(s) that call [[poll]]. */ def clear: F[Unit] = clearRef - //noinspection ForwardReference - private[this] val clearRef = F.delay { + // noinspection ForwardReference + private val clearRef = F.delay { queue.clear() notifyProducers() } @@ -355,25 +354,21 @@ final class ConcurrentQueue[F[_], A] private ( ) } - private[this] val queue: LowLevelQueue[A] = - LowLevelQueue(capacity, channelType, fenced = true) - private[this] val helpers: QueueHelpers[F] = - new QueueHelpers[F] + private val queue: LowLevelQueue[A] = LowLevelQueue(capacity, channelType, fenced = true) + private val helpers: QueueHelpers[F] = new QueueHelpers[F] - private[this] val consumersAwaiting = - AtomicAny.withPadding[CancelablePromise[Unit]](null, LeftRight128) + private val consumersAwaiting = AtomicAny.withPadding[CancelablePromise[Unit]](null, LeftRight128) - private[this] val producersAwaiting = - if (capacity.isBounded) - AtomicAny.withPadding[CancelablePromise[Unit]](null, LeftRight128) - else - null + private val producersAwaiting = if (capacity.isBounded) + AtomicAny.withPadding[CancelablePromise[Unit]](null, LeftRight128) + else + null - private[this] val pollQueue: () => A = () => tryPollUnsafe() - private[this] val pollTest: A => Boolean = _ != null - private[this] val pollMap: A => A = a => a - private[this] val offerTest: Boolean => Boolean = x => x - private[this] val offerMap: Boolean => Unit = _ => () + private val pollQueue: () => A = () => tryPollUnsafe() + private val pollTest: A => Boolean = _ != null + private val pollMap: A => A = a => a + private val offerTest: Boolean => Boolean = x => x + private val offerMap: Boolean => Unit = _ => () private def toSeq(buffer: ArrayBuffer[A]): Seq[A] = buffer.toArray[Any].toSeq.asInstanceOf[Seq[A]] @@ -440,7 +435,8 @@ object ConcurrentQueue { * @param F $concurrentParam */ def unbounded[F[_], A]( - chunkSizeHint: Option[Int] = None)(implicit F: Concurrent[F], cs: ContextShift[F]): F[ConcurrentQueue[F, A]] = + chunkSizeHint: Option[Int] = None + )(implicit F: Concurrent[F], cs: ContextShift[F]): F[ConcurrentQueue[F, A]] = withConfig(Unbounded(chunkSizeHint), MPMC) /** @@ -458,8 +454,10 @@ object ConcurrentQueue { */ @UnsafeProtocol def withConfig[F[_], A](capacity: BufferCapacity, channelType: ChannelType)( - implicit F: Concurrent[F], - cs: ContextShift[F]): F[ConcurrentQueue[F, A]] = { + implicit + F: Concurrent[F], + cs: ContextShift[F] + ): F[ConcurrentQueue[F, A]] = { F.delay(unsafe(capacity, channelType)) } @@ -485,8 +483,10 @@ object ConcurrentQueue { @UnsafeProtocol @UnsafeBecauseImpure def unsafe[F[_], A](capacity: BufferCapacity, channelType: ChannelType = MPMC)( - implicit F: Concurrent[F], - cs: ContextShift[F]): ConcurrentQueue[F, A] = { + implicit + F: Concurrent[F], + cs: ContextShift[F] + ): ConcurrentQueue[F, A] = { new ConcurrentQueue[F, A](capacity, channelType)(F, cs) } @@ -511,14 +511,16 @@ object ConcurrentQueue { * @see documentation for [[ConcurrentQueue.withConfig]] */ def withConfig[A](capacity: BufferCapacity, channelType: ChannelType = MPMC)( - implicit cs: ContextShift[F]): F[ConcurrentQueue[F, A]] = + implicit cs: ContextShift[F] + ): F[ConcurrentQueue[F, A]] = ConcurrentQueue.withConfig(capacity, channelType)(F, cs) /** * @see documentation for [[ConcurrentQueue.unsafe]] */ def unsafe[A](capacity: BufferCapacity, channelType: ChannelType = MPMC)( - implicit cs: ContextShift[F]): ConcurrentQueue[F, A] = + implicit cs: ContextShift[F] + ): ConcurrentQueue[F, A] = ConcurrentQueue.unsafe(capacity, channelType)(F, cs) } } diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/ConsumerF.scala b/monix-catnap/shared/src/main/scala/monix/catnap/ConsumerF.scala index b0e6021fe..539524a9b 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/ConsumerF.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/ConsumerF.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,7 +16,7 @@ */ package monix.catnap -import monix.execution.{BufferCapacity, ChannelType} +import monix.execution.{ BufferCapacity, ChannelType } import monix.execution.atomic.PaddingStrategy /** diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/FutureLift.scala b/monix-catnap/shared/src/main/scala/monix/catnap/FutureLift.scala index 8fdfa8357..226947473 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/FutureLift.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/FutureLift.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,11 +18,11 @@ package monix.catnap import cats.~> -import cats.effect.{Async, Concurrent} +import cats.effect.{ Async, Concurrent } import monix.execution.CancelableFuture import monix.execution.internal.AttemptCallback import monix.execution.schedulers.TrampolineExecutionContext.immediate -import scala.concurrent.{Future => ScalaFuture} +import scala.concurrent.{ Future => ScalaFuture } /** * A type class for conversions from [[scala.concurrent.Future]] or @@ -145,7 +145,8 @@ object FutureLift extends internal.FutureLiftForPlatform { * if the given `Future` is such an instance. */ def scalaToConcurrentOrAsync[F[_], MF[T] <: ScalaFuture[T], A](fa: F[MF[A]])( - implicit F: Concurrent[F] OrElse Async[F]): F[A] = { + implicit F: OrElse[Concurrent[F], Async[F]] + ): F[A] = { F.unify match { case ref: Concurrent[F] @unchecked => @@ -161,7 +162,8 @@ object FutureLift extends internal.FutureLiftForPlatform { * any `Concurrent` or `Async` data type. */ implicit def scalaFutureLiftForConcurrentOrAsync[F[_], MF[T] <: ScalaFuture[T]]( - implicit F: Concurrent[F] OrElse Async[F]): FutureLift[F, MF] = { + implicit F: OrElse[Concurrent[F], Async[F]] + ): FutureLift[F, MF] = { F.unify match { case ref: Concurrent[F] @unchecked => diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/MVar.scala b/monix-catnap/shared/src/main/scala/monix/catnap/MVar.scala index 93e578720..886a31e5c 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/MVar.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/MVar.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,8 +17,8 @@ package monix.catnap -import cats.effect.concurrent.{Ref, MVar2 => CatsMVar} -import cats.effect.{Async, Concurrent, ContextShift} +import cats.effect.concurrent.{ MVar2 => CatsMVar, Ref } +import cats.effect.{ Async, Concurrent, ContextShift } import monix.catnap.internal.AsyncUtils import monix.execution.atomic.PaddingStrategy import monix.execution.atomic.PaddingStrategy.NoPadding @@ -200,15 +200,17 @@ object MVar { * * @see [[of]] and [[empty]] */ - def apply[F[_]](implicit F: Concurrent[F] OrElse Async[F]): ApplyBuilders[F] = + def apply[F[_]](implicit F: OrElse[Concurrent[F], Async[F]]): ApplyBuilders[F] = new ApplyBuilders[F](F) /** * Builds an [[MVar]] instance with an `initial` value. */ def of[F[_], A](initial: A, ps: PaddingStrategy = NoPadding)( - implicit F: Concurrent[F] OrElse Async[F], - cs: ContextShift[F]): F[MVar[F, A]] = { + implicit + F: OrElse[Concurrent[F], Async[F]], + cs: ContextShift[F] + ): F[MVar[F, A]] = { F.fold( implicit F => F.delay(new MVar(new ConcurrentImpl(Some(initial), ps))), @@ -220,7 +222,8 @@ object MVar { * Builds an empty [[MVar]] instance. */ def empty[F[_], A]( - ps: PaddingStrategy = NoPadding)(implicit F: Concurrent[F] OrElse Async[F], cs: ContextShift[F]): F[MVar[F, A]] = { + ps: PaddingStrategy = NoPadding + )(implicit F: OrElse[Concurrent[F], Async[F]], cs: ContextShift[F]): F[MVar[F, A]] = { F.fold( implicit F => F.delay(new MVar(new ConcurrentImpl(None, ps))), @@ -231,7 +234,7 @@ object MVar { /** * Returned by the [[apply]] builder. */ - final class ApplyBuilders[F[_]](val F: Concurrent[F] OrElse Async[F]) extends AnyVal { + final class ApplyBuilders[F[_]](val F: OrElse[Concurrent[F], Async[F]]) extends AnyVal { /** * Builds an `MVar` with an initial value. * @@ -305,21 +308,22 @@ object MVar { unsafeRead(cb) } - private[this] val bindFork: (Unit => F[Unit]) = { + private val bindFork: (Unit => F[Unit]) = { val shift = cs.shift _ => shift } - private[this] val bindForkA: (Any => F[Any]) = { + private val bindForkA: (Any => F[Any]) = { val shift = cs.shift x => F.map(shift)(_ => x) } } private final class AsyncImpl[F[_], A](initial: Option[A], ps: PaddingStrategy)( - implicit val F: Async[F], - val cs: ContextShift[F]) - extends GenericVar[A, F[Unit]](initial, ps) with Impl[F, A] { + implicit + val F: Async[F], + val cs: ContextShift[F] + ) extends GenericVar[A, F[Unit]](initial, ps) with Impl[F, A] { protected def create[T](k: (Either[Throwable, T] => Unit) => F[Unit]): F[T] = AsyncUtils.cancelable(k) @@ -330,9 +334,10 @@ object MVar { } private final class ConcurrentImpl[F[_], A](initial: Option[A], ps: PaddingStrategy)( - implicit val F: Concurrent[F], - val cs: ContextShift[F]) - extends GenericVar[A, F[Unit]](initial, ps) with Impl[F, A] { + implicit + val F: Concurrent[F], + val cs: ContextShift[F] + ) extends GenericVar[A, F[Unit]](initial, ps) with Impl[F, A] { protected def create[T](k: (Either[Throwable, T] => Unit) => F[Unit]): F[T] = F.cancelable(k) @@ -343,7 +348,7 @@ object MVar { override def swap(newValue: A): F[A] = F.continual(take) { - case Left(t) => F.raiseError(t) + case Left(t) => F.raiseError(t) case Right(oldValue) => F.as(put(newValue), oldValue) } @@ -353,18 +358,18 @@ object MVar { override def modify[B](f: A => F[(A, B)]): F[B] = F.bracket(Ref[F].of[Option[A]](None)) { signal => F.flatMap(F.continual[A, A](take) { - case Left(t) => F.raiseError(t) + case Left(t) => F.raiseError(t) case Right(a) => F.as(signal.set(Some(a)), a) }) { a => F.continual[(A, B), B](f(a)) { - case Left(t) => F.raiseError(t) + case Left(t) => F.raiseError(t) case Right((newA, b)) => F.as(signal.set(Some(newA)), b) } } } { signal => F.flatMap(signal.get) { case Some(a) => put(a) - case None => F.unit + case None => F.unit } } diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/OrElse.scala b/monix-catnap/shared/src/main/scala/monix/catnap/OrElse.scala index c0d3debee..44e1256c4 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/OrElse.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/OrElse.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,12 +33,12 @@ sealed trait OrElse[+A, +B] { } object OrElse extends OrElse0 { - implicit def primary[A, B](implicit a: A): A OrElse B = + implicit def primary[A, B](implicit a: A): OrElse[A, B] = new Primary(a) } private[catnap] abstract class OrElse0 { - implicit def secondary[A, B](implicit b: B): A OrElse B = + implicit def secondary[A, B](implicit b: B): OrElse[A, B] = new Secondary(b) final class Primary[+A](value: A) extends OrElse[A, Nothing] { diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/ProducerF.scala b/monix-catnap/shared/src/main/scala/monix/catnap/ProducerF.scala index c6a0cb759..25cfe3d9d 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/ProducerF.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/ProducerF.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/SchedulerEffect.scala b/monix-catnap/shared/src/main/scala/monix/catnap/SchedulerEffect.scala index c24f2800d..b424b8323 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/SchedulerEffect.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/SchedulerEffect.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ import monix.execution.Scheduler import monix.execution.internal.AttemptCallback.RunnableTick import scala.concurrent.ExecutionContext -import scala.concurrent.duration.{FiniteDuration, TimeUnit} +import scala.concurrent.duration.{ FiniteDuration, TimeUnit } object SchedulerEffect { diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/Semaphore.scala b/monix-catnap/shared/src/main/scala/monix/catnap/Semaphore.scala index 1ec2ac721..07a12c1f8 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/Semaphore.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/Semaphore.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,10 +17,10 @@ package monix.catnap -import cats.effect.{Async, CancelToken, Concurrent, ContextShift} +import cats.effect.{ Async, CancelToken, Concurrent, ContextShift } import monix.catnap.internal.AsyncUtils import monix.execution.Callback -import monix.execution.annotations.{UnsafeBecauseImpure, UnsafeProtocol} +import monix.execution.annotations.{ UnsafeBecauseImpure, UnsafeProtocol } import monix.execution.atomic.PaddingStrategy import monix.execution.atomic.PaddingStrategy.NoPadding import monix.execution.internal.GenericSemaphore @@ -67,11 +67,12 @@ import scala.concurrent.Promise * from FS2. */ final class Semaphore[F[_]] private (provisioned: Long, ps: PaddingStrategy)( - implicit F: Concurrent[F] OrElse Async[F], - cs: ContextShift[F]) - extends cats.effect.concurrent.Semaphore[F] { + implicit + F: OrElse[Concurrent[F], Async[F]], + cs: ContextShift[F] +) extends cats.effect.concurrent.Semaphore[F] { - private[this] implicit val F0: Async[F] = F.unify + private val F0: Async[F] = F.unify /** Returns the number of permits currently available. Always non-negative. * @@ -211,8 +212,7 @@ final class Semaphore[F[_]] private (provisioned: Long, ps: PaddingStrategy)( def awaitAvailable(n: Long): F[Unit] = underlying.awaitAvailable(n) - private[this] val underlying = - new Semaphore.Impl[F](provisioned, ps) + private val underlying = new Semaphore.Impl[F](provisioned, ps)(F, F0, cs) } object Semaphore { @@ -232,8 +232,10 @@ object Semaphore { * async boundaries after successful `acquire` operations, for safety */ def apply[F[_]](provisioned: Long, ps: PaddingStrategy = NoPadding)( - implicit F: Concurrent[F] OrElse Async[F], - cs: ContextShift[F]): F[Semaphore[F]] = { + implicit + F: OrElse[Concurrent[F], Async[F]], + cs: ContextShift[F] + ): F[Semaphore[F]] = { F.unify.delay(new Semaphore[F](provisioned, ps)) } @@ -257,8 +259,10 @@ object Semaphore { */ @UnsafeBecauseImpure def unsafe[F[_]](provisioned: Long, ps: PaddingStrategy = NoPadding)( - implicit F: Concurrent[F] OrElse Async[F], - cs: ContextShift[F]): Semaphore[F] = + implicit + F: OrElse[Concurrent[F], Async[F]], + cs: ContextShift[F] + ): Semaphore[F] = new Semaphore[F](provisioned, ps) implicit final class DeprecatedExtensions[F[_]](val source: Semaphore[F]) extends AnyVal { @@ -274,10 +278,11 @@ object Semaphore { } private final class Impl[F[_]](provisioned: Long, ps: PaddingStrategy)( - implicit F: Concurrent[F] OrElse Async[F], + implicit + F: OrElse[Concurrent[F], Async[F]], F0: Async[F], - cs: ContextShift[F]) - extends GenericSemaphore[F[Unit]](provisioned, ps) { + cs: ContextShift[F] + ) extends GenericSemaphore[F[Unit]](provisioned, ps) { val available: F[Long] = F0.delay(unsafeAvailable()) val count: F[Long] = F0.delay(unsafeCount()) @@ -325,7 +330,6 @@ object Semaphore { F => AsyncUtils.cancelable(k)(F) ) - private[this] val bindFork: (Unit => F[Unit]) = - _ => cs.shift + private val bindFork: (Unit => F[Unit]) = _ => cs.shift } } diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/cancelables/AssignableCancelableF.scala b/monix-catnap/shared/src/main/scala/monix/catnap/cancelables/AssignableCancelableF.scala index 257bea47a..bf57f65c8 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/cancelables/AssignableCancelableF.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/cancelables/AssignableCancelableF.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -62,7 +62,7 @@ object AssignableCancelableF { /** * Builds an [[AssignableCancelableF]] instance that's already canceled. */ - def alreadyCanceled[F[_]](implicit F: Applicative[F]): Bool[F] with Empty[F] = + def alreadyCanceled[F[_]](implicit F: Applicative[F]): Bool[F] = new Bool[F] with Empty[F] { def set(ref: CancelableF[F]): F[Unit] = ref.cancel def isCanceled: F[Boolean] = F.pure(true) diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/cancelables/BooleanCancelableF.scala b/monix-catnap/shared/src/main/scala/monix/catnap/cancelables/BooleanCancelableF.scala index 507425fd0..27ebaea52 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/cancelables/BooleanCancelableF.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/cancelables/BooleanCancelableF.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.catnap package cancelables import cats.Applicative -import cats.effect.{CancelToken, Sync} +import cats.effect.{ CancelToken, Sync } import monix.catnap.CancelableF import monix.catnap.CancelableF.Empty import monix.execution.annotations.UnsafeBecauseImpure @@ -71,7 +71,7 @@ object BooleanCancelableF { * Returns an instance of a [[BooleanCancelableF]] that's * already canceled. */ - def alreadyCanceled[F[_]](implicit F: Applicative[F]): BooleanCancelableF[F] with Empty[F] = + def alreadyCanceled[F[_]](implicit F: Applicative[F]): BooleanCancelableF[F] = new BooleanCancelableF[F] with Empty[F] { val isCanceled = F.pure(true) def cancel = F.unit @@ -91,8 +91,8 @@ object BooleanCancelableF { private final class Impl[F[_]](token: CancelToken[F])(implicit F: Sync[F]) extends BooleanCancelableF[F] { - private[this] val canceled = Atomic(false) - private[this] var ref = token + private val canceled = Atomic(false) + private var ref = token def isCanceled = F.delay(canceled.get()) diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/cancelables/SingleAssignCancelableF.scala b/monix-catnap/shared/src/main/scala/monix/catnap/cancelables/SingleAssignCancelableF.scala index 3a37140ef..727e971a9 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/cancelables/SingleAssignCancelableF.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/cancelables/SingleAssignCancelableF.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.catnap.cancelables -import cats.effect.{CancelToken, Sync} +import cats.effect.{ CancelToken, Sync } import monix.catnap.CancelableF import monix.execution.annotations.UnsafeBecauseImpure import monix.execution.atomic.Atomic @@ -36,7 +36,7 @@ final class SingleAssignCancelableF[F[_]] private (extra: CancelableF[F])(implic extends AssignableCancelableF.Bool[F] { import SingleAssignCancelableF._ - private[this] val state = Atomic(Empty: State[F]) + private val state = Atomic(Empty: State[F]) val isCanceled: F[Boolean] = F.delay(state.get() match { @@ -87,7 +87,8 @@ final class SingleAssignCancelableF[F[_]] private (extra: CancelableF[F])(implic private def raiseError: F[Unit] = F.raiseError { new IllegalStateException( "Cannot assign to SingleAssignmentCancelableF " + - "as it was already assigned once") + "as it was already assigned once" + ) } } diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/internal/AsyncUtils.scala b/monix-catnap/shared/src/main/scala/monix/catnap/internal/AsyncUtils.scala index 2d07cdf58..d6f38a6b5 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/internal/AsyncUtils.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/internal/AsyncUtils.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.catnap.internal import cats.implicits._ -import cats.effect.{Async, ExitCase} +import cats.effect.{ Async, ExitCase } import monix.catnap.FutureLift import monix.execution.Callback import scala.concurrent.Promise diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/internal/ParallelApplicative.scala b/monix-catnap/shared/src/main/scala/monix/catnap/internal/ParallelApplicative.scala index c44328443..178ed57e0 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/internal/ParallelApplicative.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/internal/ParallelApplicative.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.catnap.internal -import cats.{CommutativeApplicative, Parallel} +import cats.{ CommutativeApplicative, Parallel } /** Given a `cats.Parallel` instance for a type `F[_]`, builds * a parallel `cats.CommutativeApplicative[F]` out of it. diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/internal/QueueHelpers.scala b/monix-catnap/shared/src/main/scala/monix/catnap/internal/QueueHelpers.scala index aa5b9e317..ced0de153 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/internal/QueueHelpers.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/internal/QueueHelpers.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.catnap package internal -import cats.effect.{Concurrent, ContextShift} +import cats.effect.{ Concurrent, ContextShift } import monix.execution.CancelablePromise import monix.execution.atomic.AtomicAny import monix.execution.internal.Constants @@ -26,7 +26,7 @@ import scala.annotation.tailrec private[catnap] class QueueHelpers[F[_]](implicit F: Concurrent[F], cs: ContextShift[F]) { - private[this] val asyncBoundary: F[Unit] = cs.shift + private val asyncBoundary: F[Unit] = cs.shift @tailrec final def sleepThenRepeat[T, U]( @@ -34,7 +34,8 @@ private[catnap] class QueueHelpers[F[_]](implicit F: Concurrent[F], cs: ContextS f: () => T, filter: T => Boolean, map: T => U, - cb: Either[Throwable, U] => Unit)(implicit F: Concurrent[F]): F[Unit] = { + cb: Either[Throwable, U] => Unit + )(implicit F: Concurrent[F]): F[Unit] = { // Registering intention to sleep via promise state.get() match { @@ -55,7 +56,8 @@ private[catnap] class QueueHelpers[F[_]](implicit F: Concurrent[F], cs: ContextS f: () => T, filter: T => Boolean, map: T => U, - cb: Either[Throwable, U] => Unit)(p: CancelablePromise[Unit])(implicit F: Concurrent[F]): F[Unit] = { + cb: Either[Throwable, U] => Unit + )(p: CancelablePromise[Unit])(implicit F: Concurrent[F]): F[Unit] = { // Async boundary, for fairness reasons; also creates a full // memory barrier between the promise registration and what follows @@ -77,7 +79,8 @@ private[catnap] class QueueHelpers[F[_]](implicit F: Concurrent[F], cs: ContextS f: () => T, filter: T => Boolean, map: T => U, - cb: Either[Throwable, U] => Unit)(implicit F: Concurrent[F]): F[Unit] = { + cb: Either[Throwable, U] => Unit + )(implicit F: Concurrent[F]): F[Unit] = { // Trying to read val value = f() diff --git a/monix-catnap/shared/src/main/scala/monix/catnap/syntax.scala b/monix-catnap/shared/src/main/scala/monix/catnap/syntax.scala index 2b095894c..c582b1631 100644 --- a/monix-catnap/shared/src/main/scala/monix/catnap/syntax.scala +++ b/monix-catnap/shared/src/main/scala/monix/catnap/syntax.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-catnap/shared/src/main/scala/monix/execution/CancelableFutureCatsInstances.scala b/monix-catnap/shared/src/main/scala/monix/execution/CancelableFutureCatsInstances.scala index d743db18f..f423d2be5 100644 --- a/monix-catnap/shared/src/main/scala/monix/execution/CancelableFutureCatsInstances.scala +++ b/monix-catnap/shared/src/main/scala/monix/execution/CancelableFutureCatsInstances.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,11 +16,11 @@ */ package monix.execution -import cats.{CoflatMap, Eval, Monad, MonadError, StackSafeMonad} +import cats.{ CoflatMap, Eval, Monad, MonadError, StackSafeMonad } import monix.execution.CancelableFuture.Pure -import scala.concurrent.{ExecutionContext, Future} -import scala.util.{Failure, Success, Try} +import scala.concurrent.{ ExecutionContext, Future } +import scala.util.{ Failure, Success, Try } /** Implementation of Cats type classes for the * [[CancelableFuture]] data type. @@ -55,7 +55,8 @@ final class CancelableFutureCatsInstances(implicit ec: ExecutionContext) override def recover[A](fa: CancelableFuture[A])(pf: PartialFunction[Throwable, A]): CancelableFuture[A] = fa.recover(pf) override def recoverWith[A](fa: CancelableFuture[A])( - pf: PartialFunction[Throwable, CancelableFuture[A]]): CancelableFuture[A] = + pf: PartialFunction[Throwable, CancelableFuture[A]] + ): CancelableFuture[A] = fa.recoverWith(pf) override def catchNonFatal[A](a: => A)(implicit ev: Throwable <:< Throwable): CancelableFuture[A] = CancelableFuture(Future(a), Cancelable.empty) diff --git a/monix-catnap/shared/src/main/scala/monix/execution/package.scala b/monix-catnap/shared/src/main/scala/monix/execution/package.scala index b14e56e5e..c6fb86073 100644 --- a/monix-catnap/shared/src/main/scala/monix/execution/package.scala +++ b/monix-catnap/shared/src/main/scala/monix/execution/package.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -40,9 +40,8 @@ package object execution { implicit def contravariantCallback[E]: Contravariant[Callback[E, *]] = contravariantRef.asInstanceOf[Contravariant[Callback[E, *]]] - private[this] val contravariantRef: Contravariant[Callback[Any, *]] = - new Contravariant[Callback[Any, *]] { - override def contramap[A, B](cb: Callback[Any, A])(f: B => A): Callback[Any, B] = - cb.contramap(f) - } + private val contravariantRef: Contravariant[Callback[Any, *]] = new Contravariant[Callback[Any, *]] { + override def contramap[A, B](cb: Callback[Any, A])(f: B => A): Callback[Any, B] = + cb.contramap(f) + } } diff --git a/monix-catnap/shared/src/test/scala/monix/catnap/CancelableFSuite.scala b/monix-catnap/shared/src/test/scala/monix/catnap/CancelableFSuite.scala index 388c030ab..59eae881d 100644 --- a/monix-catnap/shared/src/test/scala/monix/catnap/CancelableFSuite.scala +++ b/monix-catnap/shared/src/test/scala/monix/catnap/CancelableFSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,10 +16,12 @@ */ package monix.catnap +import scala.annotation.nowarn import cats.effect.IO import minitest.SimpleTestSuite +@nowarn object CancelableFSuite extends SimpleTestSuite { test("apply") { var effect = 0 @@ -59,7 +61,7 @@ object CancelableFSuite extends SimpleTestSuite { test("cancel multiple cancelables") { var effect = 0 val seq = (0 until 100).map(_ => CancelableF.unsafeApply(IO { effect += 1 })) - val col = CancelableF.collection(seq: _*) + val col = CancelableF.collection(seq*) assertEquals(effect, 0) col.cancel.unsafeRunSync() @@ -69,7 +71,7 @@ object CancelableFSuite extends SimpleTestSuite { test("cancel multiple tokens") { var effect = 0 val seq = (0 until 100).map(_ => IO { effect += 1 }) - val cancel = CancelableF.cancelAllTokens(seq: _*) + val cancel = CancelableF.cancelAllTokens(seq*) assertEquals(effect, 0) cancel.unsafeRunSync() diff --git a/monix-catnap/shared/src/test/scala/monix/catnap/CircuitBreakerSuite.scala b/monix-catnap/shared/src/test/scala/monix/catnap/CircuitBreakerSuite.scala index 538a57e3a..64dff22b6 100644 --- a/monix-catnap/shared/src/test/scala/monix/catnap/CircuitBreakerSuite.scala +++ b/monix-catnap/shared/src/test/scala/monix/catnap/CircuitBreakerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,17 +16,19 @@ */ package monix.catnap +import scala.annotation.nowarn import cats.effect._ import cats.implicits._ import minitest.TestSuite -import monix.catnap.CircuitBreaker.{Closed, Open} -import monix.execution.exceptions.{DummyException, ExecutionRejectedException} +import monix.catnap.CircuitBreaker.{ Closed, Open } +import monix.execution.exceptions.{ DummyException, ExecutionRejectedException } import monix.execution.schedulers.TestScheduler import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object CircuitBreakerSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() def tearDown(env: TestScheduler): Unit = diff --git a/monix-catnap/shared/src/test/scala/monix/catnap/ConcurrentChannelSuite.scala b/monix-catnap/shared/src/test/scala/monix/catnap/ConcurrentChannelSuite.scala index 6fb3fb749..d86347b28 100644 --- a/monix-catnap/shared/src/test/scala/monix/catnap/ConcurrentChannelSuite.scala +++ b/monix-catnap/shared/src/test/scala/monix/catnap/ConcurrentChannelSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,20 +16,22 @@ */ package monix.catnap +import scala.annotation.nowarn -import cats.effect.{ContextShift, IO, Timer} +import cats.effect.{ ContextShift, IO, Timer } import cats.implicits._ import minitest.TestSuite -import monix.execution.BufferCapacity.{Bounded, Unbounded} -import monix.execution.ChannelType.{MPMC, MPSC, SPMC, SPSC} +import monix.execution.BufferCapacity.{ Bounded, Unbounded } +import monix.execution.ChannelType.{ MPMC, MPSC, SPMC, SPSC } import monix.execution.exceptions.APIContractViolationException import monix.execution.internal.Platform import monix.execution.schedulers.TestScheduler -import monix.execution.{BufferCapacity, Scheduler, TestUtils} +import monix.execution.{ BufferCapacity, Scheduler, TestUtils } import scala.concurrent.TimeoutException import scala.concurrent.duration._ +@nowarn object ConcurrentChannelFakeSuite extends BaseConcurrentChannelSuite[TestScheduler] { def setup() = TestScheduler() def tearDown(env: TestScheduler): Unit = @@ -395,7 +397,8 @@ abstract class BaseConcurrentChannelSuite[S <: Scheduler] extends TestSuite[S] w } testIO( - s"concurrent sum via consumer.pull; MPMC; producers=4, consumers=4, workers=4, capacity=$boundedConfigForConcurrentSum") { + s"concurrent sum via consumer.pull; MPMC; producers=4, consumers=4, workers=4, capacity=$boundedConfigForConcurrentSum" + ) { implicit ec => testConcurrentSum( producers = 4, @@ -420,7 +423,8 @@ abstract class BaseConcurrentChannelSuite[S <: Scheduler] extends TestSuite[S] w } testIO( - s"concurrent sum via consumer.pull; SPMC; producers=1, consumers=4, workers=4, capacity=$boundedConfigForConcurrentSum") { + s"concurrent sum via consumer.pull; SPMC; producers=1, consumers=4, workers=4, capacity=$boundedConfigForConcurrentSum" + ) { implicit ec => testConcurrentSum( producers = 1, @@ -445,7 +449,8 @@ abstract class BaseConcurrentChannelSuite[S <: Scheduler] extends TestSuite[S] w } testIO( - s"concurrent sum via consumer.pull; MPMC; producers=4, consumers=1, workers=4, capacity=$boundedConfigForConcurrentSum") { + s"concurrent sum via consumer.pull; MPMC; producers=4, consumers=1, workers=4, capacity=$boundedConfigForConcurrentSum" + ) { implicit ec => testConcurrentSum( producers = 4, @@ -470,7 +475,8 @@ abstract class BaseConcurrentChannelSuite[S <: Scheduler] extends TestSuite[S] w } testIO( - s"concurrent sum via consumer.pull; MPSC; producers=4, consumers=4, workers=1, capacity=$boundedConfigForConcurrentSum") { + s"concurrent sum via consumer.pull; MPSC; producers=4, consumers=4, workers=1, capacity=$boundedConfigForConcurrentSum" + ) { implicit ec => testConcurrentSum( producers = 4, @@ -495,7 +501,8 @@ abstract class BaseConcurrentChannelSuite[S <: Scheduler] extends TestSuite[S] w } testIO( - s"concurrent sum via consumer.pull; SPSC; producers=1, consumers=1, workers=1, capacity=$boundedConfigForConcurrentSum") { + s"concurrent sum via consumer.pull; SPSC; producers=1, consumers=1, workers=1, capacity=$boundedConfigForConcurrentSum" + ) { implicit ec => testConcurrentSum( producers = 1, @@ -520,7 +527,8 @@ abstract class BaseConcurrentChannelSuite[S <: Scheduler] extends TestSuite[S] w } testIO( - s"concurrent sum via consumer.pullMany; MPMC; producers=4, consumers=4, workers=4, capacity=$boundedConfigForConcurrentSum") { + s"concurrent sum via consumer.pullMany; MPMC; producers=4, consumers=4, workers=4, capacity=$boundedConfigForConcurrentSum" + ) { implicit ec => testConcurrentSum( producers = 4, @@ -545,7 +553,8 @@ abstract class BaseConcurrentChannelSuite[S <: Scheduler] extends TestSuite[S] w } testIO( - s"concurrent sum via consumer.pullMany; SPMC; producers=1, consumers=4, workers=4, capacity=$boundedConfigForConcurrentSum") { + s"concurrent sum via consumer.pullMany; SPMC; producers=1, consumers=4, workers=4, capacity=$boundedConfigForConcurrentSum" + ) { implicit ec => testConcurrentSum( producers = 1, @@ -570,7 +579,8 @@ abstract class BaseConcurrentChannelSuite[S <: Scheduler] extends TestSuite[S] w } testIO( - s"concurrent sum via consumer.pullMany; MPMC; producers=4, consumers=1, workers=4, capacity=$boundedConfigForConcurrentSum") { + s"concurrent sum via consumer.pullMany; MPMC; producers=4, consumers=1, workers=4, capacity=$boundedConfigForConcurrentSum" + ) { implicit ec => testConcurrentSum( producers = 4, @@ -595,7 +605,8 @@ abstract class BaseConcurrentChannelSuite[S <: Scheduler] extends TestSuite[S] w } testIO( - s"concurrent sum via consumer.pullMany; MPSC; producers=4, consumers=4, workers=1, capacity=$boundedConfigForConcurrentSum") { + s"concurrent sum via consumer.pullMany; MPSC; producers=4, consumers=4, workers=1, capacity=$boundedConfigForConcurrentSum" + ) { implicit ec => testConcurrentSum( producers = 4, @@ -620,7 +631,8 @@ abstract class BaseConcurrentChannelSuite[S <: Scheduler] extends TestSuite[S] w } testIO( - s"concurrent sum via consumer.pullMany; SPSC; producers=1, consumers=1, workers=1, capacity=$boundedConfigForConcurrentSum") { + s"concurrent sum via consumer.pullMany; SPSC; producers=1, consumers=1, workers=1, capacity=$boundedConfigForConcurrentSum" + ) { implicit ec => testConcurrentSum( producers = 1, @@ -650,7 +662,8 @@ abstract class BaseConcurrentChannelSuite[S <: Scheduler] extends TestSuite[S] w workersPerConsumer: Int, capacity: BufferCapacity, count: Int, - pullMany: Boolean)(implicit ec: Scheduler): IO[Unit] = { + pullMany: Boolean + )(implicit ec: Scheduler): IO[Unit] = { val channelType = if (producers > 1) { diff --git a/monix-catnap/shared/src/test/scala/monix/catnap/ConcurrentQueueSuite.scala b/monix-catnap/shared/src/test/scala/monix/catnap/ConcurrentQueueSuite.scala index 9822a110b..941a53dd6 100644 --- a/monix-catnap/shared/src/test/scala/monix/catnap/ConcurrentQueueSuite.scala +++ b/monix-catnap/shared/src/test/scala/monix/catnap/ConcurrentQueueSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,15 +16,16 @@ */ package monix.catnap +import scala.annotation.nowarn import java.util.concurrent.atomic.AtomicLong -import cats.effect.{ContextShift, IO, Timer} +import cats.effect.{ ContextShift, IO, Timer } import cats.implicits._ import minitest.TestSuite -import monix.execution.BufferCapacity.{Bounded, Unbounded} -import monix.execution.ChannelType.{MPMC, MPSC, SPMC, SPSC} -import monix.execution.{BufferCapacity, ChannelType, Scheduler} +import monix.execution.BufferCapacity.{ Bounded, Unbounded } +import monix.execution.ChannelType.{ MPMC, MPSC, SPMC, SPSC } +import monix.execution.{ BufferCapacity, ChannelType, Scheduler } import monix.execution.internal.Platform import monix.execution.schedulers.TestScheduler @@ -32,6 +33,7 @@ import scala.collection.immutable.Queue import scala.concurrent.TimeoutException import scala.concurrent.duration._ +@nowarn object ConcurrentQueueFakeSuite extends BaseConcurrentQueueSuite[TestScheduler] { def setup() = TestScheduler() @@ -128,7 +130,7 @@ abstract class BaseConcurrentQueueSuite[S <: Scheduler] extends TestSuite[S] { if (n > 0) queue.poll.flatMap { a => consumer(n - 1, acc.enqueue(a)) - } + } else IO.pure(acc.foldLeft(0L)(_ + _)) diff --git a/monix-catnap/shared/src/test/scala/monix/catnap/FutureLiftSuite.scala b/monix-catnap/shared/src/test/scala/monix/catnap/FutureLiftSuite.scala index b0be56c47..46d1cffbe 100644 --- a/monix-catnap/shared/src/test/scala/monix/catnap/FutureLiftSuite.scala +++ b/monix-catnap/shared/src/test/scala/monix/catnap/FutureLiftSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,16 +16,18 @@ */ package monix.catnap +import scala.annotation.nowarn -import cats.effect.{Async, ContextShift, IO} +import cats.effect.{ Async, ContextShift, IO } import minitest.TestSuite import monix.catnap.syntax._ import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler -import monix.execution.{Cancelable, CancelableFuture} -import scala.concurrent.{Future, Promise} -import scala.util.{Failure, Success} +import monix.execution.{ Cancelable, CancelableFuture } +import scala.concurrent.{ Future, Promise } +import scala.util.{ Failure, Success } +@nowarn object FutureLiftSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() def tearDown(env: TestScheduler): Unit = @@ -106,9 +108,12 @@ object FutureLiftSuite extends TestSuite[TestScheduler] { test("F.delay(future).futureLift for Concurrent[F] data types") { implicit s => var wasCanceled = 0 - val io = IO(CancelableFuture[Int](CancelableFuture.never, Cancelable { () => - wasCanceled += 1 - })).futureLift + val io = IO(CancelableFuture[Int]( + CancelableFuture.never, + Cancelable { () => + wasCanceled += 1 + } + )).futureLift val p = Promise[Int]() val token = io.unsafeRunCancelable { @@ -126,10 +131,14 @@ object FutureLiftSuite extends TestSuite[TestScheduler] { val source = Promise[Int]() val io = FutureLift[IO, CancelableFuture].apply( IO( - CancelableFuture[Int](source.future, Cancelable { () => - wasCanceled += 1 - }) - )) + CancelableFuture[Int]( + source.future, + Cancelable { () => + wasCanceled += 1 + } + ) + ) + ) val p = Promise[Int]() val token = io.unsafeRunCancelable { @@ -158,10 +167,14 @@ object FutureLiftSuite extends TestSuite[TestScheduler] { def mkInstance[F[_]](implicit F: Async[F]): F[Int] = FutureLift[F, CancelableFuture].apply( F.delay( - CancelableFuture[Int](source.future, Cancelable { () => - wasCanceled += 1 - }) - )) + CancelableFuture[Int]( + source.future, + Cancelable { () => + wasCanceled += 1 + } + ) + ) + ) val io = mkInstance[IO] val p = Promise[Int]() diff --git a/monix-catnap/shared/src/test/scala/monix/catnap/MVarConcurrentSuite.scala b/monix-catnap/shared/src/test/scala/monix/catnap/MVarConcurrentSuite.scala index e29881ec2..77f25edee 100644 --- a/monix-catnap/shared/src/test/scala/monix/catnap/MVarConcurrentSuite.scala +++ b/monix-catnap/shared/src/test/scala/monix/catnap/MVarConcurrentSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,9 +16,10 @@ */ package monix.catnap +import scala.annotation.nowarn -import cats.effect.concurrent.{Deferred, Ref} -import cats.effect.{ContextShift, IO, Timer} +import cats.effect.concurrent.{ Deferred, Ref } +import cats.effect.{ ContextShift, IO, Timer } import cats.implicits._ import minitest.SimpleTestSuite import monix.execution.Scheduler @@ -26,6 +27,7 @@ import monix.execution.internal.Platform import scala.concurrent.duration._ +@nowarn object MVarConcurrentSuite extends BaseMVarSuite { def init[A](a: A): IO[MVar[IO, A]] = MVar[IO](OrElse.primary(IO.ioConcurrentEffect)).of(a)(cs) @@ -35,11 +37,11 @@ object MVarConcurrentSuite extends BaseMVarSuite { testAsync("swap is cancelable on take") { val task = for { - mVar <- empty[Int] + mVar <- empty[Int] finished <- Deferred.uncancelable[IO, Int] - fiber <- mVar.swap(20).flatMap(finished.complete).start - _ <- fiber.cancel - _ <- mVar.put(10) + fiber <- mVar.swap(20).flatMap(finished.complete).start + _ <- fiber.cancel + _ <- mVar.put(10) fallback = IO.sleep(100.millis) *> mVar.take v <- IO.race(finished.get, fallback) } yield v @@ -51,11 +53,11 @@ object MVarConcurrentSuite extends BaseMVarSuite { testAsync("modify is cancelable on take") { val task = for { - mVar <- empty[Int] + mVar <- empty[Int] finished <- Deferred.uncancelable[IO, String] - fiber <- mVar.modify(n => IO.pure((n * 2, n.show))).flatMap(finished.complete).start - _ <- fiber.cancel - _ <- mVar.put(10) + fiber <- mVar.modify(n => IO.pure((n * 2, n.show))).flatMap(finished.complete).start + _ <- fiber.cancel + _ <- mVar.put(10) fallback = IO.sleep(100.millis) *> mVar.take v <- IO.race(finished.get, fallback) } yield v @@ -67,12 +69,12 @@ object MVarConcurrentSuite extends BaseMVarSuite { testAsync("modify is cancelable on f") { val task = for { - mVar <- empty[Int] + mVar <- empty[Int] finished <- Deferred.uncancelable[IO, String] - fiber <- mVar.modify(n => IO.never *> IO.pure((n * 2, n.show))).flatMap(finished.complete).start - _ <- mVar.put(10) - _ <- IO.sleep(10.millis) - _ <- fiber.cancel + fiber <- mVar.modify(n => IO.never *> IO.pure((n * 2, n.show))).flatMap(finished.complete).start + _ <- mVar.put(10) + _ <- IO.sleep(10.millis) + _ <- fiber.cancel fallback = IO.sleep(100.millis) *> mVar.take v <- IO.race(finished.get, fallback) } yield v @@ -92,13 +94,13 @@ object MVarAsyncSuite extends BaseMVarSuite { testAsync("put; take; modify; put") { val task = for { - mVar <- empty[Int] - _ <- mVar.put(10) - _ <- mVar.take + mVar <- empty[Int] + _ <- mVar.put(10) + _ <- mVar.take fiber <- mVar.modify(n => IO.pure((n * 2, n.toString))).start - _ <- mVar.put(20) - s <- fiber.join - v <- mVar.take + _ <- mVar.put(20) + s <- fiber.join + v <- mVar.take } yield (s, v) for (r <- task.unsafeToFuture()) yield { @@ -109,10 +111,10 @@ object MVarAsyncSuite extends BaseMVarSuite { testAsync("modify replaces the original value of the mvar on error") { val error = new Exception("Boom!") val task = for { - mVar <- empty[Int] - _ <- mVar.put(10) + mVar <- empty[Int] + _ <- mVar.put(10) finished <- Deferred.uncancelable[IO, String] - e <- mVar.modify(_ => IO.raiseError(error)).attempt + e <- mVar.modify(_ => IO.raiseError(error)).attempt fallback = IO.sleep(100.millis) *> mVar.take v <- IO.race(finished.get, fallback) } yield (e, v) diff --git a/monix-catnap/shared/src/test/scala/monix/catnap/Overrides.scala b/monix-catnap/shared/src/test/scala/monix/catnap/Overrides.scala index cc14ff873..d80b66fc3 100644 --- a/monix-catnap/shared/src/test/scala/monix/catnap/Overrides.scala +++ b/monix-catnap/shared/src/test/scala/monix/catnap/Overrides.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.catnap -import cats.effect.{Async, ExitCase, IO, Sync} +import cats.effect.{ Async, ExitCase, IO, Sync } object Overrides { diff --git a/monix-catnap/shared/src/test/scala/monix/catnap/ReferenceSchedulerEffectSuite.scala b/monix-catnap/shared/src/test/scala/monix/catnap/ReferenceSchedulerEffectSuite.scala index 7fd58f0dc..02b9b3ab9 100644 --- a/monix-catnap/shared/src/test/scala/monix/catnap/ReferenceSchedulerEffectSuite.scala +++ b/monix-catnap/shared/src/test/scala/monix/catnap/ReferenceSchedulerEffectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-catnap/shared/src/test/scala/monix/catnap/SemaphoreSuite.scala b/monix-catnap/shared/src/test/scala/monix/catnap/SemaphoreSuite.scala index b8105d442..850d66397 100644 --- a/monix-catnap/shared/src/test/scala/monix/catnap/SemaphoreSuite.scala +++ b/monix-catnap/shared/src/test/scala/monix/catnap/SemaphoreSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,15 +16,17 @@ */ package monix.catnap +import scala.annotation.nowarn -import cats.effect.{ContextShift, IO} +import cats.effect.{ ContextShift, IO } import cats.implicits._ import minitest.TestSuite import monix.execution.internal.Platform import monix.execution.schedulers.TestScheduler -import scala.concurrent.{ExecutionContext, Promise} -import scala.util.{Random, Success} +import scala.concurrent.{ ExecutionContext, Promise } +import scala.util.{ Random, Success } +@nowarn object SemaphoreSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() def tearDown(env: TestScheduler): Unit = diff --git a/monix-catnap/shared/src/test/scala/monix/catnap/TestSchedulerEffectSuite.scala b/monix-catnap/shared/src/test/scala/monix/catnap/TestSchedulerEffectSuite.scala index 3429d6441..b040e1b80 100644 --- a/monix-catnap/shared/src/test/scala/monix/catnap/TestSchedulerEffectSuite.scala +++ b/monix-catnap/shared/src/test/scala/monix/catnap/TestSchedulerEffectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,14 +16,16 @@ */ package monix.catnap +import scala.annotation.nowarn -import cats.effect.{ContextShift, IO} +import cats.effect.{ ContextShift, IO } import minitest.TestSuite import monix.execution.schedulers.TestScheduler import scala.concurrent.duration._ import scala.util.Success +@nowarn object TestSchedulerEffectSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() def tearDown(env: TestScheduler): Unit = { diff --git a/monix-catnap/shared/src/test/scala/monix/catnap/cancelables/AssignableCancelableFSuite.scala b/monix-catnap/shared/src/test/scala/monix/catnap/cancelables/AssignableCancelableFSuite.scala index e1501f1d1..0739f87fb 100644 --- a/monix-catnap/shared/src/test/scala/monix/catnap/cancelables/AssignableCancelableFSuite.scala +++ b/monix-catnap/shared/src/test/scala/monix/catnap/cancelables/AssignableCancelableFSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-catnap/shared/src/test/scala/monix/catnap/cancelables/BooleanCancelableFSuite.scala b/monix-catnap/shared/src/test/scala/monix/catnap/cancelables/BooleanCancelableFSuite.scala index 97e0caad5..6d8285d77 100644 --- a/monix-catnap/shared/src/test/scala/monix/catnap/cancelables/BooleanCancelableFSuite.scala +++ b/monix-catnap/shared/src/test/scala/monix/catnap/cancelables/BooleanCancelableFSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-catnap/shared/src/test/scala/monix/catnap/cancelables/SingleAssignCancelableFSuite.scala b/monix-catnap/shared/src/test/scala/monix/catnap/cancelables/SingleAssignCancelableFSuite.scala index 4b05ff48c..0155fff5a 100644 --- a/monix-catnap/shared/src/test/scala/monix/catnap/cancelables/SingleAssignCancelableFSuite.scala +++ b/monix-catnap/shared/src/test/scala/monix/catnap/cancelables/SingleAssignCancelableFSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,13 @@ package monix.catnap package cancelables +import scala.annotation.nowarn import cats.effect.IO import minitest.SimpleTestSuite -import monix.execution.exceptions.{CompositeException, DummyException} +import monix.execution.exceptions.{ CompositeException, DummyException } +@nowarn object SingleAssignCancelableFSuite extends SimpleTestSuite { test("cancel") { var effect = 0 diff --git a/monix-catnap/shared/src/test/scala/monix/execution/CallbackInstanceSuite.scala b/monix-catnap/shared/src/test/scala/monix/execution/CallbackInstanceSuite.scala index ed13f7f40..1a67d83c4 100644 --- a/monix-catnap/shared/src/test/scala/monix/execution/CallbackInstanceSuite.scala +++ b/monix-catnap/shared/src/test/scala/monix/execution/CallbackInstanceSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,7 +26,7 @@ object CallbackInstanceSuite extends TestSuite[TestScheduler] { def tearDown(env: TestScheduler): Unit = assert(env.state.tasks.isEmpty, "should not have tasks left to execute") - test("contramap has a cats Contramap instance") { implicit s => + test("contramap has a cats Contramap instance") { _ => val instance = implicitly[Contravariant[Callback[Throwable, *]]] val callback = TestCallback() val stringCallback = instance.contramap(callback)((x: String) => x.toInt) diff --git a/monix-catnap/shared/src/test/scala/monix/execution/TypeClassLawsForCancelableFutureSuite.scala b/monix-catnap/shared/src/test/scala/monix/execution/TypeClassLawsForCancelableFutureSuite.scala index a9a49c1f8..effe3366a 100644 --- a/monix-catnap/shared/src/test/scala/monix/execution/TypeClassLawsForCancelableFutureSuite.scala +++ b/monix-catnap/shared/src/test/scala/monix/execution/TypeClassLawsForCancelableFutureSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,12 +16,12 @@ */ package monix.execution -import cats.laws.discipline.{CoflatMapTests, MonadErrorTests} -import cats.{Eval, Monad, MonadError} +import cats.laws.discipline.{ CoflatMapTests, MonadErrorTests } +import cats.{ Eval, Monad, MonadError } import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object TypeClassLawsForCancelableFutureSuite extends BaseLawsSuite { checkAllAsync("CoflatMap[CancelableFuture]") { implicit ec => diff --git a/monix-eval/js/src/main/scala/monix/eval/internal/TaskRunSyncUnsafe.scala b/monix-eval/js/src/main/scala/monix/eval/internal/TaskRunSyncUnsafe.scala index 9f7e43a44..2027dafc2 100644 --- a/monix-eval/js/src/main/scala/monix/eval/internal/TaskRunSyncUnsafe.scala +++ b/monix-eval/js/src/main/scala/monix/eval/internal/TaskRunSyncUnsafe.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,12 +20,18 @@ package monix.eval.internal import monix.eval.Task import monix.execution.Scheduler import scala.concurrent.duration.Duration +import scala.annotation.unused private[eval] object TaskRunSyncUnsafe { /** Implementation of `Task.runSyncUnsafe`, meant to throw an * "unsupported exception", since JavaScript cannot support it. */ - def apply[A](source: Task[A], timeout: Duration, scheduler: Scheduler, opts: Task.Options): A = { + def apply[A]( + @unused source: Task[A], + @unused timeout: Duration, + @unused scheduler: Scheduler, + @unused opts: Task.Options + ): A = { // $COVERAGE-OFF$ throw new UnsupportedOperationException("runSyncUnsafe isn't supported on top of JavaScript") // $COVERAGE-ON$ diff --git a/monix-eval/js/src/main/scala/monix/eval/internal/TracingPlatform.scala b/monix-eval/js/src/main/scala/monix/eval/internal/TracingPlatform.scala index b69e351d9..c7da918ad 100644 --- a/monix-eval/js/src/main/scala/monix/eval/internal/TracingPlatform.scala +++ b/monix-eval/js/src/main/scala/monix/eval/internal/TracingPlatform.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/jvm/src/main/java/monix/eval/internal/TracingPlatform.java b/monix-eval/jvm/src/main/java/monix/eval/internal/TracingPlatform.java index 84b05b4c6..acd8c1e59 100644 --- a/monix-eval/jvm/src/main/java/monix/eval/internal/TracingPlatform.java +++ b/monix-eval/jvm/src/main/java/monix/eval/internal/TracingPlatform.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/jvm/src/main/scala/monix/eval/internal/TaskRunSyncUnsafe.scala b/monix-eval/jvm/src/main/scala/monix/eval/internal/TaskRunSyncUnsafe.scala index 1faba574f..a61085fe3 100644 --- a/monix-eval/jvm/src/main/scala/monix/eval/internal/TaskRunSyncUnsafe.scala +++ b/monix-eval/jvm/src/main/scala/monix/eval/internal/TaskRunSyncUnsafe.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,17 +20,17 @@ package monix.eval.internal import java.util.concurrent.TimeoutException import java.util.concurrent.locks.AbstractQueuedSynchronizer -import monix.eval.Task.{Async, Context, Error, Eval, FlatMap, Map, Now, Suspend, Trace} +import monix.eval.Task.{ Async, Context, Error, Eval, FlatMap, Map, Now, Suspend, Trace } import monix.eval.internal.TaskRunLoop._ import monix.eval.Task -import monix.eval.internal.TracingPlatform.{enhancedExceptions, isStackTracing} +import monix.eval.internal.TracingPlatform.{ enhancedExceptions, isStackTracing } import monix.eval.tracing.TaskEvent -import monix.execution.{Callback, Scheduler} +import monix.execution.{ Callback, Scheduler } import monix.execution.internal.collection.ChunkedArrayStack import scala.annotation.nowarn import scala.concurrent.blocking -import scala.concurrent.duration.{Duration, FiniteDuration} +import scala.concurrent.duration.{ Duration, FiniteDuration } import scala.util.control.NonFatal private[eval] object TaskRunSyncUnsafe { @@ -153,7 +153,8 @@ private[eval] object TaskRunSyncUnsafe { opts: Task.Options, bFirst: Bind, bRest: CallStack, - tracingCtx: StackTracedContext): A = { + tracingCtx: StackTracedContext + ): A = { val latch = new OneShotLatch val cb = new BlockingCallback[Any](latch) @@ -187,8 +188,8 @@ private[eval] object TaskRunSyncUnsafe { private final class BlockingCallback[A](latch: OneShotLatch) extends Callback[Throwable, A] { - private[this] var success: A = _ - private[this] var error: Throwable = _ + private var success: A = null.asInstanceOf[A] + private var error: Throwable = null.asInstanceOf[Throwable] def value: A = error match { diff --git a/monix-eval/jvm/src/test/scala/monix/eval/TaskAsyncAutoShiftJVMSuite.scala b/monix-eval/jvm/src/test/scala/monix/eval/TaskAsyncAutoShiftJVMSuite.scala index a7523cd4e..e0e8412ff 100644 --- a/monix-eval/jvm/src/test/scala/monix/eval/TaskAsyncAutoShiftJVMSuite.scala +++ b/monix-eval/jvm/src/test/scala/monix/eval/TaskAsyncAutoShiftJVMSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,10 +22,10 @@ import java.util.concurrent.CountDownLatch import minitest.TestSuite import monix.execution.exceptions.DummyException import monix.execution.schedulers.SchedulerService -import monix.execution.{Cancelable, CancelableFuture, ExecutionModel, Scheduler} +import monix.execution.{ Cancelable, CancelableFuture, ExecutionModel, Scheduler } import scala.concurrent.duration._ -import scala.concurrent.{blocking, ExecutionContext, Future} +import scala.concurrent.{ blocking, ExecutionContext, Future } object TaskAsyncAutoShiftJVMSuite extends TestSuite[SchedulerService] { private val ThreadName = "test-thread" @@ -872,7 +872,7 @@ object TaskAsyncAutoShiftJVMSuite extends TestSuite[SchedulerService] { } } - ///... + /// ... testAsync("Task.asyncF(register) should shift back if register forks") { s => implicit val s2: Scheduler = Scheduler.global diff --git a/monix-eval/jvm/src/test/scala/monix/eval/TaskBlockingSuite.scala b/monix-eval/jvm/src/test/scala/monix/eval/TaskBlockingSuite.scala index 625452bf7..c8d5ea58f 100644 --- a/monix-eval/jvm/src/test/scala/monix/eval/TaskBlockingSuite.scala +++ b/monix-eval/jvm/src/test/scala/monix/eval/TaskBlockingSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.eval import minitest.SimpleTestSuite import monix.execution.Scheduler.Implicits.global -import scala.concurrent.{Await, TimeoutException} +import scala.concurrent.{ Await, TimeoutException } import scala.concurrent.duration._ object TaskBlockingSuite extends SimpleTestSuite { diff --git a/monix-eval/jvm/src/test/scala/monix/eval/TaskCallbackSafetyJVMSuite.scala b/monix-eval/jvm/src/test/scala/monix/eval/TaskCallbackSafetyJVMSuite.scala index e2a75ac71..4b52ebbc4 100644 --- a/monix-eval/jvm/src/test/scala/monix/eval/TaskCallbackSafetyJVMSuite.scala +++ b/monix-eval/jvm/src/test/scala/monix/eval/TaskCallbackSafetyJVMSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,15 +17,15 @@ package monix.eval -import java.util.concurrent.{CountDownLatch, TimeUnit} +import java.util.concurrent.{ CountDownLatch, TimeUnit } import minitest.SimpleTestSuite -import monix.execution.exceptions.{CallbackCalledMultipleTimesException, DummyException} +import monix.execution.exceptions.{ CallbackCalledMultipleTimesException, DummyException } import monix.execution.schedulers.SchedulerService -import monix.execution.{Callback, Scheduler, TestUtils} +import monix.execution.{ Callback, Scheduler, TestUtils } import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object TaskCallbackSafetyJVMSuite extends SimpleTestSuite with TestUtils { val WORKERS = 10 @@ -47,14 +47,16 @@ object TaskCallbackSafetyJVMSuite extends SimpleTestSuite with TestUtils { runConcurrentCallbackTest(f => Task.cancelable { cb => f(cb); Task(()) - }) + } + ) } test("Task.cancelable0 has a safe callback") { runConcurrentCallbackTest(f => Task.cancelable0 { (_, cb) => f(cb); Task(()) - }) + } + ) } def runConcurrentCallbackTest(create: (Callback[Throwable, Int] => Unit) => Task[Int]): Unit = { @@ -92,13 +94,16 @@ object TaskCallbackSafetyJVMSuite extends SimpleTestSuite with TestUtils { run(cb => try cb.onSuccess(1) - catch { case _: CallbackCalledMultipleTimesException => () }) + catch { case _: CallbackCalledMultipleTimesException => () } + ) run(cb => try cb(Right(1)) - catch { case _: CallbackCalledMultipleTimesException => () }) + catch { case _: CallbackCalledMultipleTimesException => () } + ) run(cb => try cb(Success(1)) - catch { case _: CallbackCalledMultipleTimesException => () }) + catch { case _: CallbackCalledMultipleTimesException => () } + ) val dummy = DummyException("dummy") @@ -108,13 +113,16 @@ object TaskCallbackSafetyJVMSuite extends SimpleTestSuite with TestUtils { run(cb => try cb.onError(dummy) - catch { case _: CallbackCalledMultipleTimesException => () }) + catch { case _: CallbackCalledMultipleTimesException => () } + ) run(cb => try cb(Left(dummy)) - catch { case _: CallbackCalledMultipleTimesException => () }) + catch { case _: CallbackCalledMultipleTimesException => () } + ) run(cb => try cb(Failure(dummy)) - catch { case _: CallbackCalledMultipleTimesException => () }) + catch { case _: CallbackCalledMultipleTimesException => () } + ) } def runConcurrently(sc: Scheduler)(f: => Unit): Unit = { diff --git a/monix-eval/jvm/src/test/scala/monix/eval/TaskExecuteWithLocalContextSuite.scala b/monix-eval/jvm/src/test/scala/monix/eval/TaskExecuteWithLocalContextSuite.scala index d434a4d7f..864ef1826 100644 --- a/monix-eval/jvm/src/test/scala/monix/eval/TaskExecuteWithLocalContextSuite.scala +++ b/monix-eval/jvm/src/test/scala/monix/eval/TaskExecuteWithLocalContextSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/jvm/src/test/scala/monix/eval/TaskIssue993Suite.scala b/monix-eval/jvm/src/test/scala/monix/eval/TaskIssue993Suite.scala index 3a0cddaa1..679fc6394 100644 --- a/monix-eval/jvm/src/test/scala/monix/eval/TaskIssue993Suite.scala +++ b/monix-eval/jvm/src/test/scala/monix/eval/TaskIssue993Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.eval import minitest.SimpleTestSuite -import monix.execution.{ExecutionModel, Scheduler} +import monix.execution.{ ExecutionModel, Scheduler } import monix.execution.schedulers.SchedulerService import monix.execution.misc.Local import scala.concurrent.Await diff --git a/monix-eval/jvm/src/test/scala/monix/eval/TaskLikeConversionsJava8Suite.scala b/monix-eval/jvm/src/test/scala/monix/eval/TaskLikeConversionsJava8Suite.scala index 993d4d5dc..3afdbb1f2 100644 --- a/monix-eval/jvm/src/test/scala/monix/eval/TaskLikeConversionsJava8Suite.scala +++ b/monix-eval/jvm/src/test/scala/monix/eval/TaskLikeConversionsJava8Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ import minitest.TestSuite import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object TaskLikeConversionsJava8Suite extends TestSuite[TestScheduler] { def setup() = TestScheduler() @@ -72,4 +72,4 @@ object TaskLikeConversionsJava8Suite extends TestSuite[TestScheduler] { s.tick() assertEquals(f.value, None) } -} \ No newline at end of file +} diff --git a/monix-eval/jvm/src/test/scala/monix/eval/TaskLocalJVMSuite.scala b/monix-eval/jvm/src/test/scala/monix/eval/TaskLocalJVMSuite.scala index 501dada9b..d78919916 100644 --- a/monix-eval/jvm/src/test/scala/monix/eval/TaskLocalJVMSuite.scala +++ b/monix-eval/jvm/src/test/scala/monix/eval/TaskLocalJVMSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,18 +23,18 @@ import cats.syntax.foldable._ import minitest.SimpleTestSuite import monix.execution.ExecutionModel.AlwaysAsyncExecution import monix.execution.exceptions.DummyException -import monix.execution.{ExecutionModel, Scheduler} +import monix.execution.{ ExecutionModel, Scheduler } import monix.execution.misc.Local import monix.execution.schedulers.TracingScheduler import monix.execution.cancelableFutureCatsInstances -import scala.concurrent.{Await, ExecutionContext, Future, Promise} +import scala.concurrent.{ Await, ExecutionContext, Future, Promise } import scala.concurrent.duration._ object TaskLocalJVMSuite extends SimpleTestSuite { def createShift(ec: ExecutionContext): Task[Unit] = Task.cancelable0 { (_, cb) => - ec.execute(new Runnable { def run() = cb.onSuccess(()) }) + ec.execute(() => cb.onSuccess(())) Task.unit } @@ -476,7 +476,8 @@ object TaskLocalJVMSuite extends SimpleTestSuite { val local = Local(0) for { - _ <- Task(local.update(1)).flatMap(_ => Task.raiseError(DummyException("boom"))).runToFuture.recover{ case _ => ()} + _ <- + Task(local.update(1)).flatMap(_ => Task.raiseError(DummyException("boom"))).runToFuture.recover { case _ => () } i1 <- Future(local.get) i2 <- Local.isolate { Future(local.update(i1 + 1)) @@ -545,7 +546,7 @@ object TaskLocalJVMSuite extends SimpleTestSuite { val t1 = for { i1 <- Task(local.get) - _ <- Task.sleep(10.millis) + _ <- Task.sleep(10.millis) i2 <- Task(local.get) } yield assertEquals(i1, i2) diff --git a/monix-eval/jvm/src/test/scala/monix/eval/TaskRejectedExecutionSuite.scala b/monix-eval/jvm/src/test/scala/monix/eval/TaskRejectedExecutionSuite.scala index 28903d7e6..3195aeb95 100644 --- a/monix-eval/jvm/src/test/scala/monix/eval/TaskRejectedExecutionSuite.scala +++ b/monix-eval/jvm/src/test/scala/monix/eval/TaskRejectedExecutionSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import java.util.concurrent.RejectedExecutionException import minitest.SimpleTestSuite import monix.execution.Scheduler import monix.execution.Scheduler.Implicits.global -import scala.concurrent.{Await, ExecutionContext, Future} +import scala.concurrent.{ Await, ExecutionContext, Future } import scala.concurrent.duration._ object TaskRejectedExecutionSuite extends SimpleTestSuite { diff --git a/monix-eval/jvm/src/test/scala/monix/eval/TypeClassLawsForTaskRunSyncUnsafeSuite.scala b/monix-eval/jvm/src/test/scala/monix/eval/TypeClassLawsForTaskRunSyncUnsafeSuite.scala index 5c46d8c1a..48e4ec07f 100644 --- a/monix-eval/jvm/src/test/scala/monix/eval/TypeClassLawsForTaskRunSyncUnsafeSuite.scala +++ b/monix-eval/jvm/src/test/scala/monix/eval/TypeClassLawsForTaskRunSyncUnsafeSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,13 +17,13 @@ package monix.eval -import cats.effect.{ContextShift, IO} +import cats.effect.{ ContextShift, IO } import cats.effect.laws.discipline._ import cats.kernel.laws.discipline.MonoidTests -import cats.laws.discipline.{ApplicativeTests, CoflatMapTests, ParallelTests} -import cats.{Applicative, Eq} +import cats.laws.discipline.{ ApplicativeTests, CoflatMapTests, ParallelTests } +import cats.{ Applicative, Eq } import monix.eval.instances.CatsParallelForTask -import monix.execution.{Scheduler, TestUtils, UncaughtExceptionReporter} +import monix.execution.{ Scheduler, TestUtils, UncaughtExceptionReporter } import scala.concurrent.ExecutionContext.global import scala.concurrent.duration._ diff --git a/monix-eval/shared/src/main/scala/monix/eval/Coeval.scala b/monix-eval/shared/src/main/scala/monix/eval/Coeval.scala index 123b919e1..0d26951e1 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/Coeval.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/Coeval.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,21 +17,21 @@ package monix.eval -import cats.effect.{ExitCase, Sync} +import cats.effect.{ ExitCase, Sync } import cats.kernel.Semigroup -import cats.{Monoid, ~>} -import monix.eval.instances.{CatsMonadToMonoid, CatsMonadToSemigroup, CatsSyncForCoeval} +import cats.{ ~>, Monoid } +import monix.eval.instances.{ CatsMonadToMonoid, CatsMonadToSemigroup, CatsSyncForCoeval } import monix.eval.internal._ -import monix.eval.internal.TracingPlatform.{isCachedStackTracing, isFullStackTracing} +import monix.eval.internal.TracingPlatform.{ isCachedStackTracing, isFullStackTracing } import monix.eval.tracing.CoevalEvent import monix.execution.annotations.UnsafeBecauseImpure import monix.execution.compat.BuildFrom import monix.execution.compat.internal.newBuilder -import scala.annotation.unchecked.{uncheckedVariance => uV} +import scala.annotation.unchecked.{ uncheckedVariance => uV } import scala.collection.mutable import scala.util.control.NonFatal -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } /** `Coeval` represents lazy computations that can execute synchronously. * @@ -702,7 +702,7 @@ sealed abstract class Coeval[+A] extends (() => A) with Serializable { self => } else if (isFullStackTracing) { CoevalTracing.uncached() } else { - null + null } Map(this, f, trace) @@ -724,7 +724,7 @@ sealed abstract class Coeval[+A] extends (() => A) with Serializable { self => * `fa.materialize.dematerialize <-> fa` */ final def dematerialize[B](implicit ev: A <:< Try[B]): Coeval[B] = - self.asInstanceOf[Coeval[Try[B]]].flatMap(Eager.fromTry) + self.flatMap(x => Eager.fromTry(ev(x))) /** * Converts the source [[Coeval]] into any `F[_]` that implements @@ -863,7 +863,8 @@ sealed abstract class Coeval[+A] extends (() => A) with Serializable { self => final def onErrorRestart(maxRetries: Long): Coeval[A] = self.onErrorHandleWith(ex => if (maxRetries > 0) self.onErrorRestart(maxRetries - 1) - else Error(ex)) + else Error(ex) + ) /** Creates a new coeval that in case of error will retry executing the * source again and again, until it succeeds. @@ -1153,7 +1154,8 @@ object Coeval extends CoevalInstancesLevel0 { * It's a simple version of [[traverse]]. */ def sequence[A, M[X] <: Iterable[X]](sources: M[Coeval[A]])( - implicit bf: BuildFrom[M[Coeval[A]], A, M[A]]): Coeval[M[A]] = { + implicit bf: BuildFrom[M[Coeval[A]], A, M[A]] + ): Coeval[M[A]] = { val init = eval(newBuilder(bf, sources)) val r = sources.foldLeft(init)((acc, elem) => acc.zipMap(elem)(_ += _)) r.map(_.result()) @@ -1165,7 +1167,8 @@ object Coeval extends CoevalInstancesLevel0 { * It's a generalized version of [[sequence]]. */ def traverse[A, B, M[X] <: Iterable[X]](sources: M[A])(f: A => Coeval[B])( - implicit bf: BuildFrom[M[A], B, M[B]]): Coeval[M[B]] = { + implicit bf: BuildFrom[M[A], B, M[B]] + ): Coeval[M[B]] = { val init = eval(newBuilder(bf, sources)) val r = sources.foldLeft(init)((acc, elem) => acc.zipMap(f(elem))(_ += _)) r.map(_.result()) @@ -1292,7 +1295,8 @@ object Coeval extends CoevalInstancesLevel0 { * }}} */ def map4[A1, A2, A3, A4, R](fa1: Coeval[A1], fa2: Coeval[A2], fa3: Coeval[A3], fa4: Coeval[A4])( - f: (A1, A2, A3, A4) => R): Coeval[R] = { + f: (A1, A2, A3, A4) => R + ): Coeval[R] = { for (a1 <- fa1; a2 <- fa2; a3 <- fa3; a4 <- fa4) yield f(a1, a2, a3, a4) @@ -1323,7 +1327,8 @@ object Coeval extends CoevalInstancesLevel0 { * }}} */ def map5[A1, A2, A3, A4, A5, R](fa1: Coeval[A1], fa2: Coeval[A2], fa3: Coeval[A3], fa4: Coeval[A4], fa5: Coeval[A5])( - f: (A1, A2, A3, A4, A5) => R): Coeval[R] = { + f: (A1, A2, A3, A4, A5) => R + ): Coeval[R] = { for (a1 <- fa1; a2 <- fa2; a3 <- fa3; a4 <- fa4; a5 <- fa5) yield f(a1, a2, a3, a4, a5) @@ -1360,7 +1365,8 @@ object Coeval extends CoevalInstancesLevel0 { fa3: Coeval[A3], fa4: Coeval[A4], fa5: Coeval[A5], - fa6: Coeval[A6])(f: (A1, A2, A3, A4, A5, A6) => R): Coeval[R] = { + fa6: Coeval[A6] + )(f: (A1, A2, A3, A4, A5, A6) => R): Coeval[R] = { for (a1 <- fa1; a2 <- fa2; a3 <- fa3; a4 <- fa4; a5 <- fa5; a6 <- fa6) yield f(a1, a2, a3, a4, a5, a6) @@ -1379,7 +1385,8 @@ object Coeval extends CoevalInstancesLevel0 { fa1: Coeval[A1], fa2: Coeval[A2], fa3: Coeval[A3], - fa4: Coeval[A4]): Coeval[(A1, A2, A3, A4)] = + fa4: Coeval[A4] + ): Coeval[(A1, A2, A3, A4)] = map4(fa1, fa2, fa3, fa4)((a1, a2, a3, a4) => (a1, a2, a3, a4)) /** Pairs five [[Coeval]] instances. */ @@ -1388,7 +1395,8 @@ object Coeval extends CoevalInstancesLevel0 { fa2: Coeval[A2], fa3: Coeval[A3], fa4: Coeval[A4], - fa5: Coeval[A5]): Coeval[(A1, A2, A3, A4, A5)] = + fa5: Coeval[A5] + ): Coeval[(A1, A2, A3, A4, A5)] = map5(fa1, fa2, fa3, fa4, fa5)((a1, a2, a3, a4, a5) => (a1, a2, a3, a4, a5)) /** Pairs six [[Coeval]] instances. */ @@ -1398,7 +1406,8 @@ object Coeval extends CoevalInstancesLevel0 { fa3: Coeval[A3], fa4: Coeval[A4], fa5: Coeval[A5], - fa6: Coeval[A6]): Coeval[(A1, A2, A3, A4, A5, A6)] = + fa6: Coeval[A6] + ): Coeval[(A1, A2, A3, A4, A5, A6)] = map6(fa1, fa2, fa3, fa4, fa5, fa6)((a1, a2, a3, a4, a5, a6) => (a1, a2, a3, a4, a5, a6)) /** @@ -1637,7 +1646,7 @@ object Coeval extends CoevalInstancesLevel0 { * a `Monoid[Coeval[A]]` implementation. */ implicit def catsMonoid[A](implicit A: Monoid[A]): Monoid[Coeval[A]] = - new CatsMonadToMonoid[Coeval, A]()(CatsSyncForCoeval, A) + new CatsMonadToMonoid[Coeval, A]() } private[eval] abstract class CoevalInstancesLevel0 extends CoevalDeprecatedCompanion { @@ -1649,5 +1658,5 @@ private[eval] abstract class CoevalInstancesLevel0 extends CoevalDeprecatedCompa * in order to avoid conflicts. */ implicit def catsSemigroup[A](implicit A: Semigroup[A]): Semigroup[Coeval[A]] = - new CatsMonadToSemigroup[Coeval, A]()(Coeval.catsSync, A) + new CatsMonadToSemigroup[Coeval, A]() } diff --git a/monix-eval/shared/src/main/scala/monix/eval/CoevalLift.scala b/monix-eval/shared/src/main/scala/monix/eval/CoevalLift.scala index c71055eb4..24ad0c005 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/CoevalLift.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/CoevalLift.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.eval -import cats.{~>, Eval} +import cats.{ ~>, Eval } import cats.effect._ import scala.annotation.implicitNotFound diff --git a/monix-eval/shared/src/main/scala/monix/eval/CoevalLike.scala b/monix-eval/shared/src/main/scala/monix/eval/CoevalLike.scala index 9a809592b..3c1aff0c3 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/CoevalLike.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/CoevalLike.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.eval import cats.effect.SyncIO -import cats.{~>, Eval} +import cats.{ ~>, Eval } import scala.util.Try /** A lawless type class that provides conversions to [[Coeval]]. diff --git a/monix-eval/shared/src/main/scala/monix/eval/Fiber.scala b/monix-eval/shared/src/main/scala/monix/eval/Fiber.scala index f1d18ca07..500ec97ae 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/Fiber.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/Fiber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/main/scala/monix/eval/Task.scala b/monix-eval/shared/src/main/scala/monix/eval/Task.scala index 4965f5111..5f4d9065b 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/Task.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/Task.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,27 +17,28 @@ package monix.eval -import cats.effect.{Fiber => _, _} -import cats.{CommutativeApplicative, Monoid, Semigroup, ~>} +import cats.effect.{ Fiber => _, _ } +import cats.{ ~>, CommutativeApplicative, Monoid, Semigroup } import monix.catnap.FutureLift import monix.eval.instances._ import monix.eval.internal._ -import monix.eval.tracing.{TaskEvent, TaskTrace} -import monix.eval.internal.TracingPlatform.{isCachedStackTracing, isFullStackTracing} +import monix.eval.tracing.{ TaskEvent, TaskTrace } +import monix.eval.internal.TracingPlatform.{ isCachedStackTracing, isFullStackTracing } import monix.execution.ExecutionModel.AlwaysAsyncExecution import monix.execution._ -import monix.execution.annotations.{UnsafeBecauseBlocking, UnsafeBecauseImpure} -import monix.execution.internal.{Newtype1, Platform} +import monix.execution.annotations.{ UnsafeBecauseBlocking, UnsafeBecauseImpure } +import monix.execution.internal.{ Newtype1, Platform } import monix.execution.misc.Local -import monix.execution.schedulers.{CanBlock, TracingScheduler, TrampolinedRunnable} +import monix.execution.schedulers.{ CanBlock, TracingScheduler } import monix.execution.compat.BuildFrom import monix.execution.compat.internal.newBuilder import org.reactivestreams.Publisher -import scala.annotation.unchecked.{uncheckedVariance => uV} -import scala.concurrent.duration.{Duration, FiniteDuration, NANOSECONDS, TimeUnit} -import scala.concurrent.{ExecutionContext, Future, TimeoutException} -import scala.util.{Failure, Success, Try} +import scala.annotation.unchecked.{ uncheckedVariance => uV } +import scala.concurrent.duration.{ Duration, FiniteDuration, NANOSECONDS, TimeUnit } +import scala.concurrent.{ ExecutionContext, Future, TimeoutException } +import scala.util.{ Failure, Success, Try } +import scala.annotation.unused /** `Task` represents a specification for a possibly lazy or * asynchronous computation, which when executed will produce an `A` @@ -931,7 +932,13 @@ sealed abstract class Task[+A] extends Serializable with TaskDeprecated.BinCompa def runAsyncUncancelableOpt(cb: Either[Throwable, A] => Unit)(implicit s: Scheduler, opts: Task.Options): Unit = { val opts2 = opts.withSchedulerFeatures Local.bindCurrentIf(opts2.localContextPropagation) { - TaskRunLoop.startLight(this, s, opts2, Callback.fromAttempt(cb), isCancelable = false) + val _ = TaskRunLoop.startLight( + this, + s, + opts2, + Callback.fromAttempt(cb), + isCancelable = false + ) () } } @@ -1088,9 +1095,10 @@ sealed abstract class Task[+A] extends Serializable with TaskDeprecated.BinCompa @UnsafeBecauseImpure @UnsafeBecauseBlocking final def runSyncUnsafeOpt(timeout: Duration = Duration.Inf)( - implicit s: Scheduler, + implicit + s: Scheduler, opts: Options, - permit: CanBlock + @unused permit: CanBlock ): A = { /*_*/ val opts2 = opts.withSchedulerFeatures @@ -1937,7 +1945,7 @@ sealed abstract class Task[+A] extends Serializable with TaskDeprecated.BinCompa /** Dematerializes the source's result from a `Try`. */ final def dematerialize[B](implicit ev: A <:< Try[B]): Task[B] = - this.asInstanceOf[Task[Try[B]]].flatMap(fromTry) + this.flatMap(x => fromTry(ev(x))) /** Returns a new task that mirrors the source task for normal termination, * but that triggers the given error on cancellation. @@ -2866,7 +2874,7 @@ object Task extends TaskInstancesLevel1 { * `Task` value is cancelable if the source is */ def fromConcurrentEffect[F[_], A](fa: F[A])(implicit F: ConcurrentEffect[F]): Task[A] = - TaskConversions.fromConcurrentEffect(fa)(F) + TaskConversions.fromConcurrentEffect(fa) /** Builds a [[Task]] instance out of any data type that implements * [[https://typelevel.org/cats-effect/typeclasses/async.html Async]] and @@ -3611,7 +3619,7 @@ object Task extends TaskInstancesLevel1 { * It's a simple version of [[traverse]]. */ def sequence[A, M[X] <: Iterable[X]](in: M[Task[A]])(implicit bf: BuildFrom[M[Task[A]], A, M[A]]): Task[M[A]] = - TaskSequence.list(in)(bf) + TaskSequence.list(in) /** Given a `Iterable[A]` and a function `A => Task[B]`, sequentially * apply the function to each element of the collection and gather their @@ -3620,8 +3628,9 @@ object Task extends TaskInstancesLevel1 { * It's a generalized version of [[sequence]]. */ def traverse[A, B, M[X] <: Iterable[X]](in: M[A])(f: A => Task[B])( - implicit bf: BuildFrom[M[A], B, M[B]]): Task[M[B]] = - TaskSequence.traverse(in, f)(bf) + implicit bf: BuildFrom[M[A], B, M[B]] + ): Task[M[B]] = + TaskSequence.traverse(in, f) /** * Returns the given argument if `cond` is true, otherwise `Task.Unit` @@ -3661,7 +3670,6 @@ object Task extends TaskInstancesLevel1 { */ def raiseUnless(cond: Boolean)(e: => Throwable): Task[Unit] = Task.unless(cond)(Task.raiseError(e)) - /** Executes the given sequence of tasks in parallel, non-deterministically * gathering their results, returning a task that will signal the sequence * of results once all tasks are finished. @@ -3747,7 +3755,9 @@ object Task extends TaskInstancesLevel1 { * * @see [[parTraverseN]] for a version that limits parallelism. */ - def parTraverse[A, B, M[X] <: Iterable[X]](in: M[A])(f: A => Task[B])(implicit bf: BuildFrom[M[A], B, M[B]]): Task[M[B]] = + def parTraverse[A, B, M[X] <: Iterable[X]](in: M[A])(f: A => Task[B])(implicit + bf: BuildFrom[M[A], B, M[B]] + ): Task[M[B]] = Task.eval(in.map(f)).flatMap(col => TaskParSequence[B, M](col, () => newBuilder(bf, in))) /** Given a `Iterable[A]` and a function `A => Task[B]`, @@ -3939,7 +3949,8 @@ object Task extends TaskInstancesLevel1 { * See [[Task.parMap4]] for parallel processing. */ def map4[A1, A2, A3, A4, R](fa1: Task[A1], fa2: Task[A2], fa3: Task[A3], fa4: Task[A4])( - f: (A1, A2, A3, A4) => R): Task[R] = { + f: (A1, A2, A3, A4) => R + ): Task[R] = { for (a1 <- fa1; a2 <- fa2; a3 <- fa3; a4 <- fa4) yield f(a1, a2, a3, a4) @@ -3976,7 +3987,8 @@ object Task extends TaskInstancesLevel1 { * See [[Task.parMap5]] for parallel processing. */ def map5[A1, A2, A3, A4, A5, R](fa1: Task[A1], fa2: Task[A2], fa3: Task[A3], fa4: Task[A4], fa5: Task[A5])( - f: (A1, A2, A3, A4, A5) => R): Task[R] = { + f: (A1, A2, A3, A4, A5) => R + ): Task[R] = { for (a1 <- fa1; a2 <- fa2; a3 <- fa3; a4 <- fa4; a5 <- fa5) yield f(a1, a2, a3, a4, a5) @@ -4019,7 +4031,8 @@ object Task extends TaskInstancesLevel1 { fa3: Task[A3], fa4: Task[A4], fa5: Task[A5], - fa6: Task[A6])(f: (A1, A2, A3, A4, A5, A6) => R): Task[R] = { + fa6: Task[A6] + )(f: (A1, A2, A3, A4, A5, A6) => R): Task[R] = { for (a1 <- fa1; a2 <- fa2; a3 <- fa3; a4 <- fa4; a5 <- fa5; a6 <- fa6) yield f(a1, a2, a3, a4, a5, a6) @@ -4127,7 +4140,8 @@ object Task extends TaskInstancesLevel1 { * See [[Task.map4]] for sequential processing. */ def parMap4[A1, A2, A3, A4, R](fa1: Task[A1], fa2: Task[A2], fa3: Task[A3], fa4: Task[A4])( - f: (A1, A2, A3, A4) => R): Task[R] = { + f: (A1, A2, A3, A4) => R + ): Task[R] = { val fa123 = parZip3(fa1, fa2, fa3) parMap2(fa123, fa4) { case ((a1, a2, a3), a4) => f(a1, a2, a3, a4) } } @@ -4166,7 +4180,8 @@ object Task extends TaskInstancesLevel1 { * See [[Task.map5]] for sequential processing. */ def parMap5[A1, A2, A3, A4, A5, R](fa1: Task[A1], fa2: Task[A2], fa3: Task[A3], fa4: Task[A4], fa5: Task[A5])( - f: (A1, A2, A3, A4, A5) => R): Task[R] = { + f: (A1, A2, A3, A4, A5) => R + ): Task[R] = { val fa1234 = parZip4(fa1, fa2, fa3, fa4) parMap2(fa1234, fa5) { case ((a1, a2, a3, a4), a5) => f(a1, a2, a3, a4, a5) } } @@ -4211,7 +4226,8 @@ object Task extends TaskInstancesLevel1 { fa3: Task[A3], fa4: Task[A4], fa5: Task[A5], - fa6: Task[A6])(f: (A1, A2, A3, A4, A5, A6) => R): Task[R] = { + fa6: Task[A6] + )(f: (A1, A2, A3, A4, A5, A6) => R): Task[R] = { val fa12345 = parZip5(fa1, fa2, fa3, fa4, fa5) parMap2(fa12345, fa6) { case ((a1, a2, a3, a4, a5), a6) => f(a1, a2, a3, a4, a5, a6) } } @@ -4234,7 +4250,8 @@ object Task extends TaskInstancesLevel1 { fa2: Task[A2], fa3: Task[A3], fa4: Task[A4], - fa5: Task[A5]): Task[(A1, A2, A3, A4, A5)] = + fa5: Task[A5] + ): Task[(A1, A2, A3, A4, A5)] = parMap5(fa1, fa2, fa3, fa4, fa5)((a1, a2, a3, a4, a5) => (a1, a2, a3, a4, a5)) /** Pairs six [[Task]] instances using [[parMap6]]. */ @@ -4244,7 +4261,8 @@ object Task extends TaskInstancesLevel1 { fa3: Task[A3], fa4: Task[A4], fa5: Task[A5], - fa6: Task[A6]): Task[(A1, A2, A3, A4, A5, A6)] = + fa6: Task[A6] + ): Task[(A1, A2, A3, A4, A5, A6)] = parMap6(fa1, fa2, fa3, fa4, fa5, fa6)((a1, a2, a3, a4, a5, a6) => (a1, a2, a3, a4, a5, a6)) /** @@ -4306,8 +4324,10 @@ object Task extends TaskInstancesLevel1 { * the usage of `cats.effect.Concurrent`, since [[TaskLift]] is lawless. */ def liftToConcurrent[F[_]]( - implicit F: cats.effect.Concurrent[F], - eff: cats.effect.ConcurrentEffect[Task]): (Task ~> F) = + implicit + F: cats.effect.Concurrent[F], + eff: cats.effect.ConcurrentEffect[Task] + ): (Task ~> F) = TaskLift.toConcurrent[F] /** @@ -4500,7 +4520,8 @@ object Task extends TaskInstancesLevel1 { */ private[eval] final class CreatePartiallyApplied[A](val dummy: Boolean = true) extends AnyVal { def apply[CancelationToken](register: (Scheduler, Callback[Throwable, A]) => CancelationToken)( - implicit B: AsyncBuilder[CancelationToken]): Task[A] = + implicit B: AsyncBuilder[CancelationToken] + ): Task[A] = B.create(register) } @@ -4549,11 +4570,10 @@ object Task extends TaskInstancesLevel1 { implicit def forCancelableDummy[T <: Cancelable.Empty]: AsyncBuilder[T] = forCancelableDummyRef.asInstanceOf[AsyncBuilder[T]] - private[this] val forCancelableDummyRef: AsyncBuilder[Cancelable.Empty] = - new AsyncBuilder[Cancelable.Empty] { - def create[A](register: (Scheduler, Callback[Throwable, A]) => Cancelable.Empty): Task[A] = - TaskCreate.async0(register) - } + private val forCancelableDummyRef: AsyncBuilder[Cancelable.Empty] = new AsyncBuilder[Cancelable.Empty] { + def create[A](register: (Scheduler, Callback[Throwable, A]) => Cancelable.Empty): Task[A] = + TaskCreate.async0(register) + } } private[Task] abstract class AsyncBuilder0 { @@ -4565,11 +4585,10 @@ object Task extends TaskInstancesLevel1 { implicit def forCancelable[T <: Cancelable]: AsyncBuilder[T] = forCancelableRef.asInstanceOf[AsyncBuilder[T]] - private[this] val forCancelableRef = - new AsyncBuilder[Cancelable] { - def create[A](register: (Scheduler, Callback[Throwable, A]) => Cancelable): Task[A] = - TaskCreate.cancelableCancelable(register) - } + private val forCancelableRef = new AsyncBuilder[Cancelable] { + def create[A](register: (Scheduler, Callback[Throwable, A]) => Cancelable): Task[A] = + TaskCreate.cancelableCancelable(register) + } } /** Internal API — The `Context` under which [[Task]] is supposed to be executed. @@ -4582,7 +4601,8 @@ object Task extends TaskInstancesLevel1 { options: Options, connection: TaskConnection, frameRef: FrameIndexRef, - stackTracedContext: StackTracedContext) { + stackTracedContext: StackTracedContext + ) { val scheduler: Scheduler = { if (options.localContextPropagation && !schedulerRef.features.contains(Scheduler.TRACING)) TracingScheduler(schedulerRef) @@ -4615,7 +4635,12 @@ object Task extends TaskInstancesLevel1 { def apply(scheduler: Scheduler, options: Options): Context = apply(scheduler, options, TaskConnection(), new StackTracedContext) - def apply(scheduler: Scheduler, options: Options, connection: TaskConnection, stackTracedContext: StackTracedContext): Context = { + def apply( + scheduler: Scheduler, + options: Options, + connection: TaskConnection, + stackTracedContext: StackTracedContext + ): Context = { val em = scheduler.executionModel val frameRef = FrameIndexRef(em) new Context(scheduler, options, connection, frameRef, stackTracedContext) @@ -4626,12 +4651,13 @@ object Task extends TaskInstancesLevel1 { private[eval] final case class Now[A](value: A) extends Task[A] { // Optimization to avoid the run-loop override def runAsyncOptF( - cb: Either[Throwable, A] => Unit)(implicit s: Scheduler, opts: Task.Options): CancelToken[Task] = { + cb: Either[Throwable, A] => Unit + )(implicit s: Scheduler, opts: Task.Options): CancelToken[Task] = { if (s.executionModel != AlwaysAsyncExecution) { Callback.callSuccess(cb, value) Task.unit } else { - super.runAsyncOptF(cb)(s, opts) + super.runAsyncOptF(cb) } } @@ -4646,19 +4672,20 @@ object Task extends TaskInstancesLevel1 { Callback.callSuccess(cb, value) Cancelable.empty } else { - super.runAsyncOpt(cb)(s, opts) + super.runAsyncOpt(cb) } } // Optimization to avoid the run-loop override def runAsyncUncancelableOpt(cb: Either[Throwable, A] => Unit)( - implicit s: Scheduler, + implicit + s: Scheduler, opts: Options ): Unit = { if (s.executionModel != AlwaysAsyncExecution) Callback.callSuccess(cb, value) else - super.runAsyncUncancelableOpt(cb)(s, opts) + super.runAsyncUncancelableOpt(cb) } // Optimization to avoid the run-loop @@ -4670,12 +4697,13 @@ object Task extends TaskInstancesLevel1 { private[eval] final case class Error[A](e: Throwable) extends Task[A] { // Optimization to avoid the run-loop override def runAsyncOptF( - cb: Either[Throwable, A] => Unit)(implicit s: Scheduler, opts: Task.Options): CancelToken[Task] = { + cb: Either[Throwable, A] => Unit + )(implicit s: Scheduler, opts: Task.Options): CancelToken[Task] = { if (s.executionModel != AlwaysAsyncExecution) { Callback.callError(cb, e) Task.unit } else { - super.runAsyncOptF(cb)(s, opts) + super.runAsyncOptF(cb) } } @@ -4690,7 +4718,7 @@ object Task extends TaskInstancesLevel1 { Callback.callError(cb, e) Cancelable.empty } else { - super.runAsyncOpt(cb)(s, opts) + super.runAsyncOpt(cb) } } @@ -4700,13 +4728,14 @@ object Task extends TaskInstancesLevel1 { // Optimization to avoid the run-loop override def runAsyncUncancelableOpt(cb: Either[Throwable, A] => Unit)( - implicit s: Scheduler, + implicit + s: Scheduler, opts: Options ): Unit = { if (s.executionModel != AlwaysAsyncExecution) Callback.callError(cb, e) else - super.runAsyncUncancelableOpt(cb)(s, opts) + super.runAsyncUncancelableOpt(cb) } } @@ -4748,8 +4777,8 @@ object Task extends TaskInstancesLevel1 { trampolineBefore: Boolean = false, trampolineAfter: Boolean = true, restoreLocals: Boolean = true, - trace: AnyRef = null) - extends Task[A] + trace: AnyRef = null + ) extends Task[A] /** For changing the context for the rest of the run-loop. * @@ -4758,8 +4787,8 @@ object Task extends TaskInstancesLevel1 { private[monix] final case class ContextSwitch[A]( source: Task[A], modify: Context => Context, - restore: (A, Throwable, Context, Context) => Context) - extends Task[A] + restore: (A, Throwable, Context, Context) => Context + ) extends Task[A] private[monix] final case class Trace[A](source: Task[A], trace: TaskEvent) extends Task[A] @@ -4786,9 +4815,8 @@ object Task extends TaskInstancesLevel1 { * trampolined async boundary. */ private[monix] def unsafeStartTrampolined[A](source: Task[A], context: Context, cb: Callback[Throwable, A]): Unit = - context.scheduler.execute(new TrampolinedRunnable { - def run(): Unit = - TaskRunLoop.startFull(source, context, cb, null, null, null, context.frameRef()) + context.scheduler.executeTrampolined(() => { + TaskRunLoop.startFull(source, context, cb, null, null, null, context.frameRef()) }) /** @@ -4798,8 +4826,7 @@ object Task extends TaskInstancesLevel1 { TaskRunLoop.startFull(source, context, cb, null, null, null, context.frameRef()) /** Internal, reusable reference. */ - private[this] val neverRef: Async[Nothing] = - Async((_, _) => (), trampolineBefore = false, trampolineAfter = false) + private val neverRef: Async[Nothing] = Async((_, _) => (), trampolineBefore = false, trampolineAfter = false) /** Internal, reusable reference. */ private val nowConstructor: Any => Task[Nothing] = @@ -4900,7 +4927,7 @@ private[eval] abstract class TaskInstancesLevel1 extends TaskInstancesLevel0 { * a `Monoid[ Task[A] ]` implementation. */ implicit def catsMonoid[A](implicit A: Monoid[A]): Monoid[Task[A]] = - new CatsMonadToMonoid[Task, A]()(CatsConcurrentForTask, A) + new CatsMonadToMonoid[Task, A]() } private[eval] abstract class TaskInstancesLevel0 extends TaskParallelNewtype { @@ -4933,8 +4960,10 @@ private[eval] abstract class TaskInstancesLevel0 extends TaskParallelNewtype { * to be available in scope */ implicit def catsEffect( - implicit s: Scheduler, - opts: Task.Options = Task.defaultOptions): CatsConcurrentEffectForTask = { + implicit + s: Scheduler, + opts: Task.Options = Task.defaultOptions + ): CatsConcurrentEffectForTask = { new CatsConcurrentEffectForTask } @@ -4947,7 +4976,7 @@ private[eval] abstract class TaskInstancesLevel0 extends TaskParallelNewtype { * in order to avoid conflicts. */ implicit def catsSemigroup[A](implicit A: Semigroup[A]): Semigroup[Task[A]] = - new CatsMonadToSemigroup[Task, A]()(CatsConcurrentForTask, A) + new CatsMonadToSemigroup[Task, A]() } private[eval] abstract class TaskParallelNewtype extends TaskContextShift { diff --git a/monix-eval/shared/src/main/scala/monix/eval/TaskApp.scala b/monix-eval/shared/src/main/scala/monix/eval/TaskApp.scala index 9d8f9554e..647e72c1f 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/TaskApp.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/TaskApp.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/main/scala/monix/eval/TaskLift.scala b/monix-eval/shared/src/main/scala/monix/eval/TaskLift.scala index 7a71a1eb4..adf824248 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/TaskLift.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/TaskLift.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/main/scala/monix/eval/TaskLike.scala b/monix-eval/shared/src/main/scala/monix/eval/TaskLike.scala index 79c19669f..d1ff6cdd9 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/TaskLike.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/TaskLike.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.eval import cats.effect._ -import cats.{~>, Eval} +import cats.{ ~>, Eval } import monix.catnap.FutureLift import monix.execution.CancelablePromise diff --git a/monix-eval/shared/src/main/scala/monix/eval/TaskLocal.scala b/monix-eval/shared/src/main/scala/monix/eval/TaskLocal.scala index 5ce4c8a96..a09b7b024 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/TaskLocal.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/TaskLocal.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -278,13 +278,13 @@ object TaskLocal { private def checkPropagation[A](fa: Task[A]): Task[A] = ContextSwitch(fa, checkPropagationRef, null) - private[this] val checkPropagationRef: Task.Context => Task.Context = - ctx => { - if (!ctx.options.localContextPropagation) { - throw new APIContractViolationException( - "Support for TaskLocal usage isn't active! " + - "See documentation at: https://monix.io/api/current/monix/eval/TaskLocal.html") - } - ctx + private val checkPropagationRef: Task.Context => Task.Context = ctx => { + if (!ctx.options.localContextPropagation) { + throw new APIContractViolationException( + "Support for TaskLocal usage isn't active! " + + "See documentation at: https://monix.io/api/current/monix/eval/TaskLocal.html" + ) } + ctx + } } diff --git a/monix-eval/shared/src/main/scala/monix/eval/instances/CatsAsyncForTask.scala b/monix-eval/shared/src/main/scala/monix/eval/instances/CatsAsyncForTask.scala index 425667549..2dfa693ab 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/instances/CatsAsyncForTask.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/instances/CatsAsyncForTask.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.eval package instances -import cats.effect.{Async, CancelToken, Concurrent, ExitCase} +import cats.effect.{ Async, CancelToken, Concurrent, ExitCase } import monix.eval.internal.TaskCreate /** Cats type class instance of [[monix.eval.Task Task]] @@ -40,7 +40,8 @@ class CatsAsyncForTask extends CatsBaseForTask with Async[Task] { override def bracket[A, B](acquire: Task[A])(use: A => Task[B])(release: A => Task[Unit]): Task[B] = acquire.bracket(use)(release) override def bracketCase[A, B](acquire: Task[A])(use: A => Task[B])( - release: (A, ExitCase[Throwable]) => Task[Unit]): Task[B] = + release: (A, ExitCase[Throwable]) => Task[Unit] + ): Task[B] = acquire.bracketCase(use)(release) override def asyncF[A](k: (Either[Throwable, A] => Unit) => Task[Unit]): Task[A] = Task.asyncF(k) diff --git a/monix-eval/shared/src/main/scala/monix/eval/instances/CatsBaseForTask.scala b/monix-eval/shared/src/main/scala/monix/eval/instances/CatsBaseForTask.scala index 3c15b6dd1..37fb82e6e 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/instances/CatsBaseForTask.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/instances/CatsBaseForTask.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.eval.instances -import cats.{CoflatMap, Eval, MonadError, SemigroupK} +import cats.{ CoflatMap, Eval, MonadError, SemigroupK } import monix.eval.Task import scala.util.Try diff --git a/monix-eval/shared/src/main/scala/monix/eval/instances/CatsEffectForTask.scala b/monix-eval/shared/src/main/scala/monix/eval/instances/CatsEffectForTask.scala index 4e56132c5..5b388720d 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/instances/CatsEffectForTask.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/instances/CatsEffectForTask.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.eval package instances -import cats.effect.{Fiber => _, _} +import cats.effect.{ Fiber => _, _ } import monix.eval.internal.TaskEffect import monix.execution.Scheduler @@ -44,7 +44,7 @@ class CatsEffectForTask(implicit s: Scheduler, opts: Task.Options) extends CatsB * inherit directly from it, the implicits priorities don't * work, triggering conflicts. */ - private[this] val F = CatsConcurrentForTask + private val F = CatsConcurrentForTask override def runAsync[A](fa: Task[A])(cb: Either[Throwable, A] => IO[Unit]): SyncIO[Unit] = TaskEffect.runAsync(fa)(cb) @@ -59,7 +59,8 @@ class CatsEffectForTask(implicit s: Scheduler, opts: Task.Options) extends CatsB override def bracket[A, B](acquire: Task[A])(use: A => Task[B])(release: A => Task[Unit]): Task[B] = F.bracket(acquire)(use)(release) override def bracketCase[A, B](acquire: Task[A])(use: A => Task[B])( - release: (A, ExitCase[Throwable]) => Task[Unit]): Task[B] = + release: (A, ExitCase[Throwable]) => Task[Unit] + ): Task[B] = F.bracketCase(acquire)(use)(release) } @@ -85,7 +86,7 @@ class CatsConcurrentEffectForTask(implicit s: Scheduler, opts: Task.Options) * inherit directly from it, the implicits priorities don't * work, triggering conflicts. */ - private[this] val F = CatsConcurrentForTask + private val F = CatsConcurrentForTask override def runCancelable[A](fa: Task[A])(cb: Either[Throwable, A] => IO[Unit]): SyncIO[CancelToken[Task]] = TaskEffect.runCancelable(fa)(cb) diff --git a/monix-eval/shared/src/main/scala/monix/eval/instances/CatsMonadToMonoid.scala b/monix-eval/shared/src/main/scala/monix/eval/instances/CatsMonadToMonoid.scala index 98648d1da..672668bc8 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/instances/CatsMonadToMonoid.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/instances/CatsMonadToMonoid.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.eval.instances -import cats.{Monad, Monoid, Semigroup} +import cats.{ Monad, Monoid, Semigroup } /** Given that `A` has a `cats.Semigroup` implementation, this * builds a `Semigroup[F[A]]` instance for any `F[_]` data type diff --git a/monix-eval/shared/src/main/scala/monix/eval/instances/CatsParallelForTask.scala b/monix-eval/shared/src/main/scala/monix/eval/instances/CatsParallelForTask.scala index 8fda97be1..9a035a6d5 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/instances/CatsParallelForTask.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/instances/CatsParallelForTask.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.eval.instances -import cats.{Applicative, CommutativeApplicative, Monad, Parallel, ~>} +import cats.{ ~>, Applicative, CommutativeApplicative, Monad, Parallel } import monix.eval.Task /** `cats.Parallel` type class instance for [[monix.eval.Task Task]]. @@ -49,7 +49,7 @@ object CatsParallelForTask extends CatsParallelForTask { private[eval] object NondetApplicative extends CommutativeApplicative[Task.Par] { import Task.Par.unwrap - import Task.Par.{apply => par} + import Task.Par.{ apply => par } override def ap[A, B](ff: Task.Par[A => B])(fa: Task.Par[A]): Task.Par[B] = par(Task.mapBoth(unwrap(ff), unwrap(fa))(_(_))) diff --git a/monix-eval/shared/src/main/scala/monix/eval/instances/CatsSyncForCoeval.scala b/monix-eval/shared/src/main/scala/monix/eval/instances/CatsSyncForCoeval.scala index 7bff92131..ace8f9eba 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/instances/CatsSyncForCoeval.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/instances/CatsSyncForCoeval.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,8 +17,8 @@ package monix.eval.instances -import cats.{CoflatMap, Eval, SemigroupK} -import cats.effect.{ExitCase, Sync, SyncEffect} +import cats.{ CoflatMap, Eval, SemigroupK } +import cats.effect.{ ExitCase, Sync, SyncEffect } import monix.eval.Coeval import scala.util.Try @@ -81,7 +81,8 @@ class CatsSyncForCoeval extends SyncEffect[Coeval] with CoflatMap[Coeval] with S override def bracket[A, B](acquire: Coeval[A])(use: A => Coeval[B])(release: A => Coeval[Unit]): Coeval[B] = acquire.bracket(use)(release) override def bracketCase[A, B](acquire: Coeval[A])(use: A => Coeval[B])( - release: (A, ExitCase[Throwable]) => Coeval[Unit]): Coeval[B] = + release: (A, ExitCase[Throwable]) => Coeval[Unit] + ): Coeval[B] = acquire.bracketCase(use)(release) override def combineK[A](x: Coeval[A], y: Coeval[A]): Coeval[A] = x.onErrorHandleWith(_ => y) @@ -94,4 +95,4 @@ class CatsSyncForCoeval extends SyncEffect[Coeval] with CoflatMap[Coeval] with S * Globally available in scope, as it is returned by * [[monix.eval.Coeval.catsSync Coeval.catsSync]]. */ -object CatsSyncForCoeval extends CatsSyncForCoeval \ No newline at end of file +object CatsSyncForCoeval extends CatsSyncForCoeval diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalBracket.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalBracket.scala index ab35f8925..f5e6346b9 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalBracket.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalBracket.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,12 +24,13 @@ import scala.util.control.NonFatal private[eval] object CoevalBracket { /** - * Implementation for `Coeval.bracketE`. - */ +* Implementation for `Coeval.bracketE`. +*/ def either[A, B]( acquire: Coeval[A], use: A => Coeval[B], - release: (A, Either[Throwable, B]) => Coeval[Unit]): Coeval[B] = { + release: (A, Either[Throwable, B]) => Coeval[Unit] + ): Coeval[B] = { acquire.flatMap { a => val next = @@ -40,12 +41,13 @@ private[eval] object CoevalBracket { } /** - * Implementation for `Coeval.bracketCase`. - */ +* Implementation for `Coeval.bracketCase`. +*/ def exitCase[A, B]( acquire: Coeval[A], use: A => Coeval[B], - release: (A, ExitCase[Throwable]) => Coeval[Unit]): Coeval[B] = { + release: (A, ExitCase[Throwable]) => Coeval[Unit] + ): Coeval[B] = { acquire.flatMap { a => val next = diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalDeprecated.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalDeprecated.scala index e49301976..23fba249d 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalDeprecated.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalDeprecated.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.eval package internal import cats.Eval -import cats.effect.{IO, SyncIO} +import cats.effect.{ IO, SyncIO } /** * Extension methods describing deprecated `Task` operations. diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalRunLoop.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalRunLoop.scala index 35007135c..06cc78a6a 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalRunLoop.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalRunLoop.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,10 +18,10 @@ package monix.eval.internal import monix.eval.Coeval -import monix.eval.Coeval.{Always, Eager, Error, FlatMap, Map, Now, Suspend, Trace} -import monix.eval.tracing.{CoevalEvent, CoevalTrace} +import monix.eval.Coeval.{ Always, Eager, Error, FlatMap, Map, Now, Suspend, Trace } +import monix.eval.tracing.{ CoevalEvent, CoevalTrace } import monix.execution.internal.collection.ChunkedArrayStack -import monix.eval.internal.TracingPlatform.{enhancedExceptions, isStackTracing} +import monix.eval.internal.TracingPlatform.{ enhancedExceptions, isStackTracing } import scala.reflect.NameTransformer import scala.util.control.NonFatal @@ -43,7 +43,7 @@ private[eval] object CoevalRunLoop { while (true) { current match { - case bind@FlatMap(fa, bindNext, _) => + case bind @ FlatMap(fa, bindNext, _) => if (isStackTracing) { val trace = bind.trace if (tracingCtx eq null) tracingCtx = new CoevalStackTracedContext @@ -149,7 +149,7 @@ private[eval] object CoevalRunLoop { val ref = bRest.pop() if (ref eq null) return null - else if (ref.isInstanceOf[StackFrame[_, _]]) + else if (ref.isInstanceOf[StackFrame[?, ?]]) return ref.asInstanceOf[StackFrame[Any, Coeval[Any]]] } // $COVERAGE-OFF$ @@ -160,7 +160,7 @@ private[eval] object CoevalRunLoop { } private def popNextBind(bFirst: Bind, bRest: CallStack): Bind = { - if ((bFirst ne null) && !bFirst.isInstanceOf[StackFrame.ErrorHandler[_, _]]) + if ((bFirst ne null) && !bFirst.isInstanceOf[StackFrame.ErrorHandler[?, ?]]) return bFirst if (bRest eq null) return null @@ -168,7 +168,7 @@ private[eval] object CoevalRunLoop { val next = bRest.pop() if (next eq null) { return null - } else if (!next.isInstanceOf[StackFrame.ErrorHandler[_, _]]) { + } else if (!next.isInstanceOf[StackFrame.ErrorHandler[?, ?]]) { return next } } @@ -178,10 +178,10 @@ private[eval] object CoevalRunLoop { } /** - * If stack tracing and contextual exceptions are enabled, this - * function will rewrite the stack trace of a captured exception - * to include the async stack trace. - */ +* If stack tracing and contextual exceptions are enabled, this +* function will rewrite the stack trace of a captured exception +* to include the async stack trace. +*/ private[internal] def augmentException(ex: Throwable, ctx: CoevalStackTracedContext): Unit = { val stackTrace = ex.getStackTrace if (stackTrace.nonEmpty) { @@ -195,10 +195,12 @@ private[eval] object CoevalRunLoop { case (methodSite, callSite) => val op = NameTransformer.decode(methodSite.getMethodName) - new StackTraceElement(op + " @ " + callSite.getClassName, + new StackTraceElement( + op + " @ " + callSite.getClassName, callSite.getMethodName, callSite.getFileName, - callSite.getLineNumber) + callSite.getLineNumber + ) } .toArray ex.setStackTrace(prefix ++ suffix) @@ -209,7 +211,7 @@ private[eval] object CoevalRunLoop { private def dropRunLoopFrames(frames: Array[StackTraceElement]): Array[StackTraceElement] = frames.takeWhile(ste => !runLoopFilter.exists(ste.getClassName.startsWith(_))) - private[this] val runLoopFilter = List( + private val runLoopFilter = List( "monix.eval.", "scala.runtime." ) diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalStackTracedContext.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalStackTracedContext.scala index 6379567ea..f1b7e8415 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalStackTracedContext.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalStackTracedContext.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,14 +17,14 @@ package monix.eval.internal -import monix.eval.tracing.{CoevalEvent, CoevalTrace} +import monix.eval.tracing.{ CoevalEvent, CoevalTrace } import monix.eval.internal.TracingPlatform.traceBufferLogSize import monix.execution.internal.RingBuffer private[eval] final class CoevalStackTracedContext { - private[this] val events: RingBuffer[CoevalEvent] = new RingBuffer(traceBufferLogSize) - private[this] var captured: Int = 0 - private[this] var omitted: Int = 0 + private val events: RingBuffer[CoevalEvent] = new RingBuffer(traceBufferLogSize) + private var captured: Int = 0 + private var omitted: Int = 0 def pushEvent(fr: CoevalEvent): Unit = { captured += 1 @@ -36,4 +36,4 @@ private[eval] final class CoevalStackTracedContext { def getStackTraces(): List[CoevalEvent.StackTrace] = events.toList.collect { case ev: CoevalEvent.StackTrace => ev } -} \ No newline at end of file +} diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalTracing.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalTracing.scala index 1d6954d80..cc5485790 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalTracing.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/CoevalTracing.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,17 +27,16 @@ import monix.eval.tracing.CoevalEvent * All Credits to https://github.com/typelevel/cats-effect and https://github.com/RaasAhsan */ private[eval] object CoevalTracing { - def decorated[A](source: Coeval[A]): Coeval[A] = Trace(source, buildFrame()) def uncached(): CoevalEvent = buildFrame() - def cached(clazz: Class[_]): CoevalEvent = + def cached(clazz: Class[?]): CoevalEvent = buildCachedFrame(clazz) - private def buildCachedFrame(clazz: Class[_]): CoevalEvent = { + private def buildCachedFrame(clazz: Class[?]): CoevalEvent = { val currentFrame = frameCache.get(clazz) if (currentFrame eq null) { val newFrame = buildFrame() @@ -52,9 +51,8 @@ private[eval] object CoevalTracing { CoevalEvent.StackTrace(new Throwable().getStackTrace.toList) /** - * Global cache for trace frames. Keys are references to lambda classes. - * Should converge to the working set of traces very quickly for hot code paths. - */ - private[this] val frameCache: ConcurrentHashMap[Class[_], CoevalEvent] = new ConcurrentHashMap() - -} \ No newline at end of file +* Global cache for trace frames. Keys are references to lambda classes. +* Should converge to the working set of traces very quickly for hot code paths. +*/ + private val frameCache: ConcurrentHashMap[Class[?], CoevalEvent] = new ConcurrentHashMap() +} diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/ForkedRegister.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/ForkedRegister.scala index c1f272acd..04c7324f7 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/ForkedRegister.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/ForkedRegister.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.eval.internal import monix.execution.Callback -import monix.eval.Task.{Async, Context, ContextSwitch, FlatMap, Map} +import monix.eval.Task.{ Async, Context, ContextSwitch, FlatMap, Map } import monix.eval.Task import scala.annotation.tailrec import scala.runtime.AbstractFunction2 @@ -39,12 +39,12 @@ private[eval] abstract class ForkedRegister[A] extends AbstractFunction2[Context private[eval] object ForkedRegister { /** - * Returns `true` if the given task is known to fork execution, - * or `false` otherwise. - */ - @tailrec def detect(task: Task[_], limit: Int = 8): Boolean = { +* Returns `true` if the given task is known to fork execution, +* or `false` otherwise. +*/ + @tailrec def detect(task: Task[?], limit: Int = 8): Boolean = { if (limit > 0) task match { - case Async(_: ForkedRegister[_], _, _, _, _) => true + case Async(_: ForkedRegister[?], _, _, _, _) => true case FlatMap(other, _, _) => detect(other, limit - 1) case Map(other, _, _) => detect(other, limit - 1) case ContextSwitch(other, _, _) => detect(other, limit - 1) diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/ForwardCancelable.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/ForwardCancelable.scala index 06ef13d93..5ac2b8836 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/ForwardCancelable.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/ForwardCancelable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ import java.util.concurrent.atomic.AtomicReference import cats.effect.CancelToken import monix.eval.Task import monix.execution.schedulers.TrampolineExecutionContext -import monix.execution.{Callback, Scheduler} +import monix.execution.{ Callback, Scheduler } import scala.annotation.tailrec import scala.concurrent.ExecutionContext @@ -37,7 +37,7 @@ import scala.util.control.NonFatal final private[internal] class ForwardCancelable private () { import ForwardCancelable._ - private[this] val state = new AtomicReference[State](init) + private val state = new AtomicReference[State](init) val cancel: CancelToken[Task] = { @tailrec def loop(ctx: Task.Context, cb: Callback[Throwable, Unit]): Unit = @@ -48,10 +48,7 @@ final private[internal] class ForwardCancelable private () { case Active(token) => state.lazySet(finished) // GC purposes - context.execute(new Runnable { - def run() = - Task.unsafeStartNow(token, ctx, cb) - }) + context.execute(() => Task.unsafeStartNow(token, ctx, cb)) } Task.Async(loop) @@ -80,22 +77,22 @@ final private[internal] class ForwardCancelable private () { private[internal] object ForwardCancelable { /** - * Builds reference. - */ + * Builds reference. + */ def apply(): ForwardCancelable = new ForwardCancelable /** - * Models the internal state of [[ForwardCancelable]]: - * - * - on start, the state is [[Empty]] of `Nil`, aka [[init]] - * - on `cancel`, if no token was assigned yet, then the state will - * remain [[Empty]] with a non-nil `List[Callback]` - * - if a `CancelToken` is provided without `cancel` happening, - * then the state transitions to [[Active]] mode - * - on `cancel`, if the state was [[Active]], or if it was [[Empty]], - * regardless, the state transitions to `Active(IO.unit)`, aka [[finished]] - */ + * Models the internal state of [[ForwardCancelable]]: + * + * - on start, the state is [[Empty]] of `Nil`, aka [[init]] + * - on `cancel`, if no token was assigned yet, then the state will + * remain [[Empty]] with a non-nil `List[Callback]` + * - if a `CancelToken` is provided without `cancel` happening, + * then the state transitions to [[Active]] mode + * - on `cancel`, if the state was [[Active]], or if it was [[Empty]], + * regardless, the state transitions to `Active(IO.unit)`, aka [[finished]] + */ sealed abstract private class State final private case class Empty(stack: List[Callback[Throwable, Unit]]) extends State @@ -106,19 +103,17 @@ private[internal] object ForwardCancelable { private val context: ExecutionContext = TrampolineExecutionContext.immediate private def execute(token: CancelToken[Task], stack: List[Callback[Throwable, Unit]])(implicit s: Scheduler): Unit = - context.execute(new Runnable { - def run(): Unit = { - token.runAsync { r => - for (cb <- stack) - try { - cb(r) - } catch { - // $COVERAGE-OFF$ - case NonFatal(e) => s.reportFailure(e) - // $COVERAGE-ON$ - } - } - () + context.execute(() => { + val _ = token.runAsync { r => + for (cb <- stack) + try { + cb(r) + } catch { + // $COVERAGE-OFF$ + case NonFatal(e) => s.reportFailure(e) + // $COVERAGE-ON$ + } } + () }) -} \ No newline at end of file +} diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/FrameIndexRef.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/FrameIndexRef.scala index a33d4a1c3..bba5f8d96 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/FrameIndexRef.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/FrameIndexRef.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.eval package internal import monix.execution.ExecutionModel -import monix.execution.ExecutionModel.{AlwaysAsyncExecution, BatchedExecution, SynchronousExecution} +import monix.execution.ExecutionModel.{ AlwaysAsyncExecution, BatchedExecution, SynchronousExecution } import monix.execution.misc.ThreadLocal /** Internal API — A reference that boxes a `FrameIndex` possibly @@ -76,15 +76,15 @@ private[eval] object FrameIndexRef { case BatchedExecution(_) => new Local } - // Keeps our frame index in a thread-local +// Keeps our frame index in a thread-local private final class Local extends FrameIndexRef { - private[this] val local = ThreadLocal(1) + private val local = ThreadLocal(1) def apply(): FrameIndex = local.get() def `:=`(update: FrameIndex): Unit = local.set(update) def reset(): Unit = local.reset() } - // Dummy implementation that doesn't do anything +// Dummy implementation that doesn't do anything private object Dummy extends FrameIndexRef { def apply(): FrameIndex = 1 def `:=`(update: FrameIndex): Unit = () diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/LazyVal.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/LazyVal.scala index 4f0dae902..5b99bf957 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/LazyVal.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/LazyVal.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.eval.internal import monix.eval.Coeval -import monix.eval.Coeval.{Error, Now} +import monix.eval.Coeval.{ Error, Now } import scala.util.control.NonFatal /** `LazyVal` boxes a function and memoizes its result on its first invocation, @@ -37,8 +37,8 @@ import scala.util.control.NonFatal */ private[eval] final class LazyVal[A] private (f: () => A, val cacheErrors: Boolean) extends (() => Coeval.Eager[A]) { - private[this] var thunk = f - private[this] var cache: Coeval.Eager[A] = _ + private var thunk = f + private var cache: Coeval.Eager[A] = null.asInstanceOf[Coeval.Eager[A]] override def apply(): Coeval.Eager[A] = cache match { diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/StackFrame.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/StackFrame.scala index 54b0e1667..f85e1279a 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/StackFrame.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/StackFrame.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -37,8 +37,8 @@ private[eval] object StackFrame { } /** [[StackFrame]] reference that only handles errors, - * useful for quick filtering of `onErrorHandleWith` frames. - */ +* useful for quick filtering of `onErrorHandleWith` frames. +*/ final class ErrorHandler[-A, +R](fe: Throwable => R, fa: A => R) extends StackFrame[A, R] { def apply(a: A): R = fa(a) diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/StackTracedContext.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/StackTracedContext.scala index c6c1f8098..c898a69cd 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/StackTracedContext.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/StackTracedContext.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.eval.internal -import monix.eval.tracing.{TaskEvent, TaskTrace} +import monix.eval.tracing.{ TaskEvent, TaskTrace } import monix.eval.internal.TracingPlatform.traceBufferLogSize import monix.execution.internal.RingBuffer @@ -25,9 +25,9 @@ import monix.execution.internal.RingBuffer * All Credits to https://github.com/typelevel/cats-effect and https://github.com/RaasAhsan */ private[eval] final class StackTracedContext { - private[this] val events: RingBuffer[TaskEvent] = new RingBuffer(traceBufferLogSize) - private[this] var captured: Int = 0 - private[this] var omitted: Int = 0 + private val events: RingBuffer[TaskEvent] = new RingBuffer(traceBufferLogSize) + private var captured: Int = 0 + private var omitted: Int = 0 def pushEvent(fr: TaskEvent): Unit = { captured += 1 diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskBracket.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskBracket.scala index 9a3f5ac5d..2356a10ee 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskBracket.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskBracket.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,8 +18,8 @@ package monix.eval.internal import cats.effect.ExitCase -import cats.effect.ExitCase.{Canceled, Completed, Error} -import monix.eval.Task.{Context, ContextSwitch} +import cats.effect.ExitCase.{ Canceled, Completed, Error } +import monix.eval.Task.{ Context, ContextSwitch } import monix.execution.Callback import monix.eval.Task import monix.execution.atomic.Atomic @@ -27,11 +27,9 @@ import monix.execution.internal.Platform import scala.concurrent.Promise import scala.util.control.NonFatal -private[monix] object TaskBracket { - - // ----------------------------------------------------------------- - // Task.guaranteeCase - // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +private[monix] object TaskBracket { // ----------------------------------------------------------------- +// Task.guaranteeCase +// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= def guaranteeCase[A](task: Task[A], finalizer: ExitCase[Throwable] => Task[Unit]): Task[A] = TracedAsync( @@ -78,17 +76,18 @@ private[monix] object TaskBracket { releaseFn(ExitCase.Canceled) } - // ----------------------------------------------------------------- - // Task.bracketE - // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// ----------------------------------------------------------------- +// Task.bracketE +// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= /** - * [[monix.eval.Task.bracket]] and [[monix.eval.Task.bracketCase]] - */ + * [[monix.eval.Task.bracket]] and [[monix.eval.Task.bracketCase]] + */ def either[A, B]( acquire: Task[A], use: A => Task[B], - release: (A, Either[Option[Throwable], B]) => Task[Unit]): Task[B] = { + release: (A, Either[Option[Throwable], B]) => Task[Unit] + ): Task[B] = { TracedAsync( new StartE(acquire, use, release), @@ -102,8 +101,8 @@ private[monix] object TaskBracket { private final class StartE[A, B]( acquire: Task[A], use: A => Task[B], - release: (A, Either[Option[Throwable], B]) => Task[Unit]) - extends BaseStart(acquire, use) { + release: (A, Either[Option[Throwable], B]) => Task[Unit] + ) extends BaseStart(acquire, use) { def makeReleaseFrame(ctx: Context, value: A) = new ReleaseFrameE(ctx, value, release) @@ -122,13 +121,13 @@ private[monix] object TaskBracket { release(a, leftNone) } - // ----------------------------------------------------------------- - // Task.bracketCase - // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// ----------------------------------------------------------------- +// Task.bracketCase +// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= /** - * [[monix.eval.Task.bracketE]] - */ + * [[monix.eval.Task.bracketE]] + */ def exitCase[A, B](acquire: Task[A], use: A => Task[B], release: (A, ExitCase[Throwable]) => Task[Unit]): Task[B] = TracedAsync( new StartCase(acquire, use, release), @@ -141,8 +140,8 @@ private[monix] object TaskBracket { private final class StartCase[A, B]( acquire: Task[A], use: A => Task[B], - release: (A, ExitCase[Throwable]) => Task[Unit]) - extends BaseStart(acquire, use) { + release: (A, ExitCase[Throwable]) => Task[Unit] + ) extends BaseStart(acquire, use) { def makeReleaseFrame(ctx: Context, value: A) = new ReleaseFrameCase(ctx, value, release) @@ -161,9 +160,9 @@ private[monix] object TaskBracket { release(a, Canceled) } - // ----------------------------------------------------------------- - // Base Implementation - // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +// ----------------------------------------------------------------- +// Base Implementation +// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= private abstract class BaseStart[A, B](acquire: Task[A], use: A => Task[B]) extends ((Context, Callback[Throwable, B]) => Unit) { @@ -209,8 +208,8 @@ private[monix] object TaskBracket { } private abstract class BaseReleaseFrame[A, B](ctx: Context, a: A) extends StackFrame[B, Task[B]] { - private[this] val waitsForResult = Atomic(true) - private[this] val p: Promise[Unit] = Promise() + private val waitsForResult = Atomic(true) + private val p: Promise[Unit] = Promise() protected def releaseOnSuccess(a: A, b: B): Task[Unit] protected def releaseOnError(a: A, e: Throwable): Task[Unit] protected def releaseOnCancel(a: A): Task[Unit] @@ -254,7 +253,10 @@ private[monix] object TaskBracket { private final def unsafeApply(b: B): Task[B] = { if (waitsForResult.compareAndSet(expect = true, update = false)) - releaseOnSuccess(a, b).redeemWith(ex => Task(p.success(())).flatMap(_ => Task.raiseError(ex)), _ => Task{p.success(()); b}) + releaseOnSuccess(a, b).redeemWith( + ex => Task(p.success(())).flatMap(_ => Task.raiseError(ex)), + _ => Task { p.success(()); b } + ) else Task.never @@ -288,12 +290,10 @@ private[monix] object TaskBracket { private val leftNone = Left(None) - private[this] val withConnectionUncancelable: Context => Context = - _.withConnection(TaskConnection.uncancelable) + private val withConnectionUncancelable: Context => Context = _.withConnection(TaskConnection.uncancelable) - private[this] val disableUncancelableAndPop: (Any, Throwable, Context, Context) => Context = - (_, _, old, _) => { - old.connection.pop() - old - } + private val disableUncancelableAndPop: (Any, Throwable, Context, Context) => Context = (_, _, old, _) => { + val _ = old.connection.pop() + old + } } diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskCancellation.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskCancellation.scala index a59e00775..df93b60eb 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskCancellation.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskCancellation.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,21 +19,21 @@ package monix.eval package internal import cats.effect.CancelToken -import monix.eval.Task.{Async, Context} -import monix.execution.{Callback, Scheduler} -import monix.execution.atomic.{Atomic, AtomicBoolean} +import monix.eval.Task.{ Async, Context } +import monix.execution.{ Callback, Scheduler } +import monix.execution.atomic.{ Atomic, AtomicBoolean } import monix.execution.schedulers.TrampolinedRunnable private[eval] object TaskCancellation { /** - * Implementation for `Task.uncancelable`. - */ +* Implementation for `Task.uncancelable`. +*/ def uncancelable[A](fa: Task[A]): Task[A] = Task.ContextSwitch(fa, withConnectionUncancelable, restoreConnection) /** - * Implementation for `Task.onCancelRaiseError`. - */ +* Implementation for `Task.onCancelRaiseError`. +*/ def raiseError[A](fa: Task[A], e: Throwable): Task[A] = { val start = (ctx: Context, cb: Callback[Throwable, A]) => { implicit val sc = ctx.scheduler @@ -60,8 +60,8 @@ private[eval] object TaskCancellation { )(implicit s: Scheduler) extends Callback[Throwable, A] with TrampolinedRunnable { - private[this] var value: A = _ - private[this] var error: Throwable = _ + private var value: A = null.asInstanceOf[A] + private var error: Throwable = null.asInstanceOf[Throwable] def run(): Unit = { val e = error @@ -71,14 +71,14 @@ private[eval] object TaskCancellation { def onSuccess(value: A): Unit = if (waitsForResult.getAndSet(false)) { - conn.pop() + val _ = conn.pop() this.value = value s.execute(this) } def onError(e: Throwable): Unit = if (waitsForResult.getAndSet(false)) { - conn.pop() + val _ = conn.pop() this.error = e s.execute(this) } else { @@ -91,27 +91,26 @@ private[eval] object TaskCancellation { conn: TaskConnection, conn2: TaskConnection, cb: Callback[Throwable, A], - e: Throwable): CancelToken[Task] = { - + e: Throwable + ): CancelToken[Task] = { Task.suspend { if (waitsForResult.getAndSet(false)) conn2.cancel.map { _ => - conn.tryReactivate() + val _ = conn.tryReactivate() cb.onError(e) - } else + } + else Task.unit } } - private[this] val withConnectionUncancelable: Context => Context = - ct => { - ct.withConnection(TaskConnection.uncancelable) - .withOptions(ct.options.disableAutoCancelableRunLoops) - } + private val withConnectionUncancelable: Context => Context = ct => { + ct.withConnection(TaskConnection.uncancelable) + .withOptions(ct.options.disableAutoCancelableRunLoops) + } - private[this] val restoreConnection: (Any, Throwable, Context, Context) => Context = - (_, _, old, ct) => { - ct.withConnection(old.connection) - .withOptions(old.options) - } + private val restoreConnection: (Any, Throwable, Context, Context) => Context = (_, _, old, ct) => { + ct.withConnection(old.connection) + .withOptions(old.options) + } } diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskConnection.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskConnection.scala index b843e76c9..0a0d0fd97 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskConnection.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskConnection.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,8 +20,8 @@ package internal import cats.effect.CancelToken import monix.catnap.CancelableF -import monix.execution.atomic.{Atomic, PaddingStrategy} -import monix.execution.{Cancelable, Scheduler} +import monix.execution.atomic.{ Atomic, PaddingStrategy } +import monix.execution.{ Cancelable, Scheduler } import scala.annotation.tailrec import scala.concurrent.Promise @@ -123,9 +123,9 @@ private[eval] object TaskConnection { new Impl /** - * Reusable [[TaskConnection]] reference that cannot - * be canceled. - */ +* Reusable [[TaskConnection]] reference that cannot +* be canceled. +*/ val uncancelable: TaskConnection = new Uncancelable @@ -143,11 +143,10 @@ private[eval] object TaskConnection { } private final class Impl extends TaskConnection { self => - private[this] val state = - Atomic.withPadding( - (List.empty[AnyRef], Promise[Unit]()), - PaddingStrategy.LeftRight128 - ) + private val state = Atomic.withPadding( + (List.empty[AnyRef], Promise[Unit]()), + PaddingStrategy.LeftRight128 + ) val cancel = Task.suspend { state.transformAndExtract { diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskConnectionComposite.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskConnectionComposite.scala index ed5e64058..bfcdcfc0d 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskConnectionComposite.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskConnectionComposite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,10 +20,10 @@ package monix.eval.internal import cats.effect.CancelToken import monix.catnap.CancelableF import monix.eval.Task -import monix.eval.internal.TaskConnectionComposite.{Active, Cancelled, State} -import monix.execution.{Cancelable, Scheduler} +import monix.eval.internal.TaskConnectionComposite.{ Active, Cancelled, State } +import monix.execution.{ Cancelable, Scheduler } import monix.execution.atomic.PaddingStrategy.LeftRight128 -import monix.execution.atomic.{Atomic, AtomicAny} +import monix.execution.atomic.{ Atomic, AtomicAny } import scala.annotation.tailrec @@ -73,7 +73,8 @@ private[eval] final class TaskConnectionComposite private (stateRef: AtomicAny[S @tailrec private def addAny(ref: AnyRef /* CancelToken[Task] | CancelableF[Task] | Cancelable */ )( - implicit s: Scheduler): Unit = { + implicit s: Scheduler + ): Unit = { stateRef.get() match { case Cancelled => @@ -144,10 +145,10 @@ private[eval] final class TaskConnectionComposite private (stateRef: AtomicAny[S private[eval] object TaskConnectionComposite { /** - * Builder for [[TaskConnectionComposite]]. - */ +* Builder for [[TaskConnectionComposite]]. +*/ def apply(initial: CancelToken[Task]*): TaskConnectionComposite = - new TaskConnectionComposite(Atomic.withPadding(Active(Set(initial: _*)): State, LeftRight128)) + new TaskConnectionComposite(Atomic.withPadding(Active(Set(initial*)): State, LeftRight128)) private sealed abstract class State private final case class Active(set: Set[AnyRef /* CancelToken[Task] | CancelableF[Task] | Cancelable */ ]) diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskConnectionRef.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskConnectionRef.scala index 7bf762e6c..4487e2b34 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskConnectionRef.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskConnectionRef.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package internal import cats.effect.CancelToken import monix.catnap.CancelableF -import monix.execution.{Cancelable, Scheduler} +import monix.execution.{ Cancelable, Scheduler } import monix.execution.atomic.Atomic import scala.annotation.tailrec @@ -41,7 +41,8 @@ private[eval] final class TaskConnectionRef extends CancelableF[Task] { @tailrec private def unsafeSet(ref: AnyRef /* CancelToken[Task] | CancelableF[Task] | Cancelable */ )( - implicit s: Scheduler): Unit = { + implicit s: Scheduler + ): Unit = { if (!state.compareAndSet(Empty, IsActive(ref))) { state.get() match { @@ -87,16 +88,17 @@ private[eval] final class TaskConnectionRef extends CancelableF[Task] { private def raiseError(): Nothing = { throw new IllegalStateException( "Cannot assign to SingleAssignmentCancelable, " + - "as it was already assigned once") + "as it was already assigned once" + ) } - private[this] val state = Atomic(Empty: State) + private val state = Atomic(Empty: State) } private[eval] object TaskConnectionRef { /** - * Returns a new `TaskForwardConnection` reference. - */ +* Returns a new `TaskForwardConnection` reference. +*/ def apply(): TaskConnectionRef = new TaskConnectionRef() private sealed trait State diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskConversions.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskConversions.scala index 1776618b0..e59d21677 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskConversions.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskConversions.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,15 +23,15 @@ import monix.execution.Callback import monix.eval.Task import monix.execution.Scheduler import monix.execution.schedulers.TrampolinedRunnable -import org.reactivestreams.{Publisher, Subscriber} +import org.reactivestreams.{ Publisher, Subscriber } import monix.execution.rstreams.SingleAssignSubscription import scala.util.control.NonFatal private[eval] object TaskConversions { /** - * Implementation for `Task#toIO`. - */ +* Implementation for `Task#toIO`. +*/ def toIO[A](source: Task[A])(implicit eff: ConcurrentEffect[Task]): IO[A] = source match { case Task.Now(value) => IO.pure(value) @@ -44,8 +44,8 @@ private[eval] object TaskConversions { } /** - * Implementation for `Task#toConcurrent`. - */ +* Implementation for `Task#toConcurrent`. +*/ def toConcurrent[F[_], A](source: Task[A])(implicit F: Concurrent[F], eff: ConcurrentEffect[Task]): F[A] = source match { case Task.Now(value) => F.pure(value) @@ -59,8 +59,8 @@ private[eval] object TaskConversions { } /** - * Implementation for `Task#toAsync`. - */ +* Implementation for `Task#toAsync`. +*/ def toAsync[F[_], A](source: Task[A])(implicit F: Async[F], eff: Effect[Task]): F[A] = source match { case Task.Now(value) => F.pure(value) @@ -73,8 +73,8 @@ private[eval] object TaskConversions { } /** - * Implementation for `Task.from`. - */ +* Implementation for `Task.from`. +*/ def fromEffect[F[_], A](fa: F[A])(implicit F: Effect[F]): Task[A] = fa.asInstanceOf[AnyRef] match { case ref: Task[A] @unchecked => ref @@ -101,8 +101,8 @@ private[eval] object TaskConversions { } /** - * Implementation for `Task.fromConcurrent`. - */ +* Implementation for `Task.fromConcurrent`. +*/ def fromConcurrentEffect[F[_], A](fa: F[A])(implicit F: ConcurrentEffect[F]): Task[A] = fa.asInstanceOf[AnyRef] match { case ref: Task[A] @unchecked => ref @@ -111,14 +111,14 @@ private[eval] object TaskConversions { } /** - * Implementation for `Task.fromReactivePublisher`. - */ +* Implementation for `Task.fromReactivePublisher`. +*/ def fromReactivePublisher[A](source: Publisher[A]): Task[Option[A]] = Task.cancelable0 { (scheduler, cb) => val sub = SingleAssignSubscription() source.subscribe(new Subscriber[A] { - private[this] var isActive = true + private var isActive = true def onSubscribe(s: org.reactivestreams.Subscription): Unit = { sub := s @@ -159,7 +159,7 @@ private[eval] object TaskConversions { implicit val sc = ctx.scheduler val conn = ctx.connection val cancelable = TaskConnectionRef() - conn push cancelable.cancel + conn.push(cancelable.cancel) val syncIO = F.runCancelable(fa)(new CreateCallback[A](conn, cb)) cancelable := fromEffect(syncIO.unsafeRunSync(): F[Unit]) @@ -178,13 +178,15 @@ private[eval] object TaskConversions { private final class CreateCallback[A](conn: TaskConnection, cb: Callback[Throwable, A])(implicit s: Scheduler) extends (Either[Throwable, A] => IO[Unit]) with TrampolinedRunnable { - private[this] var canCall = true - private[this] var value: Either[Throwable, A] = _ + private var canCall = true + private var value: Either[Throwable, A] = null.asInstanceOf[Either[Throwable, A]] def run(): Unit = { if (canCall) { canCall = false - if (conn ne null) conn.pop() + if (conn ne null) { + val _ = conn.pop() + } cb(value) value = null } diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskCreate.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskCreate.scala index 0fe10a715..fd6feb770 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskCreate.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskCreate.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,27 +19,27 @@ package monix.eval.internal import java.util.concurrent.RejectedExecutionException -import cats.effect.{CancelToken, IO} +import cats.effect.{ CancelToken, IO } import monix.eval.Task.Context -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.atomic.AtomicInt import monix.execution.exceptions.CallbackCalledMultipleTimesException import monix.execution.internal.Platform -import monix.execution.schedulers.{StartAsyncBatchRunnable, TrampolinedRunnable} -import monix.execution.{Callback, Cancelable, Scheduler, UncaughtExceptionReporter} +import monix.execution.schedulers.{ StartAsyncBatchRunnable, TrampolinedRunnable } +import monix.execution.{ Callback, Cancelable, Scheduler, UncaughtExceptionReporter } import scala.util.control.NonFatal private[eval] object TaskCreate { /** - * Implementation for `cats.effect.Concurrent#cancelable`. - */ +* Implementation for `cats.effect.Concurrent#cancelable`. +*/ def cancelableEffect[A](k: (Either[Throwable, A] => Unit) => CancelToken[Task]): Task[A] = cancelable0((_, cb) => k(cb)) /** - * Implementation for `Task.cancelable` - */ +* Implementation for `Task.cancelable` +*/ def cancelable0[A](fn: (Scheduler, Callback[Throwable, A]) => CancelToken[Task]): Task[A] = { val start = new Cancelable0Start[A, CancelToken[Task]](fn) { def setConnection(ref: TaskConnectionRef, token: CancelToken[Task])(implicit s: Scheduler): Unit = @@ -49,14 +49,14 @@ private[eval] object TaskCreate { } /** - * Implementation for `Task.create`, used via `TaskBuilder`. - */ +* Implementation for `Task.create`, used via `TaskBuilder`. +*/ def cancelableIO[A](start: (Scheduler, Callback[Throwable, A]) => CancelToken[IO]): Task[A] = cancelable0((sc, cb) => Task.from(start(sc, cb))) /** - * Implementation for `Task.create`, used via `TaskBuilder`. - */ +* Implementation for `Task.create`, used via `TaskBuilder`. +*/ def cancelableCancelable[A](fn: (Scheduler, Callback[Throwable, A]) => Cancelable): Task[A] = { val start = new Cancelable0Start[A, Cancelable](fn) { def setConnection(ref: TaskConnectionRef, token: Cancelable)(implicit s: Scheduler): Unit = @@ -66,14 +66,14 @@ private[eval] object TaskCreate { } /** - * Implementation for `Task.create`, used via `TaskBuilder`. - */ +* Implementation for `Task.create`, used via `TaskBuilder`. +*/ def cancelableCoeval[A](start: (Scheduler, Callback[Throwable, A]) => Coeval[Unit]): Task[A] = cancelable0((sc, cb) => Task.from(start(sc, cb))) /** - * Implementation for `Task.async0` - */ +* Implementation for `Task.async0` +*/ def async0[A](fn: (Scheduler, Callback[Throwable, A]) => Any): Task[A] = { val start = (ctx: Context, cb: Callback[Throwable, A]) => { implicit val s = ctx.scheduler @@ -92,11 +92,11 @@ private[eval] object TaskCreate { } /** - * Implementation for `cats.effect.Async#async`. - * - * It duplicates the implementation of `Task.async0` with the purpose - * of avoiding extraneous callback allocations. - */ +* Implementation for `cats.effect.Async#async`. +* +* It duplicates the implementation of `Task.async0` with the purpose +* of avoiding extraneous callback allocations. +*/ def async[A](k: Callback[Throwable, A] => Unit): Task[A] = { val start = (ctx: Context, cb: Callback[Throwable, A]) => { implicit val s = ctx.scheduler @@ -114,8 +114,8 @@ private[eval] object TaskCreate { } /** - * Implementation for `Task.asyncF`. - */ +* Implementation for `Task.asyncF`. +*/ def asyncF[A](k: Callback[Throwable, A] => Task[Unit]): Task[A] = { val start = (ctx: Context, cb: Callback[Throwable, A]) => { implicit val s = ctx.scheduler @@ -149,7 +149,7 @@ private[eval] object TaskCreate { implicit val s = ctx.scheduler val conn = ctx.connection val cancelable = TaskConnectionRef() - conn push cancelable.cancel + conn.push(cancelable.cancel) val cbProtected = new CallbackForCreate(ctx, shouldPop = true, cb) try { @@ -166,7 +166,7 @@ private[eval] object TaskCreate { } } - private final class ForwardErrorCallback(cb: Callback[Throwable, _])(implicit r: UncaughtExceptionReporter) + private final class ForwardErrorCallback(cb: Callback[Throwable, ?])(implicit r: UncaughtExceptionReporter) extends Callback[Throwable, Unit] { override def onSuccess(value: Unit): Unit = () @@ -179,10 +179,10 @@ private[eval] object TaskCreate { private final class CallbackForCreate[A](ctx: Context, threadId: Long, shouldPop: Boolean, cb: Callback[Throwable, A]) extends Callback[Throwable, A] with TrampolinedRunnable { - private[this] val state = AtomicInt(0) - private[this] var value: A = _ - private[this] var error: Throwable = _ - private[this] var isSameThread = false + private val state = AtomicInt(0) + private var value: A = null.asInstanceOf[A] + private var error: Throwable = null.asInstanceOf[Throwable] + private var isSameThread = false def this(ctx: Context, shouldPop: Boolean, cb: Callback[Throwable, A]) = this(ctx, Platform.currentThreadId(), shouldPop, cb) @@ -219,7 +219,9 @@ private[eval] object TaskCreate { private def startExecution(): Unit = { // Cleanup of the current finalizer - if (shouldPop) ctx.connection.pop() + if (shouldPop) { + val _ = ctx.connection.pop() + } // Optimization — if the callback was called on the same thread // where it was created, then we are not going to fork // This is not safe to do when localContextPropagation enabled diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskDeferAction.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskDeferAction.scala index 49e7f8634..1b9650299 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskDeferAction.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskDeferAction.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskDeprecated.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskDeprecated.scala index 3bd9b0ef8..f807c47b3 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskDeprecated.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskDeprecated.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,26 +18,26 @@ package monix.eval package internal -import cats.effect.{ConcurrentEffect, IO} +import cats.effect.{ ConcurrentEffect, IO } import monix.eval.Task.Options import monix.execution.annotations.UnsafeBecauseImpure import monix.execution.compat.BuildFrom -import monix.execution.{Callback, Cancelable, CancelableFuture, Scheduler} +import monix.execution.{ Callback, Cancelable, CancelableFuture, Scheduler } import scala.annotation.unchecked.uncheckedVariance -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } private[eval] object TaskDeprecated { /** - * BinCompat trait describing deprecated `Task` operations. - */ +* BinCompat trait describing deprecated `Task` operations. +*/ private[eval] trait BinCompat[+A] { self: Task[A] => /** - * DEPRECATED — subsumed by [[Task.startAndForget startAndForget]]. - * - * Renamed to `startAndForget` to be consistent with `start` which - * also enforces an asynchronous boundary - */ +* DEPRECATED — subsumed by [[Task.startAndForget startAndForget]]. +* +* Renamed to `startAndForget` to be consistent with `start` which +* also enforces an asynchronous boundary +*/ @deprecated("Replaced with startAndForget", since = "3.0.0") def forkAndForget: Task[Unit] = { // $COVERAGE-OFF$ @@ -47,18 +47,18 @@ private[eval] object TaskDeprecated { } /** - * Extension methods describing deprecated `Task` operations. - */ +* Extension methods describing deprecated `Task` operations. +*/ private[eval] trait Extensions[+A] extends Any { def self: Task[A] /** - * DEPRECATED — renamed to [[Task.runToFuture runToFuture]], otherwise - * due to overloading we can get a pretty bad conflict with the - * callback-driven [[Task.runAsync]]. - * - * The naming is also nice for discovery. - */ +* DEPRECATED — renamed to [[Task.runToFuture runToFuture]], otherwise +* due to overloading we can get a pretty bad conflict with the +* callback-driven [[Task.runAsync]]. +* +* The naming is also nice for discovery. +*/ @UnsafeBecauseImpure @deprecated("Renamed to Task.runToFuture", since = "3.0.0") def runAsync(implicit s: Scheduler): CancelableFuture[A] = { @@ -68,12 +68,12 @@ private[eval] object TaskDeprecated { } /** - * DEPRECATED — renamed to [[Task.runToFutureOpt runAsyncOpt]], - * otherwise due to overloading we can get a pretty bad conflict with the - * callback-driven [[Task.runToFutureOpt]]. - * - * The naming is also nice for discovery. - */ +* DEPRECATED — renamed to [[Task.runToFutureOpt runAsyncOpt]], +* otherwise due to overloading we can get a pretty bad conflict with the +* callback-driven [[Task.runToFutureOpt]]. +* +* The naming is also nice for discovery. +*/ @UnsafeBecauseImpure @deprecated("Renamed to Task.runAsyncOpt", since = "3.0.0") def runAsyncOpt(implicit s: Scheduler, opts: Task.Options): CancelableFuture[A] = { @@ -83,17 +83,17 @@ private[eval] object TaskDeprecated { } /** - * DEPRECATED — switch to [[Task.runSyncStep]] or to [[Task.runToFuture]]. - * - * The [[Task.runToFuture runToFuture]] operation that returns - * [[monix.execution.CancelableFuture CancelableFuture]] will - * return already completed future values, useful for low level - * optimizations. All this `runSyncMaybe` did was to piggyback - * on it. - * - * The reason for the deprecation is to reduce the unneeded - * "run" overloads. - */ +* DEPRECATED — switch to [[Task.runSyncStep]] or to [[Task.runToFuture]]. +* +* The [[Task.runToFuture runToFuture]] operation that returns +* [[monix.execution.CancelableFuture CancelableFuture]] will +* return already completed future values, useful for low level +* optimizations. All this `runSyncMaybe` did was to piggyback +* on it. +* +* The reason for the deprecation is to reduce the unneeded +* "run" overloads. +*/ @UnsafeBecauseImpure @deprecated("Please use `Task.runSyncStep`", since = "3.0.0") def runSyncMaybe(implicit s: Scheduler): Either[CancelableFuture[A], A] = { @@ -103,18 +103,18 @@ private[eval] object TaskDeprecated { } /** - * DEPRECATED — switch to [[Task.runSyncStepOpt]] or to - * [[Task.runToFutureOpt(implicit* runAsync]]. - * - * The [[Task.runToFutureOpt(implicit* runAsyncOpt]] variant that returns - * [[monix.execution.CancelableFuture CancelableFuture]] will - * return already completed future values, useful for low level - * optimizations. All this `runSyncMaybeOpt` did was to piggyback - * on it. - * - * The reason for the deprecation is to reduce the unneeded - * "run" overloads. - */ +* DEPRECATED — switch to [[Task.runSyncStepOpt]] or to +* [[Task.runToFutureOpt(implicit* runAsync]]. +* +* The [[Task.runToFutureOpt(implicit* runAsyncOpt]] variant that returns +* [[monix.execution.CancelableFuture CancelableFuture]] will +* return already completed future values, useful for low level +* optimizations. All this `runSyncMaybeOpt` did was to piggyback +* on it. +* +* The reason for the deprecation is to reduce the unneeded +* "run" overloads. +*/ @UnsafeBecauseImpure @deprecated("Please use `Task.runAsyncOpt`", since = "3.0.0") def runSyncMaybeOpt(implicit s: Scheduler, opts: Options): Either[CancelableFuture[A], A] = { @@ -123,7 +123,7 @@ private[eval] object TaskDeprecated { // $COVERAGE-ON$ } - private[this] def runSyncMaybeOptPrv(implicit s: Scheduler, opts: Options): Either[CancelableFuture[A], A] = { + private def runSyncMaybeOptPrv(implicit s: Scheduler, opts: Options): Either[CancelableFuture[A], A] = { // $COVERAGE-OFF$ val future = self.runToFutureOpt(s, opts) future.value match { @@ -139,21 +139,21 @@ private[eval] object TaskDeprecated { } /** - * DEPRECATED — switch to [[Task.runToFuture]] in combination - * with [[monix.execution.Callback.fromTry Callback.fromTry]] - * instead. - * - * If for example you have a `Try[A] => Unit` function, you can - * replace usage of `runOnComplete` with: - * - * `task.runAsync(Callback.fromTry(f))` - * - * A more common usage is via Scala's `Promise`, but with - * a `Promise` reference this construct would be even more - * efficient: - * - * `task.runAsync(Callback.fromPromise(p))` - */ +* DEPRECATED — switch to [[Task.runToFuture]] in combination +* with [[monix.execution.Callback.fromTry Callback.fromTry]] +* instead. +* +* If for example you have a `Try[A] => Unit` function, you can +* replace usage of `runOnComplete` with: +* +* `task.runAsync(Callback.fromTry(f))` +* +* A more common usage is via Scala's `Promise`, but with +* a `Promise` reference this construct would be even more +* efficient: +* +* `task.runAsync(Callback.fromPromise(p))` +*/ @UnsafeBecauseImpure @deprecated("Please use `Task.runAsync`", since = "3.0.0") def runOnComplete(f: Try[A] => Unit)(implicit s: Scheduler): Cancelable = { @@ -163,11 +163,11 @@ private[eval] object TaskDeprecated { } /** DEPRECATED — use [[Task.redeem redeem]] instead. - * - * [[Task.redeem]] is the same operation, but with a different name and the - * function parameters in an inverted order, to make it consistent with `fold` - * on `Either` and others (i.e. the function for error recovery is at the left). - */ +* +* [[Task.redeem]] is the same operation, but with a different name and the +* function parameters in an inverted order, to make it consistent with `fold` +* on `Either` and others (i.e. the function for error recovery is at the left). +*/ @deprecated("Please use `Task.redeem`", since = "3.0.0-RC2") def transform[R](fa: A => R, fe: Throwable => R): Task[R] = { // $COVERAGE-OFF$ @@ -176,11 +176,11 @@ private[eval] object TaskDeprecated { } /** DEPRECATED — use [[Task.redeemWith redeemWith]] instead. - * - * [[Task.redeemWith]] is the same operation, but with a different name and the - * function parameters in an inverted order, to make it consistent with `fold` - * on `Either` and others (i.e. the function for error recovery is at the left). - */ +* +* [[Task.redeemWith]] is the same operation, but with a different name and the +* function parameters in an inverted order, to make it consistent with `fold` +* on `Either` and others (i.e. the function for error recovery is at the left). +*/ @deprecated("Please use `Task.redeemWith`", since = "3.0.0-RC2") def transformWith[R](fa: A => Task[R], fe: Throwable => Task[R]): Task[R] = { // $COVERAGE-OFF$ @@ -189,8 +189,8 @@ private[eval] object TaskDeprecated { } /** - * DEPRECATED — switch to [[Task.parZip2]], which has the same behavior. - */ +* DEPRECATED — switch to [[Task.parZip2]], which has the same behavior. +*/ @deprecated("Switch to Task.parZip2", since = "3.0.0-RC2") def zip[B](that: Task[B]): Task[(A, B)] = { // $COVERAGE-OFF$ @@ -199,16 +199,16 @@ private[eval] object TaskDeprecated { } /** - * DEPRECATED — switch to [[Task.parMap2]], which has the same behavior. - */ +* DEPRECATED — switch to [[Task.parMap2]], which has the same behavior. +*/ @deprecated("Use Task.parMap2", since = "3.0.0-RC2") def zipMap[B, C](that: Task[B])(f: (A, B) => C): Task[C] = Task.mapBoth(self, that)(f) /** DEPRECATED — renamed to [[Task.executeAsync executeAsync]]. - * - * The reason for the deprecation is the repurposing of the word "fork". - */ +* +* The reason for the deprecation is the repurposing of the word "fork". +*/ @deprecated("Renamed to Task!.executeAsync", "3.0.0") def executeWithFork: Task[A] = { // $COVERAGE-OFF$ @@ -217,25 +217,25 @@ private[eval] object TaskDeprecated { } /** DEPRECATED — please use [[Task.flatMap flatMap]]. - * - * The reason for the deprecation is that this operation is - * redundant, as it can be expressed with `flatMap`, with the - * same effect: - * {{{ - * import monix.eval.Task - * - * val trigger = Task(println("do it")) - * val task = Task(println("must be done now")) - * trigger.flatMap(_ => task) - * }}} - * - * The syntax provided by Cats can also help: - * {{{ - * import cats.syntax.all._ - * - * trigger *> task - * }}} - */ +* +* The reason for the deprecation is that this operation is +* redundant, as it can be expressed with `flatMap`, with the +* same effect: +* {{{ +* import monix.eval.Task +* +* val trigger = Task(println("do it")) +* val task = Task(println("must be done now")) +* trigger.flatMap(_ => task) +* }}} +* +* The syntax provided by Cats can also help: +* {{{ +* import cats.syntax.all._ +* +* trigger *> task +* }}} +*/ @deprecated("Please use flatMap", "3.0.0") def delayExecutionWith(trigger: Task[Any]): Task[A] = { // $COVERAGE-OFF$ @@ -244,19 +244,19 @@ private[eval] object TaskDeprecated { } /** DEPRECATED — please use [[Task.flatMap flatMap]]. - * - * The reason for the deprecation is that this operation is - * redundant, as it can be expressed with `flatMap` and `map`, - * with the same effect: - * - * {{{ - * import monix.eval.Task - * - * val task = Task(5) - * val selector = (n: Int) => Task(n.toString) - * task.flatMap(a => selector(a).map(_ => a)) - * }}} - */ +* +* The reason for the deprecation is that this operation is +* redundant, as it can be expressed with `flatMap` and `map`, +* with the same effect: +* +* {{{ +* import monix.eval.Task +* +* val task = Task(5) +* val selector = (n: Int) => Task(n.toString) +* task.flatMap(a => selector(a).map(_ => a)) +* }}} +*/ @deprecated("Please rewrite in terms of flatMap", "3.0.0") def delayResultBySelector[B](selector: A => Task[B]): Task[A] = { // $COVERAGE-OFF$ @@ -265,13 +265,13 @@ private[eval] object TaskDeprecated { } /** - * DEPRECATED — since Monix 3.0 the `Task` implementation has switched - * to auto-cancelable run-loops by default (which can still be turned off - * in its configuration). - * - * For ensuring the old behavior, you can use - * [[Task.executeWithOptions executeWithOptions]]. - */ +* DEPRECATED — since Monix 3.0 the `Task` implementation has switched +* to auto-cancelable run-loops by default (which can still be turned off +* in its configuration). +* +* For ensuring the old behavior, you can use +* [[Task.executeWithOptions executeWithOptions]]. +*/ @deprecated("Switch to executeWithOptions(_.enableAutoCancelableRunLoops)", "3.0.0") def cancelable: Task[A] = { // $COVERAGE-OFF$ @@ -280,12 +280,12 @@ private[eval] object TaskDeprecated { } /** - * DEPRECATED — subsumed by [[Task.start start]]. - * - * To be consistent with cats-effect 1.1.0, `start` now - * enforces an asynchronous boundary, being exactly the same - * as `fork` from 3.0.0-RC1 - */ +* DEPRECATED — subsumed by [[Task.start start]]. +* +* To be consistent with cats-effect 1.1.0, `start` now +* enforces an asynchronous boundary, being exactly the same +* as `fork` from 3.0.0-RC1 +*/ @deprecated("Replaced with start", since = "3.0.0-RC2") def fork: Task[Fiber[A @uncheckedVariance]] = { // $COVERAGE-OFF$ @@ -294,9 +294,9 @@ private[eval] object TaskDeprecated { } /** DEPRECATED — replace with usage of [[Task.runSyncStep]]: - * - * `task.coeval <-> Coeval(task.runSyncStep)` - */ +* +* `task.coeval <-> Coeval(task.runSyncStep)` +*/ @deprecated("Replaced with Coeval(task.runSyncStep)", since = "3.0.0-RC2") def coeval(implicit s: Scheduler): Coeval[Either[CancelableFuture[A], A]] = { // $COVERAGE-OFF$ @@ -305,16 +305,16 @@ private[eval] object TaskDeprecated { } /** - * DEPRECATED — replace with usage of [[Task.to]]: - * - * {{{ - * import cats.effect.IO - * import monix.execution.Scheduler.Implicits.global - * import monix.eval.Task - * - * Task(1 + 1).to[IO] - * }}} - */ +* DEPRECATED — replace with usage of [[Task.to]]: +* +* {{{ +* import cats.effect.IO +* import monix.execution.Scheduler.Implicits.global +* import monix.eval.Task +* +* Task(1 + 1).to[IO] +* }}} +*/ @deprecated("Switch to task.to[IO]", since = "3.0.0-RC3") def toIO(implicit eff: ConcurrentEffect[Task]): IO[A] = { // $COVERAGE-OFF$ @@ -355,7 +355,8 @@ private[eval] object TaskDeprecated { fa2: Task[A2], fa3: Task[A3], fa4: Task[A4], - fa5: Task[A5]): Task[(A1, A2, A3, A4, A5)] = { + fa5: Task[A5] + ): Task[(A1, A2, A3, A4, A5)] = { // $COVERAGE-OFF$ Task.parZip5(fa1, fa2, fa3, fa4, fa5) // $COVERAGE-ON$ @@ -369,16 +370,17 @@ private[eval] object TaskDeprecated { fa3: Task[A3], fa4: Task[A4], fa5: Task[A5], - fa6: Task[A6]): Task[(A1, A2, A3, A4, A5, A6)] = { + fa6: Task[A6] + ): Task[(A1, A2, A3, A4, A5, A6)] = { // $COVERAGE-OFF$ Task.parZip6(fa1, fa2, fa3, fa4, fa5, fa6) // $COVERAGE-ON$ } /** DEPRECATED — please use [[Task!.executeAsync .executeAsync]]. - * - * The reason for the deprecation is the repurposing of the word "fork". - */ +* +* The reason for the deprecation is the repurposing of the word "fork". +*/ @deprecated("Please use Task!.executeAsync", "3.0.0") def fork[A](fa: Task[A]): Task[A] = { // $COVERAGE-OFF$ @@ -387,9 +389,9 @@ private[eval] object TaskDeprecated { } /** DEPRECATED — please use [[Task.executeOn .executeOn]]. - * - * The reason for the deprecation is the repurposing of the word "fork". - */ +* +* The reason for the deprecation is the repurposing of the word "fork". +*/ @deprecated("Please use Task!.executeOn", "3.0.0") def fork[A](fa: Task[A], s: Scheduler): Task[A] = { // $COVERAGE-OFF$ @@ -398,8 +400,8 @@ private[eval] object TaskDeprecated { } /** - * DEPRECATED — please use [[Task.from]]. - */ +* DEPRECATED — please use [[Task.from]]. +*/ @deprecated("Please use Task.from", "3.0.0") def fromEval[A](a: cats.Eval[A]): Task[A] = { // $COVERAGE-OFF$ @@ -408,8 +410,8 @@ private[eval] object TaskDeprecated { } /** - * DEPRECATED — please use [[Task.from]]. - */ +* DEPRECATED — please use [[Task.from]]. +*/ @deprecated("Please use Task.from", "3.0.0") def fromIO[A](ioa: IO[A]): Task[A] = { // $COVERAGE-OFF$ @@ -443,7 +445,9 @@ private[eval] object TaskDeprecated { /** DEPRECATED — renamed to [[Task.parTraverse]] */ @deprecated("Use parTraverse", "3.2.0") - def wander[A, B, M[X] <: Iterable[X]](in: M[A])(f: A => Task[B])(implicit bf: BuildFrom[M[A], B, M[B]]): Task[M[B]] = { + def wander[A, B, M[X] <: Iterable[X]](in: M[A])(f: A => Task[B])(implicit + bf: BuildFrom[M[A], B, M[B]] + ): Task[M[B]] = { // $COVERAGE-OFF$ Task.parTraverse(in)(f) // $COVERAGE-ON$ diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskDoOnCancel.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskDoOnCancel.scala index dab2d809d..9107f97e6 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskDoOnCancel.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskDoOnCancel.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.eval.internal -import monix.eval.Task.{Async, Context} +import monix.eval.Task.{ Async, Context } import monix.execution.Callback import monix.eval.Task import monix.execution.exceptions.CallbackCalledMultipleTimesException @@ -25,8 +25,8 @@ import monix.execution.schedulers.TrampolinedRunnable private[eval] object TaskDoOnCancel { /** - * Implementation for `Task.doOnCancel` - */ +* Implementation for `Task.doOnCancel` +*/ def apply[A](self: Task[A], callback: Task[Unit]): Task[A] = { if (callback eq Task.unit) { self @@ -43,9 +43,9 @@ private[eval] object TaskDoOnCancel { private final class CallbackThatPops[A](ctx: Task.Context, cb: Callback[Throwable, A]) extends Callback[Throwable, A] with TrampolinedRunnable { - private[this] var isActive = true - private[this] var value: A = _ - private[this] var error: Throwable = _ + private var isActive = true + private var value: A = null.asInstanceOf[A] + private var error: Throwable = null.asInstanceOf[Throwable] override def onSuccess(value: A): Unit = if (!tryOnSuccess(value)) { @@ -60,7 +60,7 @@ private[eval] object TaskDoOnCancel { override def tryOnSuccess(value: A): Boolean = { if (isActive) { isActive = false - ctx.connection.pop() + val _ = ctx.connection.pop() this.value = value ctx.scheduler.execute(this) true @@ -72,7 +72,7 @@ private[eval] object TaskDoOnCancel { override def tryOnError(e: Throwable): Boolean = { if (isActive) { isActive = false - ctx.connection.pop() + val _ = ctx.connection.pop() this.error = e ctx.scheduler.execute(this) true diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskEffect.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskEffect.scala index 20116c827..0e4bbd1e4 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskEffect.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskEffect.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.eval package internal -import cats.effect.{CancelToken, IO, SyncIO} +import cats.effect.{ CancelToken, IO, SyncIO } import monix.execution.Callback import monix.execution.Scheduler import monix.execution.internal.AttemptCallback.noop @@ -31,28 +31,31 @@ import scala.util.control.NonFatal */ private[eval] object TaskEffect { /** - * `cats.effect.Effect#runAsync` - */ +* `cats.effect.Effect#runAsync` +*/ def runAsync[A](fa: Task[A])(cb: Either[Throwable, A] => IO[Unit])( - implicit s: Scheduler, + implicit + s: Scheduler, opts: Task.Options ): SyncIO[Unit] = SyncIO { - execute(fa, cb) + val _ = execute(fa, cb) () } /** - * `cats.effect.ConcurrentEffect#runCancelable` - */ +* `cats.effect.ConcurrentEffect#runCancelable` +*/ def runCancelable[A](fa: Task[A])(cb: Either[Throwable, A] => IO[Unit])( - implicit s: Scheduler, + implicit + s: Scheduler, opts: Task.Options ): SyncIO[CancelToken[Task]] = SyncIO { execute(fa, cb) } private def execute[A](fa: Task[A], cb: Either[Throwable, A] => IO[Unit])( - implicit s: Scheduler, + implicit + s: Scheduler, opts: Task.Options ): CancelToken[Task] = { fa.runAsyncOptF(new Callback[Throwable, A] { diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskEvalAsync.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskEvalAsync.scala index 2b3e959fa..7fc25b950 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskEvalAsync.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskEvalAsync.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,8 +23,8 @@ import scala.util.control.NonFatal private[eval] object TaskEvalAsync { /** - * Implementation for `Task.evalAsync`. - */ +* Implementation for `Task.evalAsync`. +*/ def apply[A](a: () => A): Task[A] = Task.Async( new EvalAsyncRegister[A](a), @@ -33,8 +33,8 @@ private[eval] object TaskEvalAsync { restoreLocals = false ) - // Implementing Async's "start" via `ForkedStart` in order to signal - // that this is a task that forks on evaluation +// Implementing Async's "start" via `ForkedStart` in order to signal +// that this is a task that forks on evaluation private final class EvalAsyncRegister[A](a: () => A) extends ForkedRegister[A] { def apply(ctx: Task.Context, cb: Callback[Throwable, A]): Unit = diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskExecuteOn.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskExecuteOn.scala index dab763e0e..5985cd7b7 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskExecuteOn.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskExecuteOn.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.eval.internal -import monix.eval.Task.{Async, Context} +import monix.eval.Task.{ Async, Context } import java.util.concurrent.RejectedExecutionException import monix.execution.Callback import monix.eval.Task @@ -25,8 +25,8 @@ import monix.execution.Scheduler private[eval] object TaskExecuteOn { /** - * Implementation for `Task.executeOn`. - */ +* Implementation for `Task.executeOn`. +*/ def apply[A](source: Task[A], s: Scheduler, forceAsync: Boolean): Task[A] = { val withTrampoline = !forceAsync val start = @@ -41,8 +41,8 @@ private[eval] object TaskExecuteOn { ) } - // Implementing Async's "start" via `ForkedStart` in order to signal - // that this is task that forks on evaluation +// Implementing Async's "start" via `ForkedStart` in order to signal +// that this is task that forks on evaluation private final class AsyncRegister[A](source: Task[A], s: Scheduler) extends ForkedRegister[A] { def apply(ctx: Context, cb: Callback[Throwable, A]): Unit = { val oldS = ctx.scheduler @@ -53,8 +53,8 @@ private[eval] object TaskExecuteOn { source, ctx2, new Callback[Throwable, A] with Runnable { - private[this] var value: A = _ - private[this] var error: Throwable = _ + private var value: A = null.asInstanceOf[A] + private var error: Throwable = null.asInstanceOf[Throwable] def onSuccess(value: A): Unit = { this.value = value diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskExecuteWithModel.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskExecuteWithModel.scala index fb5278426..d958bbce1 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskExecuteWithModel.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskExecuteWithModel.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,14 +19,14 @@ package monix.eval.internal import monix.execution.Callback import monix.eval.Task -import monix.eval.Task.{Async, Context} +import monix.eval.Task.{ Async, Context } import monix.execution.ExecutionModel -import monix.execution.ExecutionModel.{AlwaysAsyncExecution, BatchedExecution, SynchronousExecution} +import monix.execution.ExecutionModel.{ AlwaysAsyncExecution, BatchedExecution, SynchronousExecution } private[eval] object TaskExecuteWithModel { /** - * Implementation for `Task.executeWithModel` - */ +* Implementation for `Task.executeWithModel` +*/ def apply[A](self: Task[A], em: ExecutionModel): Task[A] = { val start = (context: Context, cb: Callback[Throwable, A]) => { val context2 = context.withExecutionModel(em) diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskExecuteWithOptions.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskExecuteWithOptions.scala index 98a667e78..8dbfdbc12 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskExecuteWithOptions.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskExecuteWithOptions.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,22 +18,21 @@ package monix.eval.internal import monix.eval.Task -import monix.eval.Task.{Context, ContextSwitch, Options} +import monix.eval.Task.{ Context, ContextSwitch, Options } private[eval] object TaskExecuteWithOptions { /** - * Implementation for `Task.executeWithOptions` - */ +* Implementation for `Task.executeWithOptions` +*/ def apply[A](self: Task[A], f: Options => Options): Task[A] = ContextSwitch(self, enable(f), disable) - private[this] def enable(f: Options => Options): Context => Context = - ctx => { - val opts2 = f(ctx.options) - if (opts2 != ctx.options) ctx.withOptions(opts2) - else ctx - } + private def enable(f: Options => Options): Context => Context = ctx => { + val opts2 = f(ctx.options) + if (opts2 != ctx.options) ctx.withOptions(opts2) + else ctx + } - private[this] val disable: (Any, Throwable, Context, Context) => Context = + private val disable: (Any, Throwable, Context, Context) => Context = (_, _, old, current) => current.withOptions(old.options) } diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskFromFuture.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskFromFuture.scala index ac1437775..bc08ef6da 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskFromFuture.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskFromFuture.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ import monix.eval.Task import monix.execution.cancelables.SingleAssignCancelable import scala.util.control.NonFatal import monix.execution.schedulers.TrampolinedRunnable -import scala.concurrent.{ExecutionContext, Future} +import scala.concurrent.{ ExecutionContext, Future } import scala.util.Try private[eval] object TaskFromFuture { @@ -77,7 +77,7 @@ private[eval] object TaskFromFuture { val start: Start[A] = (ctx, cb) => { implicit val ec = ctx.scheduler if (p.isCompleted) { - p.subscribe(trampolinedCB(cb, null)) + val _ = p.subscribe(trampolinedCB(cb, null)) () } else { val conn = ctx.connection @@ -127,17 +127,18 @@ private[eval] object TaskFromFuture { conn.push(c)(ctx.scheduler) // Async boundary f.onComplete { result => - conn.pop() + val _ = conn.pop() cb(result) }(ctx.scheduler) } } private def trampolinedCB[A](cb: Callback[Throwable, A], conn: TaskConnection)( - implicit ec: ExecutionContext): Try[A] => Unit = { + implicit ec: ExecutionContext + ): Try[A] => Unit = { new (Try[A] => Unit) with TrampolinedRunnable { - private[this] var value: Try[A] = _ + private var value: Try[A] = null.asInstanceOf[Try[A]] def apply(value: Try[A]): Unit = { this.value = value @@ -145,7 +146,9 @@ private[eval] object TaskFromFuture { } def run(): Unit = { - if (conn ne null) conn.pop() + if (conn ne null) { + val _ = conn.pop() + } val v = value value = null cb(v) diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskMapBoth.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskMapBoth.scala index 9759d6afd..c829106d5 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskMapBoth.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskMapBoth.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,41 +23,45 @@ import monix.eval.Task import monix.execution.Ack.Stop import monix.execution.Scheduler import monix.execution.atomic.PaddingStrategy.LeftRight128 -import monix.execution.atomic.{Atomic, AtomicAny} +import monix.execution.atomic.{ Atomic, AtomicAny } import monix.execution.internal.exceptions.matchError import scala.annotation.tailrec import scala.util.control.NonFatal private[eval] object TaskMapBoth { /** - * Implementation for `Task.mapBoth`. - */ +* Implementation for `Task.mapBoth`. +*/ def apply[A1, A2, R](fa1: Task[A1], fa2: Task[A2])(f: (A1, A2) => R): Task[R] = { - TracedAsync(new Register(fa1, fa2, f), trampolineBefore = true, trampolineAfter = true, restoreLocals = true, traceKey = f) + TracedAsync( + new Register(fa1, fa2, f), + trampolineBefore = true, + trampolineAfter = true, + restoreLocals = true, + traceKey = f + ) } - // Implementing Async's "start" via `ForkedStart` in order to signal - // that this is a task that forks on evaluation. - // - // N.B. the contract is that the injected callback gets called after - // a full async boundary! +// Implementing Async's "start" via `ForkedStart` in order to signal +// that this is a task that forks on evaluation. +// +// N.B. the contract is that the injected callback gets called after +// a full async boundary! private final class Register[A1, A2, R](fa1: Task[A1], fa2: Task[A2], f: (A1, A2) => R) extends ForkedRegister[R] { /* For signaling the values after the successful completion of both tasks. */ - def sendSignal(mainConn: TaskConnection, cb: Callback[Throwable, R], a1: A1, a2: A2)( - implicit s: Scheduler): Unit = { - + def sendSignal(mainConn: TaskConnection, cb: Callback[Throwable, R], a1: A1, a2: A2): Unit = { var streamErrors = true try { val r = f(a1, a2) streamErrors = false - mainConn.pop() + val _ = mainConn.pop() cb.onSuccess(r) } catch { case NonFatal(ex) if streamErrors => // Both tasks completed by this point, so we don't need // to worry about the `state` being a `Stop` - mainConn.pop() + val _ = mainConn.pop() cb.onError(ex) } } @@ -67,7 +71,8 @@ private[eval] object TaskMapBoth { mainConn: TaskConnection, state: AtomicAny[AnyRef], cb: Callback[Throwable, R], - ex: Throwable)(implicit s: Scheduler): Unit = { + ex: Throwable + )(implicit s: Scheduler): Unit = { // Guarding the contract of the callback, as we cannot send an error // if an error has already happened because of the other task @@ -107,7 +112,7 @@ private[eval] object TaskMapBoth { case null => // null means this is the first task to complete if (!state.compareAndSet(null, Left(a1))) onSuccess(a1) case Right(a2) => // the other task completed, so we can send - sendSignal(mainConn, cb, a1, a2.asInstanceOf[A2])(s) + sendSignal(mainConn, cb, a1, a2.asInstanceOf[A2]) case Stop => // the other task triggered an error () // do nothing case s @ Left(_) => @@ -117,7 +122,7 @@ private[eval] object TaskMapBoth { case other => // $COVERAGE-OFF$ matchError(other) - // $COVERAGE-ON$ + // $COVERAGE-ON$ } def onError(ex: Throwable): Unit = @@ -135,7 +140,7 @@ private[eval] object TaskMapBoth { case null => // null means this is the first task to complete if (!state.compareAndSet(null, Right(a2))) onSuccess(a2) case Left(a1) => // the other task completed, so we can send - sendSignal(mainConn, cb, a1.asInstanceOf[A1], a2)(s) + sendSignal(mainConn, cb, a1.asInstanceOf[A1], a2) case Stop => // the other task triggered an error () // do nothing case s @ Right(_) => @@ -145,7 +150,7 @@ private[eval] object TaskMapBoth { case other => // $COVERAGE-OFF$ matchError(other) - // $COVERAGE-ON$ + // $COVERAGE-ON$ } def onError(ex: Throwable): Unit = diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskMemoize.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskMemoize.scala index 211808370..6bbd11aaa 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskMemoize.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskMemoize.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,21 +17,21 @@ package monix.eval.internal -import monix.eval.Task.{Context, Error, Now} +import monix.eval.Task.{ Context, Error, Now } import monix.eval.internal.TaskRunLoop.startFull import monix.execution.Callback -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.Scheduler import monix.execution.atomic.Atomic import monix.execution.internal.exceptions.matchError import scala.annotation.tailrec -import scala.concurrent.{ExecutionContext, Promise} -import scala.util.{Failure, Success, Try} +import scala.concurrent.{ ExecutionContext, Promise } +import scala.util.{ Failure, Success, Try } private[eval] object TaskMemoize { /** - * Implementation for `.memoize` and `.memoizeOnSuccess`. - */ +* Implementation for `.memoize` and `.memoizeOnSuccess`. +*/ def apply[A](source: Task[A], cacheErrors: Boolean): Task[A] = source match { case Now(_) | Error(_) => @@ -45,7 +45,8 @@ private[eval] object TaskMemoize { new Register(source, cacheErrors), trampolineBefore = false, trampolineAfter = true, - restoreLocals = true) + restoreLocals = true + ) } /** Registration function, used in `Task.Async`. */ @@ -53,8 +54,8 @@ private[eval] object TaskMemoize { extends ((Task.Context, Callback[Throwable, A]) => Unit) { self => // N.B. keeps state! - private[this] var thunk = source - private[this] val state = Atomic(null: AnyRef) + private var thunk = source + private val state = Atomic(null: AnyRef) def apply(ctx: Context, cb: Callback[Throwable, A]): Unit = state.get() match { @@ -65,8 +66,8 @@ private[eval] object TaskMemoize { } /** Saves the final result on completion and triggers the registered - * listeners. - */ +* listeners. +*/ @tailrec def cacheValue(value: Try[A])(implicit s: Scheduler): Unit = { // Should we cache everything, error results as well, // or only successful results? @@ -91,7 +92,7 @@ private[eval] object TaskMemoize { // Resetting the state to `null` will trigger the // execution again on next `runAsync` if (state.compareAndSet(p, null)) { - p.tryComplete(value) + val _ = p.tryComplete(value) () } else { // Race condition, retry @@ -117,10 +118,11 @@ private[eval] object TaskMemoize { } /** While the task is pending completion, registers a new listener - * that will receive the result once the task is complete. - */ +* that will receive the result once the task is complete. +*/ private def registerListener(p: Promise[A], context: Context, cb: Callback[Throwable, A])( - implicit ec: ExecutionContext): Unit = { + implicit ec: ExecutionContext + ): Unit = { p.future.onComplete { r => // Listener is cancelable: we simply ensure that the result isn't streamed @@ -132,8 +134,8 @@ private[eval] object TaskMemoize { } /** - * Starts execution, eventually caching the value on completion. - */ +* Starts execution, eventually caching the value on completion. +*/ @tailrec private def start(context: Context, cb: Callback[Throwable, A]): Unit = { implicit val sc: Scheduler = context.scheduler self.state.get() match { @@ -164,12 +166,12 @@ private[eval] object TaskMemoize { // Race condition happened // $COVERAGE-OFF$ cb(ref) - // $COVERAGE-ON$ + // $COVERAGE-ON$ case other => // $COVERAGE-OFF$ matchError(other) - // $COVERAGE-ON$ + // $COVERAGE-ON$ } } } diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskParSequence.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskParSequence.scala index dde1d54e1..280f8ed84 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskParSequence.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskParSequence.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.eval.internal import cats.effect.CancelToken -import monix.eval.Task.{Async, Context} +import monix.eval.Task.{ Async, Context } import monix.execution.Callback import monix.eval.Task import monix.execution.Scheduler @@ -28,8 +28,8 @@ import scala.collection.mutable.ListBuffer private[eval] object TaskParSequence { /** - * Implementation for [[Task.parSequence]] - */ +* Implementation for [[Task.parSequence]] +*/ def apply[A, M[X] <: Iterable[X]](in: Iterable[Task[A]], makeBuilder: () => mutable.Builder[A, M[A]]): Task[M[A]] = { Async( new Register(in, makeBuilder), @@ -39,15 +39,15 @@ private[eval] object TaskParSequence { ) } - // Implementing Async's "start" via `ForkedStart` in order to signal - // that this is a task that forks on evaluation. - // - // N.B. the contract is that the injected callback gets called after - // a full async boundary! +// Implementing Async's "start" via `ForkedStart` in order to signal +// that this is a task that forks on evaluation. +// +// N.B. the contract is that the injected callback gets called after +// a full async boundary! private final class Register[A, M[X] <: Iterable[X]]( in: Iterable[Task[A]], - makeBuilder: () => mutable.Builder[A, M[A]]) - extends ForkedRegister[M[A]] { + makeBuilder: () => mutable.Builder[A, M[A]] + ) extends ForkedRegister[M[A]] { def apply(context: Context, finalCallback: Callback[Throwable, M[A]]): Unit = { // We need a monitor to synchronize on, per evaluation! @@ -65,13 +65,11 @@ private[eval] object TaskParSequence { // MUST BE synchronized by `lock`! // MUST NOT BE called if isActive == false! - def maybeSignalFinal(mainConn: TaskConnection, finalCallback: Callback[Throwable, M[A]])( - implicit s: Scheduler): Unit = { - + def maybeSignalFinal(mainConn: TaskConnection, finalCallback: Callback[Throwable, M[A]]): Unit = { completed += 1 if (completed >= tasksCount) { isActive = false - mainConn.pop() + val _ = mainConn.pop() val builder = makeBuilder() var idx = 0 diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskParSequenceN.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskParSequenceN.scala index f1d6d543e..ea0e6c056 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskParSequenceN.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskParSequenceN.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,12 +21,12 @@ import cats.effect.ExitCase import cats.effect.concurrent.Deferred import monix.catnap.ConcurrentQueue import monix.eval.Task -import monix.execution.{BufferCapacity, ChannelType} +import monix.execution.{ BufferCapacity, ChannelType } private[eval] object TaskParSequenceN { /** - * Implementation for [[Task.parSequenceN]] - */ +* Implementation for [[Task.parSequenceN]] +*/ def apply[A]( parallelism: Int, in: Iterable[Task[A]] diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskParSequenceUnordered.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskParSequenceUnordered.scala index e811a45c2..a799727a6 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskParSequenceUnordered.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskParSequenceUnordered.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,11 +18,11 @@ package monix.eval.internal import cats.effect.CancelToken -import monix.eval.Task.{Async, Context} +import monix.eval.Task.{ Async, Context } import monix.execution.Callback import monix.eval.Task import monix.execution.Scheduler -import monix.execution.atomic.{Atomic, AtomicAny} +import monix.execution.atomic.{ Atomic, AtomicAny } import monix.execution.atomic.PaddingStrategy.LeftRight128 import monix.execution.compat.internal.toIterator import monix.execution.internal.Platform @@ -33,8 +33,8 @@ import scala.collection.mutable.ListBuffer private[eval] object TaskParSequenceUnordered { /** - * Implementation for [[Task.parSequenceUnordered]] - */ +* Implementation for [[Task.parSequenceUnordered]] +*/ def apply[A](in: Iterable[Task[A]]): Task[List[A]] = { Async( new Register(in), @@ -44,23 +44,24 @@ private[eval] object TaskParSequenceUnordered { ) } - // Implementing Async's "start" via `ForkedStart` in order to signal - // that this is a task that forks on evaluation. - // - // N.B. the contract is that the injected callback gets called after - // a full async boundary! +// Implementing Async's "start" via `ForkedStart` in order to signal +// that this is a task that forks on evaluation. +// +// N.B. the contract is that the injected callback gets called after +// a full async boundary! private final class Register[A](in: Iterable[Task[A]]) extends ForkedRegister[List[A]] { def maybeSignalFinal( ref: AtomicAny[State[A]], currentState: State[A], mainConn: TaskConnection, - finalCallback: Callback[Throwable, List[A]])(implicit s: Scheduler): Unit = { + finalCallback: Callback[Throwable, List[A]] + )(implicit s: Scheduler): Unit = { currentState match { case State.Active(list, 0) => ref.lazySet(State.Complete) - mainConn.pop() + val _ = mainConn.pop() if (list ne Nil) finalCallback.onSuccess(list) else { @@ -77,7 +78,8 @@ private[eval] object TaskParSequenceUnordered { stateRef: AtomicAny[State[A]], mainConn: TaskConnection, ex: Throwable, - finalCallback: Callback[Throwable, List[A]])(implicit s: Scheduler): Unit = { + finalCallback: Callback[Throwable, List[A]] + )(implicit s: Scheduler): Unit = { val currentState = stateRef.getAndSet(State.Complete) if (currentState != State.Complete) { @@ -93,7 +95,8 @@ private[eval] object TaskParSequenceUnordered { stateRef: AtomicAny[State[A]], count: Int, conn: TaskConnection, - finalCallback: Callback[Throwable, List[A]])(implicit s: Scheduler): Unit = { + finalCallback: Callback[Throwable, List[A]] + )(implicit s: Scheduler): Unit = { stateRef.get() match { case current @ State.Initializing(_, _) => diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRace.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRace.scala index af54bcf21..8b0f5a069 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRace.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRace.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,8 +23,8 @@ import monix.execution.atomic.Atomic private[eval] object TaskRace { /** - * Implementation for `Task.race`. - */ +* Implementation for `Task.race`. +*/ def apply[A, B](fa: Task[A], fb: Task[B]): Task[Either[A, B]] = Task.Async( new Register(fa, fb), @@ -32,11 +32,11 @@ private[eval] object TaskRace { trampolineAfter = true ) - // Implementing Async's "start" via `ForkedStart` in order to signal - // that this is a task that forks on evaluation. - // - // N.B. the contract is that the injected callback gets called after - // a full async boundary! +// Implementing Async's "start" via `ForkedStart` in order to signal +// that this is a task that forks on evaluation. +// +// N.B. the contract is that the injected callback gets called after +// a full async boundary! private final class Register[A, B](fa: Task[A], fb: Task[B]) extends ForkedRegister[Either[A, B]] { def apply(context: Task.Context, cb: Callback[Throwable, Either[A, B]]): Unit = { @@ -59,7 +59,7 @@ private[eval] object TaskRace { def onSuccess(valueA: A): Unit = if (isActive.getAndSet(false)) { connB.cancel.map { _ => - conn.pop() + val _ = conn.pop() cb.onSuccess(Left(valueA)) }.runAsyncAndForget } @@ -67,7 +67,7 @@ private[eval] object TaskRace { def onError(ex: Throwable): Unit = if (isActive.getAndSet(false)) { connB.cancel.map { _ => - conn.pop() + val _ = conn.pop() cb.onError(ex) }.runAsyncAndForget } else { @@ -84,7 +84,7 @@ private[eval] object TaskRace { def onSuccess(valueB: B): Unit = if (isActive.getAndSet(false)) { connA.cancel.map { _ => - conn.pop() + val _ = conn.pop() cb.onSuccess(Right(valueB)) }.runAsyncAndForget } @@ -92,7 +92,7 @@ private[eval] object TaskRace { def onError(ex: Throwable): Unit = if (isActive.getAndSet(false)) { connA.cancel.map { _ => - conn.pop() + val _ = conn.pop() cb.onError(ex) }.runAsyncAndForget } else { diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRaceList.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRaceList.scala index 80e23b6a5..9ab0b091d 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRaceList.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRaceList.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,20 +21,20 @@ import cats.effect.CancelToken import monix.catnap.CancelableF import monix.execution.Callback import monix.eval.Task -import monix.execution.atomic.{Atomic, PaddingStrategy} +import monix.execution.atomic.{ Atomic, PaddingStrategy } private[eval] object TaskRaceList { /** - * Implementation for `Task.raceList` - */ +* Implementation for `Task.raceList` +*/ def apply[A](tasks: Iterable[Task[A]]): Task[A] = Task.Async(new Register(tasks), trampolineBefore = true, trampolineAfter = true) - // Implementing Async's "start" via `ForkedStart` in order to signal - // that this is a task that forks on evaluation. - // - // N.B. the contract is that the injected callback gets called after - // a full async boundary! +// Implementing Async's "start" via `ForkedStart` in order to signal +// that this is a task that forks on evaluation. +// +// N.B. the contract is that the injected callback gets called after +// a full async boundary! private final class Register[A](tasks: Iterable[Task[A]]) extends ForkedRegister[A] { def apply(context: Task.Context, callback: Callback[Throwable, A]): Unit = { @@ -44,7 +44,7 @@ private[eval] object TaskRaceList { val isActive = Atomic.withPadding(true, PaddingStrategy.LeftRight128) val taskArray = tasks.toArray val cancelableArray = buildCancelableArray(taskArray.length) - conn.pushConnections(cancelableArray.toIndexedSeq: _*) + conn.pushConnections(cancelableArray.toIndexedSeq*) var index = 0 while (index < taskArray.length) { @@ -58,12 +58,12 @@ private[eval] object TaskRaceList { taskContext, new Callback[Throwable, A] { private def popAndCancelRest(): CancelToken[Task] = { - conn.pop() + val _ = conn.pop() val arr2 = cancelableArray.collect { case cc if cc ne taskCancelable => cc.cancel } - CancelableF.cancelAllTokens[Task](arr2.toIndexedSeq: _*) + CancelableF.cancelAllTokens[Task](arr2.toIndexedSeq*) } def onSuccess(value: A): Unit = diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRacePair.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRacePair.scala index c70587a3c..1c8fbd477 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRacePair.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRacePair.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,13 +23,12 @@ import monix.execution.atomic.Atomic import scala.concurrent.Promise -private[eval] object TaskRacePair { - // Type aliasing the result only b/c it's a mouthful +private[eval] object TaskRacePair { // Type aliasing the result only b/c it's a mouthful type RaceEither[A, B] = Either[(A, Fiber[B]), (Fiber[A], B)] /** - * Implementation for `Task.racePair`. - */ + * Implementation for `Task.racePair`. + */ def apply[A, B](fa: Task[A], fb: Task[B]): Task[RaceEither[A, B]] = Task.Async( new Register(fa, fb), @@ -37,11 +36,11 @@ private[eval] object TaskRacePair { trampolineAfter = true ) - // Implementing Async's "start" via `ForkedStart` in order to signal - // that this is a task that forks on evaluation. - // - // N.B. the contract is that the injected callback gets called after - // a full async boundary! +// Implementing Async's "start" via `ForkedStart` in order to signal +// that this is a task that forks on evaluation. +// +// N.B. the contract is that the injected callback gets called after +// a full async boundary! private final class Register[A, B](fa: Task[A], fb: Task[B]) extends ForkedRegister[RaceEither[A, B]] { def apply(context: Task.Context, cb: Callback[Throwable, RaceEither[A, B]]): Unit = { @@ -67,7 +66,7 @@ private[eval] object TaskRacePair { def onSuccess(valueA: A): Unit = if (isActive.getAndSet(false)) { val fiberB = Fiber(TaskFromFuture.strict(pb.future), connB.cancel) - conn.pop() + val _ = conn.pop() cb.onSuccess(Left((valueA, fiberB))) } else { pa.success(valueA) @@ -77,7 +76,7 @@ private[eval] object TaskRacePair { def onError(ex: Throwable): Unit = if (isActive.getAndSet(false)) { connB.cancel.map { _ => - conn.pop() + val _ = conn.pop() cb.onError(ex) }.runAsyncAndForget } else { @@ -95,7 +94,7 @@ private[eval] object TaskRacePair { def onSuccess(valueB: B): Unit = if (isActive.getAndSet(false)) { val fiberA = Fiber(TaskFromFuture.strict(pa.future), connA.cancel) - conn.pop() + val _ = conn.pop() cb.onSuccess(Right((fiberA, valueB))) } else { pb.success(valueB) @@ -105,7 +104,7 @@ private[eval] object TaskRacePair { def onError(ex: Throwable): Unit = if (isActive.getAndSet(false)) { connA.cancel.map { _ => - conn.pop() + val _ = conn.pop() cb.onError(ex) }.runAsyncAndForget } else { diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRestartCallback.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRestartCallback.scala index de492d71e..07443ba3a 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRestartCallback.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRestartCallback.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,29 +17,31 @@ package monix.eval.internal -import monix.eval.Task.{Context, Error, Now} -import monix.eval.internal.TaskRunLoop.{startFull, Bind, CallStack} +import monix.eval.Task.{ Context, Error, Now } +import monix.eval.internal.TaskRunLoop.{ startFull, Bind, CallStack } import monix.eval.Task import monix.execution.Callback import monix.execution.misc.Local import monix.execution.schedulers.TrampolinedRunnable +import scala.annotation.unused private[internal] abstract class TaskRestartCallback(contextInit: Context, callback: Callback[Throwable, Any]) extends Callback[Throwable, Any] with TrampolinedRunnable { // Modified on prepare() - private[this] var bFirst: Bind = _ - private[this] var bRest: CallStack = _ - private[this] var register: (Context, Callback[Throwable, Any]) => Unit = _ + private var bFirst: Bind = null.asInstanceOf[Bind] + private var bRest: CallStack = null.asInstanceOf[CallStack] + private var register: (Context, Callback[Throwable, Any]) => Unit = + null.asInstanceOf[(Context, Callback[Throwable, Any]) => Unit] // Mutated in onSuccess and onError, just before scheduling // onSuccessRun and onErrorRun - private[this] var value: Any = _ - private[this] var error: Throwable = _ - private[this] var trampolineAfter: Boolean = true + private var value: Any = null.asInstanceOf[Any] + private var error: Throwable = null.asInstanceOf[Throwable] + private var trampolineAfter: Boolean = true // Can change via ContextSwitch - private[this] var context = contextInit + private var context = contextInit final def contextSwitch(other: Context): Unit = { this.context = other @@ -89,9 +91,9 @@ private[internal] abstract class TaskRestartCallback(contextInit: Context, callb // $COVERAGE-ON$ } - protected def prepareStart(task: Task.Async[_]): Unit = () + protected def prepareStart(@unused task: Task.Async[?]): Unit = () protected def prepareCallback: Callback[Throwable, Any] = callback - private[this] val wrappedCallback = prepareCallback + private val wrappedCallback = prepareCallback protected def syncOnSuccess(value: Any): Unit = { val bFirst = this.bFirst @@ -110,30 +112,28 @@ private[internal] abstract class TaskRestartCallback(contextInit: Context, callb } /** Reusable Runnable reference, to go lighter on memory allocations. */ - private[this] val onSuccessRun: TrampolinedRunnable = - new TrampolinedRunnable { - def run(): Unit = { - val v = value - value = null - syncOnSuccess(v) - } + private val onSuccessRun: TrampolinedRunnable = new TrampolinedRunnable { + def run(): Unit = { + val v = value + value = null + syncOnSuccess(v) } + } /** Reusable Runnable reference, to go lighter on memory allocations. */ - private[this] val onErrorRun: TrampolinedRunnable = - new TrampolinedRunnable { - def run(): Unit = { - val e = error - error = null - syncOnError(e) - } + private val onErrorRun: TrampolinedRunnable = new TrampolinedRunnable { + def run(): Unit = { + val e = error + error = null + syncOnError(e) } + } } private[internal] object TaskRestartCallback { /** Builder for [[TaskRestartCallback]], returning a specific instance - * optimized for the passed in `Task.Options`. - */ + * optimized for the passed in `Task.Options`. + */ def apply(context: Context, callback: Callback[Throwable, Any]): TaskRestartCallback = { if (context.options.localContextPropagation) new WithLocals(context, callback) @@ -149,10 +149,10 @@ private[internal] object TaskRestartCallback { private final class WithLocals(context: Context, callback: Callback[Throwable, Any]) extends TaskRestartCallback(context, callback) { - private[this] var preparedLocals: Local.Context = _ - private[this] var previousLocals: Local.Context = _ + private var preparedLocals: Local.Context = null.asInstanceOf[Local.Context] + private var previousLocals: Local.Context = null.asInstanceOf[Local.Context] - override protected def prepareStart(task: Task.Async[_]): Unit = { + override protected def prepareStart(task: Task.Async[?]): Unit = { preparedLocals = if (task.restoreLocals) Local.getContext() else null } diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRunLoop.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRunLoop.scala index ce88cd6b3..54f28df9f 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRunLoop.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRunLoop.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,15 +19,15 @@ package monix.eval.internal import cats.effect.CancelToken import monix.eval.Task -import monix.eval.Task.{Async, Context, ContextSwitch, Error, Eval, FlatMap, Map, Now, Suspend, Trace} +import monix.eval.Task.{ Async, Context, ContextSwitch, Error, Eval, FlatMap, Map, Now, Suspend, Trace } import monix.execution.internal.collection.ChunkedArrayStack import monix.execution.misc.Local -import monix.execution.{Callback, CancelableFuture, ExecutionModel, Scheduler} +import monix.execution.{ Callback, CancelableFuture, ExecutionModel, Scheduler } import scala.concurrent.Promise import scala.util.control.NonFatal -import monix.eval.internal.TracingPlatform.{enhancedExceptions, isStackTracing} -import monix.eval.tracing.{TaskEvent, TaskTrace} +import monix.eval.internal.TracingPlatform.{ enhancedExceptions, isStackTracing } +import monix.eval.tracing.{ TaskEvent, TaskTrace } import scala.reflect.NameTransformer @@ -37,11 +37,11 @@ private[eval] object TaskRunLoop { type CallStack = ChunkedArrayStack[Bind] /** Starts or resumes evaluation of the run-loop from where it left - * off. This is the complete run-loop. - * - * Used for continuing a run-loop after an async boundary - * happens from [[startFuture]] and [[startLight]]. - */ +* off. This is the complete run-loop. +* +* Used for continuing a run-loop after an async boundary +* happens from [[startFuture]] and [[startLight]]. +*/ def startFull[A]( source: Task[A], contextInit: Context, @@ -49,7 +49,8 @@ private[eval] object TaskRunLoop { rcb: TaskRestartCallback, bFirst: Bind, bRest: CallStack, - frameIndex: FrameIndex): Unit = { + frameIndex: FrameIndex + ): Unit = { val cba = cb.asInstanceOf[Callback[Throwable, Any]] var current: Current = source @@ -205,15 +206,16 @@ private[eval] object TaskRunLoop { } /** Internal utility, for forcing an asynchronous boundary in the - * trampoline loop. - */ +* trampoline loop. +*/ def restartAsync[A]( source: Task[A], context: Context, cb: Callback[Throwable, A], rcb: TaskRestartCallback, bindCurrent: Bind, - bindRest: CallStack): Unit = { + bindRest: CallStack + ): Unit = { val savedLocals = if (context.options.localContextPropagation) Local.getContext() @@ -248,17 +250,18 @@ private[eval] object TaskRunLoop { } /** A run-loop that attempts to evaluate a `Task` without - * initializing a `Task.Context`, falling back to - * [[startFull]] when the first `Async` boundary is hit. - * - * Function gets invoked by `Task.runAsync(cb: Callback)`. - */ +* initializing a `Task.Context`, falling back to +* [[startFull]] when the first `Async` boundary is hit. +* +* Function gets invoked by `Task.runAsync(cb: Callback)`. +*/ def startLight[A]( source: Task[A], scheduler: Scheduler, opts: Task.Options, cb: Callback[Throwable, A], - isCancelable: Boolean = true): CancelToken[Task] = { + isCancelable: Boolean = true + ): CancelToken[Task] = { var current = source.asInstanceOf[Task[Any]] var bFirst: Bind = null @@ -363,7 +366,8 @@ private[eval] object TaskRunLoop { frameIndex, forceFork = false, isCancelable = isCancelable, - tracingCtx = tracingCtx) + tracingCtx = tracingCtx + ) } @@ -399,7 +403,8 @@ private[eval] object TaskRunLoop { frameIndex, forceFork = true, isCancelable = true, - tracingCtx = tracingCtx) + tracingCtx = tracingCtx + ) } } // $COVERAGE-OFF$ @@ -408,8 +413,8 @@ private[eval] object TaskRunLoop { } /** A run-loop version that evaluates the given task until the - * first async boundary or until completion. - */ +* first async boundary or until completion. +*/ def startStep[A](source: Task[A], scheduler: Scheduler, opts: Task.Options): Either[Task[A], A] = { var current = source.asInstanceOf[Task[Any]] var bFirst: Bind = null @@ -502,7 +507,16 @@ private[eval] object TaskRunLoop { case async => if (tracingCtx eq null) tracingCtx = new StackTracedContext - return goAsync4Step(async, scheduler, opts, bFirst, bRest, frameIndex, forceFork = false, tracingCtx = tracingCtx) + return goAsync4Step( + async, + scheduler, + opts, + bFirst, + bRest, + frameIndex, + forceFork = false, + tracingCtx = tracingCtx + ) } if (hasUnboxed) { @@ -526,7 +540,16 @@ private[eval] object TaskRunLoop { if (tracingCtx eq null) tracingCtx = new StackTracedContext // Force async boundary - return goAsync4Step(current, scheduler, opts, bFirst, bRest, frameIndex, forceFork = true, tracingCtx = tracingCtx) + return goAsync4Step( + current, + scheduler, + opts, + bFirst, + bRest, + frameIndex, + forceFork = true, + tracingCtx = tracingCtx + ) } } // $COVERAGE-OFF$ @@ -535,11 +558,11 @@ private[eval] object TaskRunLoop { } /** A run-loop that attempts to complete a `CancelableFuture` - * synchronously falling back to [[startFull]] and actual - * asynchronous execution in case of an asynchronous boundary. - * - * Function gets invoked by `Task.runToFuture(implicit s: Scheduler)`. - */ +* synchronously falling back to [[startFull]] and actual +* asynchronous execution in case of an asynchronous boundary. +* +* Function gets invoked by `Task.runToFuture(implicit s: Scheduler)`. +*/ def startFuture[A](source: Task[A], scheduler: Scheduler, opts: Task.Options): CancelableFuture[A] = { var current = source.asInstanceOf[Task[Any]] var bFirst: Bind = null @@ -665,7 +688,16 @@ private[eval] object TaskRunLoop { } else { if (tracingCtx eq null) tracingCtx = new StackTracedContext // Force async boundary - return goAsync4Future(current, scheduler, opts, bFirst, bRest, frameIndex, forceFork = true, tracingCtx = tracingCtx) + return goAsync4Future( + current, + scheduler, + opts, + bFirst, + bRest, + frameIndex, + forceFork = true, + tracingCtx = tracingCtx + ) } } // $COVERAGE-OFF$ @@ -680,7 +712,8 @@ private[eval] object TaskRunLoop { rcb: TaskRestartCallback, bFirst: Bind, bRest: CallStack, - nextFrame: FrameIndex): Unit = { + nextFrame: FrameIndex + ): Unit = { if (isStackTracing) { val trace = task.trace @@ -704,8 +737,8 @@ private[eval] object TaskRunLoop { } /** Called when we hit the first async boundary in - * [[startLight]]. - */ +* [[startLight]]. +*/ private def goAsyncForLightCB( source: Current, scheduler: Scheduler, @@ -716,7 +749,8 @@ private[eval] object TaskRunLoop { nextFrame: FrameIndex, isCancelable: Boolean, forceFork: Boolean, - tracingCtx: StackTracedContext): CancelToken[Task] = { + tracingCtx: StackTracedContext + ): CancelToken[Task] = { val context = Context( scheduler, @@ -747,7 +781,8 @@ private[eval] object TaskRunLoop { bRest: CallStack, nextFrame: FrameIndex, forceFork: Boolean, - tracingCtx: StackTracedContext): CancelableFuture[A] = { + tracingCtx: StackTracedContext + ): CancelableFuture[A] = { val p = Promise[A]() val cb = Callback.fromPromise(p).asInstanceOf[Callback[Throwable, Any]] @@ -775,7 +810,8 @@ private[eval] object TaskRunLoop { bRest: CallStack, nextFrame: FrameIndex, forceFork: Boolean, - tracingCtx: StackTracedContext): Either[Task[A], A] = { + tracingCtx: StackTracedContext + ): Either[Task[A], A] = { val ctx = Context(scheduler, opts, TaskConnection(), tracingCtx) val start: Start[Any] = @@ -791,7 +827,8 @@ private[eval] object TaskRunLoop { start.asInstanceOf[Start[A]], trampolineBefore = false, trampolineAfter = false - )) + ) + ) } private[internal] def findErrorHandler(bFirst: Bind, bRest: CallStack): StackFrame[Any, Task[Any]] = { @@ -804,7 +841,7 @@ private[eval] object TaskRunLoop { val ref = bRest.pop() if (ref eq null) return null - else if (ref.isInstanceOf[StackFrame[_, _]]) + else if (ref.isInstanceOf[StackFrame[?, ?]]) return ref.asInstanceOf[StackFrame[Any, Task[Any]]] } // $COVERAGE-OFF$ @@ -815,7 +852,7 @@ private[eval] object TaskRunLoop { } private[internal] def popNextBind(bFirst: Bind, bRest: CallStack): Bind = { - if ((bFirst ne null) && !bFirst.isInstanceOf[StackFrame.ErrorHandler[_, _]]) + if ((bFirst ne null) && !bFirst.isInstanceOf[StackFrame.ErrorHandler[?, ?]]) return bFirst if (bRest eq null) return null @@ -823,7 +860,7 @@ private[eval] object TaskRunLoop { val next = bRest.pop() if (next eq null) { return null - } else if (!next.isInstanceOf[StackFrame.ErrorHandler[_, _]]) { + } else if (!next.isInstanceOf[StackFrame.ErrorHandler[?, ?]]) { return next } } @@ -847,10 +884,10 @@ private[eval] object TaskRunLoop { } /** - * If stack tracing and contextual exceptions are enabled, this - * function will rewrite the stack trace of a captured exception - * to include the async stack trace. - */ +* If stack tracing and contextual exceptions are enabled, this +* function will rewrite the stack trace of a captured exception +* to include the async stack trace. +*/ private[internal] def augmentException(ex: Throwable, ctx: StackTracedContext): Unit = { val stackTrace = ex.getStackTrace if (stackTrace.nonEmpty) { @@ -864,10 +901,12 @@ private[eval] object TaskRunLoop { case (methodSite, callSite) => val op = NameTransformer.decode(methodSite.getMethodName) - new StackTraceElement(op + " @ " + callSite.getClassName, + new StackTraceElement( + op + " @ " + callSite.getClassName, callSite.getMethodName, callSite.getFileName, - callSite.getLineNumber) + callSite.getLineNumber + ) } .toArray ex.setStackTrace(prefix ++ suffix) @@ -878,9 +917,8 @@ private[eval] object TaskRunLoop { private def dropRunLoopFrames(frames: Array[StackTraceElement]): Array[StackTraceElement] = frames.takeWhile(ste => !runLoopFilter.exists(ste.getClassName.startsWith(_))) - private[this] val runLoopFilter = List( + private val runLoopFilter = List( "monix.eval.", "scala.runtime." ) - } diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRunToFutureWithLocal.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRunToFutureWithLocal.scala index 3d684dd1f..04b9759c2 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRunToFutureWithLocal.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRunToFutureWithLocal.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,24 +18,24 @@ package monix.eval.internal import monix.eval.Task -import monix.eval.Task.{Async, Context, Error, Eval, FlatMap, Map, Now, Suspend, Trace} +import monix.eval.Task.{ Async, Context, Error, Eval, FlatMap, Map, Now, Suspend, Trace } import monix.eval.internal.TaskRunLoop._ import monix.eval.tracing.TaskEvent -import monix.eval.internal.TracingPlatform.{enhancedExceptions, isStackTracing} +import monix.eval.internal.TracingPlatform.{ enhancedExceptions, isStackTracing } import monix.execution.internal.collection.ChunkedArrayStack import monix.execution.misc.Local -import monix.execution.{Callback, CancelableFuture, Scheduler} +import monix.execution.{ Callback, CancelableFuture, Scheduler } import scala.concurrent.Promise import scala.util.control.NonFatal private[eval] object TaskRunToFutureWithLocal { /** A run-loop that attempts to complete a `CancelableFuture` - * synchronously falling back to [[startFull]] and actual - * asynchronous execution in case of an asynchronous boundary. - * - * Function gets invoked by `Task.runToFuture(implicit s: Scheduler)`. - */ +* synchronously falling back to [[startFull]] and actual +* asynchronous execution in case of an asynchronous boundary. +* +* Function gets invoked by `Task.runToFuture(implicit s: Scheduler)`. +*/ def startFuture[A](source: Task[A], scheduler: Scheduler, opts: Task.Options): CancelableFuture[A] = { var current = source.asInstanceOf[Task[Any]] var bFirst: Bind = null @@ -170,7 +170,18 @@ private[eval] object TaskRunToFutureWithLocal { } else { if (tracingCtx eq null) tracingCtx = new StackTracedContext // Force async boundary - return goAsync4Future(current, scheduler, opts, bFirst, bRest, frameIndex, forceFork = true, prev, isolated, tracingCtx = tracingCtx) + return goAsync4Future( + current, + scheduler, + opts, + bFirst, + bRest, + frameIndex, + forceFork = true, + prev, + isolated, + tracingCtx = tracingCtx + ) } } // $COVERAGE-OFF$ @@ -189,7 +200,8 @@ private[eval] object TaskRunToFutureWithLocal { forceFork: Boolean, previousCtx: Local.Context, isolatedCtx: Local.Context, - tracingCtx: StackTracedContext): CancelableFuture[A] = { + tracingCtx: StackTracedContext + ): CancelableFuture[A] = { Local.setContext(isolatedCtx) diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskSequence.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskSequence.scala index 012bb4fd5..1ac181261 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskSequence.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskSequence.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -45,7 +45,8 @@ private[eval] object TaskSequence { /** Implementation for `Task.traverse`. */ def traverse[A, B, M[X] <: Iterable[X]](in: M[A], f: A => Task[B])( - implicit bf: BuildFrom[M[A], B, M[B]]): Task[M[B]] = { + implicit bf: BuildFrom[M[A], B, M[B]] + ): Task[M[B]] = { def loop(cursor: Iterator[A], acc: mutable.Builder[B, M[B]]): Task[M[B]] = { if (cursor.hasNext) { diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskShift.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskShift.scala index 7b072317d..5f62e745c 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskShift.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskShift.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,15 +19,15 @@ package monix.eval.internal import java.util.concurrent.RejectedExecutionException import monix.eval.Task -import monix.eval.Task.{Async, Context} +import monix.eval.Task.{ Async, Context } import monix.execution.schedulers.TracingScheduler -import monix.execution.{Callback, Scheduler} +import monix.execution.{ Callback, Scheduler } import scala.concurrent.ExecutionContext private[eval] object TaskShift { /** - * Implementation for `Task.shift` - */ +* Implementation for `Task.shift` +*/ def apply(ec: ExecutionContext): Task[Unit] = { Async( new Register(ec), @@ -37,11 +37,11 @@ private[eval] object TaskShift { ) } - // Implementing Async's "start" via `ForkedStart` in order to signal - // that this is a task that forks on evaluation. - // - // N.B. the contract is that the injected callback gets called after - // a full async boundary! +// Implementing Async's "start" via `ForkedStart` in order to signal +// that this is a task that forks on evaluation. +// +// N.B. the contract is that the injected callback gets called after +// a full async boundary! private final class Register(ec: ExecutionContext) extends ForkedRegister[Unit] { def apply(context: Context, cb: Callback[Throwable, Unit]): Unit = { val ec2 = @@ -59,11 +59,9 @@ private[eval] object TaskShift { } try { - ec2.execute(new Runnable { - def run(): Unit = { - context.frameRef.reset() - cb.onSuccess(()) - } + ec2.execute(() => { + context.frameRef.reset() + cb.onSuccess(()) }) } catch { case e: RejectedExecutionException => diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskSleep.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskSleep.scala index d37c674da..331b036eb 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskSleep.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskSleep.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.eval.internal import java.util.concurrent.RejectedExecutionException -import monix.eval.Task.{Async, Context} +import monix.eval.Task.{ Async, Context } import monix.execution.Callback import monix.eval.Task @@ -34,11 +34,11 @@ private[eval] object TaskSleep { trampolineAfter = false ) - // Implementing Async's "start" via `ForkedStart` in order to signal - // that this is a task that forks on evaluation. - // - // N.B. the contract is that the injected callback gets called after - // a full async boundary! +// Implementing Async's "start" via `ForkedStart` in order to signal +// that this is a task that forks on evaluation. +// +// N.B. the contract is that the injected callback gets called after +// a full async boundary! private final class Register(timespan: Duration) extends ForkedRegister[Unit] { def apply(ctx: Context, cb: Callback[Throwable, Unit]): Unit = { implicit val s = ctx.scheduler @@ -58,14 +58,14 @@ private[eval] object TaskSleep { } } - // Implementing Async's "start" via `ForkedStart` in order to signal - // that this is a task that forks on evaluation. - // - // N.B. the contract is that the injected callback gets called after - // a full async boundary! +// Implementing Async's "start" via `ForkedStart` in order to signal +// that this is a task that forks on evaluation. +// +// N.B. the contract is that the injected callback gets called after +// a full async boundary! private final class SleepRunnable(ctx: Context, cb: Callback[Throwable, Unit]) extends Runnable { def run(): Unit = { - ctx.connection.pop() + val _ = ctx.connection.pop() // We had an async boundary, as we must reset the frame ctx.frameRef.reset() cb.onSuccess(()) diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskStart.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskStart.scala index 9115ffc07..92c964a9e 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskStart.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskStart.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,13 +18,13 @@ package monix.eval package internal -import monix.eval.Task.{Async, Context} -import monix.execution.{Callback, CancelablePromise} +import monix.eval.Task.{ Async, Context } +import monix.execution.{ Callback, CancelablePromise } private[eval] object TaskStart { /** - * Implementation for `Task.fork`. - */ +* Implementation for `Task.fork`. +*/ def forked[A](fa: Task[A]): Task[Fiber[A]] = fa match { // There's no point in evaluating strict stuff diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskStartAndForget.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskStartAndForget.scala index 498ecfc77..1e516dcd9 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskStartAndForget.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskStartAndForget.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,8 +23,8 @@ import monix.eval.Task.Context private[eval] object TaskStartAndForget { /** - * Implementation for `Task.startAndForget`. - */ +* Implementation for `Task.startAndForget`. +*/ def apply[A](fa: Task[A]): Task[Unit] = { val start = (ctx: Context, cb: Callback[Throwable, Unit]) => { implicit val sc = ctx.scheduler diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskToReactivePublisher.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskToReactivePublisher.scala index 884d8bc50..800d1221a 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskToReactivePublisher.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskToReactivePublisher.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,21 +19,20 @@ package monix.eval.internal import monix.eval.Task import monix.execution.rstreams.Subscription -import monix.execution.{Callback, Scheduler, UncaughtExceptionReporter} +import monix.execution.{ Callback, Scheduler, UncaughtExceptionReporter } import org.reactivestreams.Subscriber private[eval] object TaskToReactivePublisher { /** - * Implementation for `Task.toReactivePublisher` - */ +* Implementation for `Task.toReactivePublisher` +*/ def apply[A](self: Task[A])(implicit s: Scheduler): org.reactivestreams.Publisher[A] = new org.reactivestreams.Publisher[A] { - def subscribe(out: Subscriber[_ >: A]): Unit = { + def subscribe(out: Subscriber[? >: A]): Unit = { out.onSubscribe(new Subscription { - private[this] var isActive = true - private[this] val conn = TaskConnection() - private[this] val context = - Task.Context(s, Task.defaultOptions.withSchedulerFeatures, conn, new StackTracedContext) + private var isActive = true + private val conn = TaskConnection() + private val context = Task.Context(s, Task.defaultOptions.withSchedulerFeatures, conn, new StackTracedContext) def request(n: Long): Unit = { require(n > 0, "n must be strictly positive, according to the Reactive Streams contract, rule 3.9") @@ -50,9 +49,9 @@ private[eval] object TaskToReactivePublisher { } } - private final class PublisherCallback[A](out: Subscriber[_ >: A])(implicit s: UncaughtExceptionReporter) + private final class PublisherCallback[A](out: Subscriber[? >: A])(implicit s: UncaughtExceptionReporter) extends Callback[Throwable, A] { - private[this] var isActive = true + private var isActive = true def onError(e: Throwable): Unit = if (isActive) { diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskTracing.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskTracing.scala index 5c04b8322..4ed9d721f 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TaskTracing.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TaskTracing.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,17 +27,16 @@ import monix.eval.tracing.TaskEvent * All Credits to https://github.com/typelevel/cats-effect and https://github.com/RaasAhsan */ private[eval] object TaskTracing { - def decorated[A](source: Task[A]): Task[A] = Trace(source, buildFrame()) def uncached(): TaskEvent = buildFrame() - def cached(clazz: Class[_]): TaskEvent = + def cached(clazz: Class[?]): TaskEvent = buildCachedFrame(clazz) - private def buildCachedFrame(clazz: Class[_]): TaskEvent = { + private def buildCachedFrame(clazz: Class[?]): TaskEvent = { val currentFrame = frameCache.get(clazz) if (currentFrame eq null) { val newFrame = buildFrame() @@ -52,9 +51,8 @@ private[eval] object TaskTracing { TaskEvent.StackTrace(new Throwable().getStackTrace.toList) /** - * Global cache for trace frames. Keys are references to lambda classes. - * Should converge to the working set of traces very quickly for hot code paths. - */ - private[this] val frameCache: ConcurrentHashMap[Class[_], TaskEvent] = new ConcurrentHashMap() - +* Global cache for trace frames. Keys are references to lambda classes. +* Should converge to the working set of traces very quickly for hot code paths. +*/ + private val frameCache: ConcurrentHashMap[Class[?], TaskEvent] = new ConcurrentHashMap() } diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/TracedAsync.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/TracedAsync.scala index 31e9c41a3..a693764d8 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/TracedAsync.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/TracedAsync.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,22 +18,21 @@ package monix.eval.internal import monix.eval.Task -import monix.eval.internal.TracingPlatform.{isCachedStackTracing, isFullStackTracing} +import monix.eval.internal.TracingPlatform.{ isCachedStackTracing, isFullStackTracing } import monix.execution.Callback /** * All Credits to https://github.com/typelevel/cats-effect and https://github.com/RaasAhsan */ -private[eval] object TracedAsync { - - // Convenience function for internal Async calls that intend - // to opt into tracing so the following code isn't repeated. +private[eval] object TracedAsync { // Convenience function for internal Async calls that intend +// to opt into tracing so the following code isn't repeated. def apply[A]( k: (Task.Context, Callback[Throwable, A]) => Unit, trampolineBefore: Boolean = false, trampolineAfter: Boolean = false, restoreLocals: Boolean = true, - traceKey: AnyRef): Task[A] = { + traceKey: AnyRef + ): Task[A] = { val trace = if (isCachedStackTracing) { TaskTracing.cached(traceKey.getClass) @@ -45,5 +44,4 @@ private[eval] object TracedAsync { Task.Async(k, trampolineBefore, trampolineAfter, restoreLocals, trace) } - } diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/UnsafeCancelUtils.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/UnsafeCancelUtils.scala index 8eaed7044..c144e7b6d 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/UnsafeCancelUtils.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/UnsafeCancelUtils.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.eval.internal import cats.effect.CancelToken import monix.catnap.CancelableF import monix.eval.Task -import monix.execution.{Cancelable, Scheduler} +import monix.execution.{ Cancelable, Scheduler } import monix.execution.internal.Platform import scala.collection.mutable.ListBuffer @@ -28,18 +28,19 @@ import scala.util.control.NonFatal private[eval] object UnsafeCancelUtils { /** - * Internal API. - */ +* Internal API. +*/ def taskToCancelable(task: Task[Unit])(implicit s: Scheduler): Cancelable = { if (task == Task.unit) Cancelable.empty else Cancelable(() => task.runAsyncAndForget(s)) } /** - * Internal API — very unsafe! - */ +* Internal API — very unsafe! +*/ private[internal] def cancelAllUnsafe( - cursor: Iterable[AnyRef /* Cancelable | Task[Unit] | CancelableF[Task] */ ]): CancelToken[Task] = { + cursor: Iterable[AnyRef /* Cancelable | Task[Unit] | CancelableF[Task] */ ] + ): CancelToken[Task] = { if (cursor.isEmpty) Task.unit @@ -51,10 +52,11 @@ private[eval] object UnsafeCancelUtils { } /** - * Internal API — very unsafe! - */ +* Internal API — very unsafe! +*/ private[internal] def unsafeCancel( - task: AnyRef /* Cancelable | Task[Unit] | CancelableF[Task] */ ): CancelToken[Task] = { + task: AnyRef /* Cancelable | Task[Unit] | CancelableF[Task] */ + ): CancelToken[Task] = { task match { case ref: Task[Unit] @unchecked => @@ -72,8 +74,8 @@ private[eval] object UnsafeCancelUtils { } /** - * Internal API — very unsafe! - */ +* Internal API — very unsafe! +*/ private[internal] def getToken(task: AnyRef /* Cancelable | Task[Unit] | CancelableF[Task] */ ): CancelToken[Task] = task match { case ref: Task[Unit] @unchecked => @@ -89,10 +91,11 @@ private[eval] object UnsafeCancelUtils { } /** - * Internal API — very unsafe! - */ +* Internal API — very unsafe! +*/ private[internal] def triggerCancel(task: AnyRef /* Cancelable | Task[Unit] | CancelableF[Task] */ )( - implicit s: Scheduler): Unit = { + implicit s: Scheduler + ): Unit = { task match { case ref: Task[Unit] @unchecked => @@ -111,11 +114,11 @@ private[eval] object UnsafeCancelUtils { } } - // Optimization for `cancelAll` +// Optimization for `cancelAll` private final class CancelAllFrame(cursor: Iterator[AnyRef /* Cancelable | Task[Unit] | CancelableF[Task] */ ]) extends StackFrame[Unit, Task[Unit]] { - private[this] val errors = ListBuffer.empty[Throwable] + private val errors = ListBuffer.empty[Throwable] def loop(): CancelToken[Task] = { var task: Task[Unit] = null @@ -147,7 +150,7 @@ private[eval] object UnsafeCancelUtils { case Nil => Task.unit case first :: rest => - Task.raiseError(Platform.composeErrors(first, rest: _*)) + Task.raiseError(Platform.composeErrors(first, rest*)) } } } diff --git a/monix-eval/shared/src/main/scala/monix/eval/internal/package.scala b/monix-eval/shared/src/main/scala/monix/eval/internal/package.scala index 514754d3d..c05e6c217 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/internal/package.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/internal/package.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/main/scala/monix/eval/package.scala b/monix-eval/shared/src/main/scala/monix/eval/package.scala index 387b089c1..a1ff29b7c 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/package.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/package.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ import monix.catnap.CircuitBreaker import monix.execution.atomic.PaddingStrategy import monix.execution.atomic.PaddingStrategy.NoPadding -import scala.concurrent.duration.{Duration, FiniteDuration} +import scala.concurrent.duration.{ Duration, FiniteDuration } package object eval { @@ -55,7 +55,8 @@ package object eval { onClosed: Task[Unit] = Task.unit, onHalfOpen: Task[Unit] = Task.unit, onOpen: Task[Unit] = Task.unit, - padding: PaddingStrategy = NoPadding): Task[CircuitBreaker[Task]] = { + padding: PaddingStrategy = NoPadding + ): Task[CircuitBreaker[Task]] = { // $COVERAGE-OFF$ CircuitBreaker[Task].of( diff --git a/monix-eval/shared/src/main/scala/monix/eval/tracing/CoevalEvent.scala b/monix-eval/shared/src/main/scala/monix/eval/tracing/CoevalEvent.scala index e0bc560e8..eaa133241 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/tracing/CoevalEvent.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/tracing/CoevalEvent.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,4 +27,3 @@ object CoevalEvent { final case class StackTrace(stackTrace: List[StackTraceElement]) extends CoevalEvent } - diff --git a/monix-eval/shared/src/main/scala/monix/eval/tracing/CoevalTrace.scala b/monix-eval/shared/src/main/scala/monix/eval/tracing/CoevalTrace.scala index ca0766e87..a2e12a8f2 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/tracing/CoevalTrace.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/tracing/CoevalTrace.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -122,12 +122,12 @@ private[eval] object CoevalTrace { private def demangleMethod(methodName: String): String = anonfunRegex.findFirstMatchIn(methodName) match { case Some(mat) => mat.group(1) - case None => methodName + case None => methodName } - private[this] val anonfunRegex = "^\\$+anonfun\\$+(.+)\\$+\\d+$".r + private val anonfunRegex = "^\\$+anonfun\\$+(.+)\\$+\\d+$".r - private[this] val stackTraceFilter = List( + private val stackTraceFilter = List( "monix.", "cats.effect.", "cats.", diff --git a/monix-eval/shared/src/main/scala/monix/eval/tracing/PrintingOptions.scala b/monix-eval/shared/src/main/scala/monix/eval/tracing/PrintingOptions.scala index 68c17b7ca..be15d80da 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/tracing/PrintingOptions.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/tracing/PrintingOptions.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,9 +26,11 @@ package monix.eval.tracing * * All Credits to https://github.com/typelevel/cats-effect and https://github.com/RaasAhsan */ -final case class PrintingOptions private (showFullStackTraces: Boolean, - maxStackTraceLines: Int, - ignoreStackTraceLines: Int) { +final case class PrintingOptions private ( + showFullStackTraces: Boolean, + maxStackTraceLines: Int, + ignoreStackTraceLines: Int +) { def withShowFullStackTraces(showFullStackTraces: Boolean): PrintingOptions = copy(showFullStackTraces = showFullStackTraces) @@ -47,4 +49,4 @@ object PrintingOptions { ) def apply(): PrintingOptions = Default -} \ No newline at end of file +} diff --git a/monix-eval/shared/src/main/scala/monix/eval/tracing/TaskEvent.scala b/monix-eval/shared/src/main/scala/monix/eval/tracing/TaskEvent.scala index e0cc78bee..6347c9fb9 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/tracing/TaskEvent.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/tracing/TaskEvent.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/main/scala/monix/eval/tracing/TaskTrace.scala b/monix-eval/shared/src/main/scala/monix/eval/tracing/TaskTrace.scala index 41f3238e4..6c61bbadc 100644 --- a/monix-eval/shared/src/main/scala/monix/eval/tracing/TaskTrace.scala +++ b/monix-eval/shared/src/main/scala/monix/eval/tracing/TaskTrace.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -122,12 +122,12 @@ private[eval] object TaskTrace { private def demangleMethod(methodName: String): String = anonfunRegex.findFirstMatchIn(methodName) match { case Some(mat) => mat.group(1) - case None => methodName + case None => methodName } - private[this] val anonfunRegex = "^\\$+anonfun\\$+(.+)\\$+\\d+$".r + private val anonfunRegex = "^\\$+anonfun\\$+(.+)\\$+\\d+$".r - private[this] val stackTraceFilter = List( + private val stackTraceFilter = List( "monix.", "cats.effect.", "cats.", diff --git a/monix-eval/shared/src/test/scala/monix/eval/BaseLawsSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/BaseLawsSuite.scala index 928cba222..8aea23353 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/BaseLawsSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/BaseLawsSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,21 +16,23 @@ */ package monix.eval +import scala.annotation.nowarn import cats.Eq import cats.effect.laws.discipline.Parameters -import cats.effect.laws.discipline.arbitrary.{catsEffectLawsArbitraryForIO, catsEffectLawsCogenForIO} -import cats.effect.{Async, IO} +import cats.effect.laws.discipline.arbitrary.{ catsEffectLawsArbitraryForIO, catsEffectLawsCogenForIO } +import cats.effect.{ Async, IO } import monix.execution.atomic.Atomic import monix.execution.internal.Platform import monix.execution.schedulers.TestScheduler -import org.scalacheck.Arbitrary.{arbitrary => getArbitrary} -import org.scalacheck.{Arbitrary, Cogen, Gen} -import scala.util.{Either, Success, Try} +import org.scalacheck.Arbitrary.{ arbitrary => getArbitrary } +import org.scalacheck.{ Arbitrary, Cogen, Gen } +import scala.util.{ Either, Success, Try } /** * Base trait to inherit in all `monix-eval` tests that use ScalaCheck. */ +@nowarn trait BaseLawsSuite extends monix.execution.BaseLawsSuite with ArbitraryInstances { /** * Customizes Cats-Effect's default params. @@ -47,7 +49,8 @@ trait ArbitraryInstances extends ArbitraryInstancesBase { implicit A: Eq[A], sc: TestScheduler, - opts: Task.Options = Task.defaultOptions): Eq[Task[A]] = { + opts: Task.Options = Task.defaultOptions + ): Eq[Task[A]] = { new Eq[Task[A]] { def eqv(lh: Task[A], rh: Task[A]): Boolean = @@ -59,7 +62,8 @@ trait ArbitraryInstances extends ArbitraryInstancesBase { implicit A: Eq[A], ec: TestScheduler, - opts: Task.Options = Task.defaultOptions): Eq[Task.Par[A]] = { + opts: Task.Options = Task.defaultOptions + ): Eq[Task.Par[A]] = { new Eq[Task.Par[A]] { import Task.Par.unwrap @@ -85,7 +89,8 @@ trait ArbitraryInstancesBase extends monix.execution.ArbitraryInstances { Coeval.evalOnce(a), Coeval.eval(a), Coeval.unit.map(_ => a), - Coeval.unit.flatMap(_ => Coeval.now(a))) + Coeval.unit.flatMap(_ => Coeval.now(a)) + ) } yield coeval } @@ -173,7 +178,8 @@ trait ArbitraryInstancesBase extends monix.execution.ArbitraryInstances { 1 -> getMapOne, 1 -> getMapTwo, 2 -> genFlatMap - )) + ) + ) } implicit def arbitraryTaskPar[A: Arbitrary: Cogen]: Arbitrary[Task.Par[A]] = @@ -194,17 +200,17 @@ trait ArbitraryInstancesBase extends monix.execution.ArbitraryInstances { for (f <- fun.arbitrary) yield { case (t: Throwable) => f(t.hashCode()) } } - implicit def arbitraryCoevalToLong[A, B](implicit A: Arbitrary[A], B: Arbitrary[B]): Arbitrary[Coeval[A] => B] = + implicit def arbitraryCoevalToLong[A, B](implicit B: Arbitrary[B]): Arbitrary[Coeval[A] => B] = Arbitrary { for (b <- B.arbitrary) yield (_: Coeval[A]) => b } - implicit def arbitraryTaskToLong[A, B](implicit A: Arbitrary[A], B: Arbitrary[B]): Arbitrary[Task[A] => B] = + implicit def arbitraryTaskToLong[A, B](implicit B: Arbitrary[B]): Arbitrary[Task[A] => B] = Arbitrary { for (b <- B.arbitrary) yield (_: Task[A]) => b } - implicit def arbitraryIOToLong[A, B](implicit A: Arbitrary[A], B: Arbitrary[B]): Arbitrary[IO[A] => B] = + implicit def arbitraryIOToLong[A, B](implicit B: Arbitrary[B]): Arbitrary[IO[A] => B] = Arbitrary { for (b <- B.arbitrary) yield (_: IO[A]) => b } diff --git a/monix-eval/shared/src/test/scala/monix/eval/BaseTestSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/BaseTestSuite.scala index 03b430d6a..5c90d4287 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/BaseTestSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/BaseTestSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalBracketSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalBracketSuite.scala index 26e41ba69..cffeff516 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalBracketSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalBracketSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,14 +16,16 @@ */ package monix.eval +import scala.annotation.nowarn import cats.laws._ import cats.laws.discipline._ import cats.syntax.all._ -import monix.execution.exceptions.{CompositeException, DummyException} +import monix.execution.exceptions.{ CompositeException, DummyException } import monix.execution.internal.Platform -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object CoevalBracketSuite extends BaseTestSuite { test("equivalence with onErrorHandleWith") { _ => check2 { (coeval: Coeval[Int], f: Throwable => Coeval[Unit]) => diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalCatsConversions.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalCatsConversions.scala index 69e2782c0..bd094710a 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalCatsConversions.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalCatsConversions.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,13 +16,15 @@ */ package monix.eval +import scala.annotation.nowarn import cats.Eval import cats.effect.IO import monix.execution.atomic.Atomic import monix.execution.exceptions.DummyException -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object CoevalCatsConversions extends BaseTestSuite { test("Coeval.now(value).to[Eval]") { _ => assertEquals(Coeval.now(10).to[Eval].value, 10) @@ -99,7 +101,7 @@ object CoevalCatsConversions extends BaseTestSuite { assertEquals(eval.value(), 1) } - test("Coeval.from protects against user error") { implicit s => + test("Coeval.from protects against user error") { _ => val dummy = DummyException("dummy") val eval = Coeval.from(Eval.always { throw dummy }) assertEquals(eval.runTry(), Failure(dummy)) diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalConversionsKSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalConversionsKSuite.scala index a8e4955b6..1b2ff9ab4 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalConversionsKSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalConversionsKSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.eval -import cats.effect.{Resource, SyncIO} +import cats.effect.{ Resource, SyncIO } import minitest.SimpleTestSuite object CoevalConversionsKSuite extends SimpleTestSuite { diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalErrorSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalErrorSuite.scala index 6c0403114..8484e1b45 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalErrorSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalErrorSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,30 +16,32 @@ */ package monix.eval +import scala.annotation.nowarn import monix.execution.exceptions.DummyException import scala.concurrent.TimeoutException -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object CoevalErrorSuite extends BaseTestSuite { - test("Coeval.attempt should expose error") { implicit s => + test("Coeval.attempt should expose error") { _ => val dummy = DummyException("ex") val r = Coeval.raiseError[Int](dummy).attempt.value() assertEquals(r, Left(dummy)) } - test("Coeval.attempt should expose successful value") { implicit s => + test("Coeval.attempt should expose successful value") { _ => val r = Coeval.now(10).attempt.value() assertEquals(r, Right(10)) } - test("Coeval.fail should expose error") { implicit s => + test("Coeval.fail should expose error") { _ => val dummy = DummyException("dummy") val r = Coeval.raiseError[Int](dummy).failed.value() assertEquals(r, dummy) } - test("Coeval.fail should fail for successful values") { implicit s => + test("Coeval.fail should fail for successful values") { _ => intercept[NoSuchElementException] { Coeval.now(10).failed.value() () @@ -47,75 +49,75 @@ object CoevalErrorSuite extends BaseTestSuite { () } - test("Coeval.now.materialize") { implicit s => + test("Coeval.now.materialize") { _ => assertEquals(Coeval.now(10).materialize.value(), Success(10)) } - test("Coeval.error.materialize") { implicit s => + test("Coeval.error.materialize") { _ => val dummy = DummyException("dummy") assertEquals(Coeval.raiseError[Int](dummy).materialize.value(), Failure(dummy)) } - test("Coeval.evalOnce.materialize") { implicit s => + test("Coeval.evalOnce.materialize") { _ => assertEquals(Coeval.evalOnce(10).materialize.value(), Success(10)) } - test("Coeval.eval.materialize") { implicit s => + test("Coeval.eval.materialize") { _ => assertEquals(Coeval.eval(10).materialize.value(), Success(10)) } - test("Coeval.defer.materialize") { implicit s => + test("Coeval.defer.materialize") { _ => assertEquals(Coeval.defer(Coeval.now(10)).materialize.value(), Success(10)) } - test("Coeval.defer.flatMap.materialize") { implicit s => + test("Coeval.defer.flatMap.materialize") { _ => assertEquals(Coeval.defer(Coeval.now(10)).flatMap(Coeval.now).materialize.value(), Success(10)) } - test("Coeval.error.materialize") { implicit s => + test("Coeval.error.materialize") { _ => val dummy = DummyException("dummy") assertEquals(Coeval.raiseError[Int](dummy).materialize.value(), Failure(dummy)) } - test("Coeval.flatMap.materialize") { implicit s => + test("Coeval.flatMap.materialize") { _ => assertEquals(Coeval.eval(10).flatMap(x => Coeval.now(x)).materialize.runTry(), Success(Success(10))) } - test("Coeval.now.flatMap(error).materialize") { implicit s => + test("Coeval.now.flatMap(error).materialize") { _ => val dummy = DummyException("dummy") val r = Coeval.now(10).flatMap[Int](_ => throw dummy).materialize assertEquals(r.runTry(), Success(Failure(dummy))) } - test("Coeval.defer(error).materialize") { implicit s => + test("Coeval.defer(error).materialize") { _ => val dummy = DummyException("dummy") val f = Coeval.defer[Int](throw dummy).materialize assertEquals(f.runTry(), Success(Failure(dummy))) } - test("Coeval.defer(error).flatMap.materialize") { implicit s => + test("Coeval.defer(error).flatMap.materialize") { _ => val dummy = DummyException("dummy") val f = Coeval.defer[Int](throw dummy).flatMap(Coeval.now).materialize assertEquals(f.runTry(), Success(Failure(dummy))) } - test("Coeval.now.dematerialize") { implicit s => + test("Coeval.now.dematerialize") { _ => val result = Coeval.now(10).materialize.dematerialize.runTry() assertEquals(result, Success(10)) } - test("Coeval.error.dematerialize") { implicit s => + test("Coeval.error.dematerialize") { _ => val dummy = DummyException("dummy") val result = Coeval.raiseError[Int](dummy).materialize.dematerialize.runTry() assertEquals(result, Failure(dummy)) } - test("Coeval#onErrorRecover should mirror source on success") { implicit s => + test("Coeval#onErrorRecover should mirror source on success") { _ => val coeval = Coeval(1).onErrorRecover { case _: Throwable => 99 } assertEquals(coeval.runTry(), Success(1)) } - test("Coeval#onErrorRecover should recover") { implicit s => + test("Coeval#onErrorRecover should recover") { _ => val ex = DummyException("dummy") val coeval = Coeval[Int](if (1 == 1) throw ex else 1).onErrorRecover { case _: DummyException => 99 @@ -124,7 +126,7 @@ object CoevalErrorSuite extends BaseTestSuite { assertEquals(coeval.runTry(), Success(99)) } - test("Coeval#onErrorRecover should protect against user code") { implicit s => + test("Coeval#onErrorRecover should protect against user code") { _ => val ex1 = DummyException("one") val ex2 = DummyException("two") @@ -133,19 +135,19 @@ object CoevalErrorSuite extends BaseTestSuite { assertEquals(coeval.runTry(), Failure(ex2)) } - test("Coeval#onErrorHandle should mirror source on success") { implicit s => + test("Coeval#onErrorHandle should mirror source on success") { _ => val f = Coeval(1).onErrorHandle { _ => 99 } assertEquals(f.runTry(), Success(1)) } - test("Coeval#onErrorHandle should recover") { implicit s => + test("Coeval#onErrorHandle should recover") { _ => val ex = DummyException("dummy") val f = Coeval[Int](if (1 == 1) throw ex else 1).onErrorHandle { _ => 99 } assertEquals(f.runTry(), Success(99)) } - test("Coeval#onErrorHandle should protect against user code") { implicit s => + test("Coeval#onErrorHandle should protect against user code") { _ => val ex1 = DummyException("one") val ex2 = DummyException("two") val f = Coeval[Int](if (1 == 1) throw ex1 else 1).onErrorHandle { _ => @@ -155,32 +157,32 @@ object CoevalErrorSuite extends BaseTestSuite { assertEquals(f.runTry(), Failure(ex2)) } - test("Coeval.onErrorFallbackTo should mirror source onSuccess") { implicit s => + test("Coeval.onErrorFallbackTo should mirror source onSuccess") { _ => val f = Coeval(1).onErrorFallbackTo(Coeval(2)) assertEquals(f.runTry(), Success(1)) } - test("Coeval.onErrorFallbackTo should fallback to backup onError") { implicit s => + test("Coeval.onErrorFallbackTo should fallback to backup onError") { _ => val ex = DummyException("dummy") val f = Coeval(throw ex).onErrorFallbackTo(Coeval(2)) assertEquals(f.runTry(), Success(2)) } - test("Coeval.onErrorFallbackTo should protect against user code") { implicit s => + test("Coeval.onErrorFallbackTo should protect against user code") { _ => val ex = DummyException("dummy") val err = DummyException("unexpected") val f = Coeval(throw ex).onErrorFallbackTo(Coeval.defer(throw err)) assertEquals(f.runTry(), Failure(err)) } - test("Coeval.onErrorRestart should mirror the source onSuccess") { implicit s => + test("Coeval.onErrorRestart should mirror the source onSuccess") { _ => var tries = 0 val f = Coeval.eval { tries += 1; 1 }.onErrorRestart(10) assertEquals(f.runTry(), Success(1)) assertEquals(tries, 1) } - test("Coeval.onErrorRestart should retry onError") { implicit s => + test("Coeval.onErrorRestart should retry onError") { _ => val ex = DummyException("dummy") var tries = 0 val f = Coeval.eval { tries += 1; if (tries < 5) throw ex else 1 }.onErrorRestart(10) @@ -189,7 +191,7 @@ object CoevalErrorSuite extends BaseTestSuite { assertEquals(tries, 5) } - test("Coeval.onErrorRestart should emit onError after max retries") { implicit s => + test("Coeval.onErrorRestart should emit onError after max retries") { _ => val ex = DummyException("dummy") var tries = 0 val f = Coeval.eval { tries += 1; throw ex }.onErrorRestart(10) @@ -198,14 +200,14 @@ object CoevalErrorSuite extends BaseTestSuite { assertEquals(tries, 11) } - test("Coeval.onErrorRestartIf should mirror the source onSuccess") { implicit s => + test("Coeval.onErrorRestartIf should mirror the source onSuccess") { _ => var tries = 0 val f = Coeval.eval { tries += 1; 1 }.onErrorRestartIf(_ => tries < 10) assertEquals(f.runTry(), Success(1)) assertEquals(tries, 1) } - test("Coeval.onErrorRestartIf should retry onError") { implicit s => + test("Coeval.onErrorRestartIf should retry onError") { _ => val ex = DummyException("dummy") var tries = 0 val f = Coeval.eval { tries += 1; if (tries < 5) throw ex else 1 } @@ -215,7 +217,7 @@ object CoevalErrorSuite extends BaseTestSuite { assertEquals(tries, 5) } - test("Coeval.onErrorRestartIf should emit onError") { implicit s => + test("Coeval.onErrorRestartIf should emit onError") { _ => val ex = DummyException("dummy") var tries = 0 val f = Coeval.eval { tries += 1; throw ex } @@ -225,12 +227,12 @@ object CoevalErrorSuite extends BaseTestSuite { assertEquals(tries, 11) } - test("Coeval#onErrorRecoverWith should mirror source on success") { implicit s => + test("Coeval#onErrorRecoverWith should mirror source on success") { _ => val f = Coeval(1).onErrorRecoverWith { case _: Throwable => Coeval(99) } assertEquals(f.runTry(), Success(1)) } - test("Coeval#onErrorRecoverWith should recover") { implicit s => + test("Coeval#onErrorRecoverWith should recover") { _ => val ex = DummyException("dummy") val f = Coeval[Int](throw ex).onErrorRecoverWith { case _: DummyException => Coeval(99) @@ -239,7 +241,7 @@ object CoevalErrorSuite extends BaseTestSuite { assertEquals(f.runTry(), Success(99)) } - test("Coeval#onErrorRecoverWith should protect against user code") { implicit s => + test("Coeval#onErrorRecoverWith should protect against user code") { _ => val ex1 = DummyException("one") val ex2 = DummyException("two") @@ -248,19 +250,19 @@ object CoevalErrorSuite extends BaseTestSuite { assertEquals(f.runTry(), Failure(ex2)) } - test("Coeval#onErrorRecover should emit error if not matches") { implicit s => + test("Coeval#onErrorRecover should emit error if not matches") { _ => val dummy = DummyException("dummy") val f = Coeval[Int](throw dummy).onErrorRecover { case _: TimeoutException => 10 } assertEquals(f.runTry(), Failure(dummy)) } - test("Coeval#onErrorRecoverWith should emit error if not matches") { implicit s => + test("Coeval#onErrorRecoverWith should emit error if not matches") { _ => val dummy = DummyException("dummy") val f = Coeval[Int](throw dummy).onErrorRecoverWith { case _: TimeoutException => Coeval.now(10) } assertEquals(f.runTry(), Failure(dummy)) } - test("Coeval.onErrorRestartLoop works for success") { implicit s => + test("Coeval.onErrorRestartLoop works for success") { _ => val dummy = DummyException("dummy") var tries = 0 val source = Coeval.eval { @@ -280,7 +282,7 @@ object CoevalErrorSuite extends BaseTestSuite { assertEquals(tries, 5) } - test("Coeval.onErrorRestartLoop can rethrow") { implicit s => + test("Coeval.onErrorRestartLoop can rethrow") { _ => val dummy = DummyException("dummy") val source = Coeval.eval[Int] { throw dummy } diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalEvalAlwaysSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalEvalAlwaysSuite.scala index acf4cbdac..395ef4a66 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalEvalAlwaysSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalEvalAlwaysSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,10 +21,10 @@ import cats.laws._ import cats.laws.discipline._ import monix.execution.exceptions.DummyException -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object CoevalEvalAlwaysSuite extends BaseTestSuite { - test("Coeval.eval should work synchronously") { implicit s => + test("Coeval.eval should work synchronously") { _ => var wasTriggered = false def trigger(): String = { wasTriggered = true; "result" } @@ -36,7 +36,7 @@ object CoevalEvalAlwaysSuite extends BaseTestSuite { assertEquals(f, Success("result")) } - test("Coeval.eval should protect against user code errors") { implicit s => + test("Coeval.eval should protect against user code errors") { s => val ex = DummyException("dummy") val f = Coeval.eval[Int](if (1 == 1) throw ex else 1).runTry() @@ -44,19 +44,19 @@ object CoevalEvalAlwaysSuite extends BaseTestSuite { assertEquals(s.state.lastReportedError, null) } - test("Coeval.eval.flatMap should be equivalent with Coeval.eval") { implicit s => + test("Coeval.eval.flatMap should be equivalent with Coeval.eval") { _ => val ex = DummyException("dummy") val t = Coeval.eval[Int](if (1 == 1) throw ex else 1).flatMap(Coeval.now) check(t <-> Coeval.raiseError(ex)) } - test("Coeval.eval.flatMap should protect against user code") { implicit s => + test("Coeval.eval.flatMap should protect against user code") { _ => val ex = DummyException("dummy") val t = Coeval.eval(1).flatMap[Int](_ => throw ex) check(t <-> Coeval.raiseError(ex)) } - test("Coeval.eval.map should work") { implicit s => + test("Coeval.eval.map should work") { _ => check1 { (a: Int) => Coeval.eval(a).map(_ + 1) <-> Coeval.eval(a + 1) } @@ -76,7 +76,7 @@ object CoevalEvalAlwaysSuite extends BaseTestSuite { assertEquals(f, Success(iterations * 2)) } - test("Coeval.eval(error).memoize should work") { implicit s => + test("Coeval.eval(error).memoize should work") { _ => var effect = 0 val dummy = DummyException("dummy") val task = Coeval.eval[Int] { effect += 1; throw dummy }.memoize @@ -88,27 +88,27 @@ object CoevalEvalAlwaysSuite extends BaseTestSuite { assertEquals(effect, 1) } - test("Coeval.eval.materialize should work for success") { implicit s => + test("Coeval.eval.materialize should work for success") { _ => val task = Coeval.eval(1).materialize val f = task.runTry() assertEquals(f, Success(Success(1))) } - test("Coeval.eval.materialize should work for failure") { implicit s => + test("Coeval.eval.materialize should work for failure") { _ => val dummy = DummyException("dummy") val task = Coeval.eval[Int](throw dummy).materialize val f = task.runTry() assertEquals(f, Success(Failure(dummy))) } - test("Coeval.EvalAlways.runTry() override") { implicit s => + test("Coeval.EvalAlways.runTry() override") { _ => val dummy = DummyException("dummy") val task = Coeval.eval { if (1 == 1) throw dummy else 10 } val f = task.runTry() assertEquals(f, Failure(dummy)) } - test("Coeval.eval is equivalent with Coeval.evalOnce on first run") { implicit s => + test("Coeval.eval is equivalent with Coeval.evalOnce on first run") { _ => check1 { (a: Int) => val t1 = { var effect = 100 diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalEvalOnceSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalEvalOnceSuite.scala index 1af14bf45..91f9458a6 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalEvalOnceSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalEvalOnceSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,10 +21,10 @@ import cats.laws._ import cats.laws.discipline._ import monix.execution.exceptions.DummyException -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object CoevalEvalOnceSuite extends BaseTestSuite { - test("Coeval.evalOnce should work synchronously") { implicit s => + test("Coeval.evalOnce should work synchronously") { _ => var wasTriggered = false def trigger(): String = { wasTriggered = true; "result" } @@ -36,7 +36,7 @@ object CoevalEvalOnceSuite extends BaseTestSuite { assertEquals(f, Success("result")) } - test("Coeval.evalOnce should protect against user code errors") { implicit s => + test("Coeval.evalOnce should protect against user code errors") { s => val ex = DummyException("dummy") val f = Coeval.evalOnce[Int](if (1 == 1) throw ex else 1).runTry() @@ -44,25 +44,25 @@ object CoevalEvalOnceSuite extends BaseTestSuite { assertEquals(s.state.lastReportedError, null) } - test("Coeval.evalOnce.flatMap should be equivalent with Coeval.evalOnce") { implicit s => + test("Coeval.evalOnce.flatMap should be equivalent with Coeval.evalOnce") { _ => val ex = DummyException("dummy") val t = Coeval.evalOnce[Int](if (1 == 1) throw ex else 1).flatMap(Coeval.now) check(t <-> Coeval.raiseError(ex)) } - test("Coeval.evalOnce.flatMap should protect against user code") { implicit s => + test("Coeval.evalOnce.flatMap should protect against user code") { _ => val ex = DummyException("dummy") val t = Coeval.evalOnce(1).flatMap[Int](_ => throw ex) check(t <-> Coeval.raiseError(ex)) } - test("Coeval.evalOnce.map should work") { implicit s => + test("Coeval.evalOnce.map should work") { _ => check1 { (a: Int) => Coeval.evalOnce(a).map(_ + 1) <-> Coeval.evalOnce(a + 1) } } - test("Coeval.evalOnce.flatMap should be tail recursive") { implicit s => + test("Coeval.evalOnce.flatMap should be tail recursive") { s => def loop(n: Int, idx: Int): Coeval[Int] = Coeval.evalOnce(idx).flatMap { _ => if (idx < n) loop(n, idx + 1).map(_ + 1) @@ -76,7 +76,7 @@ object CoevalEvalOnceSuite extends BaseTestSuite { assertEquals(f, Success(iterations * 2)) } - test("Coeval.eval(error).memoize should work") { implicit s => + test("Coeval.eval(error).memoize should work") { _ => var effect = 0 val dummy = DummyException("dummy") val task = Coeval.evalOnce[Int] { effect += 1; throw dummy }.memoize @@ -88,20 +88,20 @@ object CoevalEvalOnceSuite extends BaseTestSuite { assertEquals(effect, 1) } - test("Coeval.evalOnce.materialize should work for success") { implicit s => + test("Coeval.evalOnce.materialize should work for success") { _ => val task = Coeval.evalOnce(1).materialize val f = task.runTry() assertEquals(f, Success(Success(1))) } - test("Coeval.evalOnce.materialize should work for failure") { implicit s => + test("Coeval.evalOnce.materialize should work for failure") { _ => val dummy = DummyException("dummy") val task = Coeval.evalOnce[Int](throw dummy).materialize val f = task.runTry() assertEquals(f, Success(Failure(dummy))) } - test("Coeval.evalOnce.runTry() override") { implicit s => + test("Coeval.evalOnce.runTry() override") { _ => val dummy = DummyException("dummy") val task = Coeval.evalOnce { if (1 == 1) throw dummy else 10 } val f = task.runTry() diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalFlatMapSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalFlatMapSuite.scala index ec1d3e769..db2f85d7b 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalFlatMapSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalFlatMapSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,40 +21,40 @@ import cats.laws._ import cats.laws.discipline._ import monix.execution.exceptions.DummyException -import scala.util.{Random, Success} +import scala.util.{ Random, Success } object CoevalFlatMapSuite extends BaseTestSuite { - test("transformWith equivalence with flatMap") { implicit s => + test("transformWith equivalence with flatMap") { _ => check2 { (fa: Coeval[Int], f: Int => Coeval[Int]) => fa.redeemWith(Coeval.raiseError, f) <-> fa.flatMap(f) } } - test("transform equivalence with map") { implicit s => + test("transform equivalence with map") { _ => check2 { (fa: Coeval[Int], f: Int => Int) => fa.redeem(ex => throw ex, f) <-> fa.map(f) } } - test("transformWith can recover") { implicit s => + test("transformWith can recover") { _ => val dummy = new DummyException("dummy") val coeval = Coeval.raiseError[Int](dummy).redeemWith(_ => Coeval.now(1), Coeval.now) assertEquals(coeval.runTry(), Success(1)) } - test("transform can recover") { implicit s => + test("transform can recover") { _ => val dummy = new DummyException("dummy") val coeval = Coeval.raiseError[Int](dummy).redeem(_ => 1, identity) assertEquals(coeval.runTry(), Success(1)) } - test(">> is stack safe for infinite loops") { implicit s => + test(">> is stack safe for infinite loops") { _ => def looped: Coeval[Unit] = Coeval.unit >> looped val _ = looped assert(true) } - test("flatMapLoop enables loops") { implicit s => + test("flatMapLoop enables loops") { _ => val random = Coeval(Random.nextInt()) val loop = random.flatMapLoop(Vector.empty[Int]) { (a, list, continue) => val newList = list :+ a @@ -66,13 +66,13 @@ object CoevalFlatMapSuite extends BaseTestSuite { assertEquals(loop.apply().size, 5) } - test("fa *> fb <-> fa.flatMap(_ => fb)") { implicit s => + test("fa *> fb <-> fa.flatMap(_ => fb)") { _ => check2 { (fa: Coeval[Int], fb: Coeval[Int]) => fa *> fb <-> fa.flatMap(_ => fb) } } - test("fa <* fb <-> fa.flatMap(a => fb.map(_ => a))") { implicit s => + test("fa <* fb <-> fa.flatMap(a => fb.map(_ => a))") { _ => check2 { (fa: Coeval[Int], fb: Coeval[Int]) => fa <* fb <-> fa.flatMap(a => fb.map(_ => a)) } diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalGuaranteeSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalGuaranteeSuite.scala index 4d49d39d5..1c58d006d 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalGuaranteeSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalGuaranteeSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,9 @@ package monix.eval -import monix.execution.exceptions.{CompositeException, DummyException} +import monix.execution.exceptions.{ CompositeException, DummyException } import monix.execution.internal.Platform -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object CoevalGuaranteeSuite extends BaseTestSuite { diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalLeftSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalLeftSuite.scala index a1f4bf2a4..cdb371bdf 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalLeftSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalLeftSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.eval object CoevalLeftSuite extends BaseTestSuite { - test("Coeval.left should return a Now with a Left") { implicit s => + test("Coeval.left should return a Now with a Left") { _ => val t = Coeval.left[Int, String](1) t.value() match { diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalLikeConversionsSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalLikeConversionsSuite.scala index 6caa60830..3d2239b94 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalLikeConversionsSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalLikeConversionsSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ import cats.effect.SyncIO import minitest.SimpleTestSuite import monix.execution.exceptions.DummyException -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } object CoevalLikeConversionsSuite extends SimpleTestSuite { test("Coeval.from(Coeval)") { diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalMemoizeOnSuccessSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalMemoizeOnSuccessSuite.scala index c1dd24db4..e00cdddb5 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalMemoizeOnSuccessSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalMemoizeOnSuccessSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,14 +16,16 @@ */ package monix.eval +import scala.annotation.nowarn import monix.execution.exceptions.DummyException import monix.execution.internal.Platform -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object CoevalMemoizeOnSuccessSuite extends BaseTestSuite { - test("Coeval.eval.memoizeOnSuccess should work for first subscriber") { implicit s => + test("Coeval.eval.memoizeOnSuccess should work for first subscriber") { _ => var effect = 0 val coeval = Coeval.eval { effect += 1; effect }.memoizeOnSuccess @@ -31,7 +33,7 @@ object CoevalMemoizeOnSuccessSuite extends BaseTestSuite { assertEquals(f, Success(1)) } - test("Coeval.eval.memoizeOnSuccess should work for next subscribers") { implicit s => + test("Coeval.eval.memoizeOnSuccess should work for next subscribers") { _ => var effect = 0 val coeval = Coeval.eval { effect += 1; effect }.memoizeOnSuccess coeval.runTry() @@ -42,7 +44,7 @@ object CoevalMemoizeOnSuccessSuite extends BaseTestSuite { assertEquals(f2, Success(1)) } - test("Coeval.evalOnce.memoizeOnSuccess should work for first subscriber") { implicit s => + test("Coeval.evalOnce.memoizeOnSuccess should work for first subscriber") { _ => var effect = 0 val coeval = Coeval.evalOnce { effect += 1; effect }.memoizeOnSuccess @@ -50,7 +52,7 @@ object CoevalMemoizeOnSuccessSuite extends BaseTestSuite { assertEquals(f, Success(1)) } - test("Coeval.evalOnce.memoizeOnSuccess should work for next subscribers") { implicit s => + test("Coeval.evalOnce.memoizeOnSuccess should work for next subscribers") { _ => var effect = 0 val coeval = Coeval.evalOnce { effect += 1; effect }.memoizeOnSuccess coeval.runTry() @@ -61,16 +63,16 @@ object CoevalMemoizeOnSuccessSuite extends BaseTestSuite { assertEquals(f2, Success(1)) } - test("Coeval.now.memoizeOnSuccess should return self") { implicit s => + test("Coeval.now.memoizeOnSuccess should return self") { _ => assertEquals(Coeval.now(10), Coeval.now(10).memoizeOnSuccess) } - test("Coeval.error.memoizeOnSuccess should return self") { implicit s => + test("Coeval.error.memoizeOnSuccess should return self") { _ => val dummy = DummyException("dummy") assertEquals(Coeval.raiseError(dummy), Coeval.raiseError(dummy).memoizeOnSuccess) } - test("Coeval.memoizeOnSuccess should be stack safe") { implicit s => + test("Coeval.memoizeOnSuccess should be stack safe") { _ => var effect = 0 var coeval = Coeval { effect += 1; effect } val count = if (Platform.isJVM) 100000 else 5000 @@ -78,7 +80,7 @@ object CoevalMemoizeOnSuccessSuite extends BaseTestSuite { assertEquals(coeval.runTry(), Success(1)) } - test("Coeval.apply.memoizeOnSuccess effects") { implicit s => + test("Coeval.apply.memoizeOnSuccess effects") { _ => var effect = 0 val coeval1 = Coeval { effect += 1; 3 }.memoizeOnSuccess val coeval2 = coeval1.map { x => @@ -94,7 +96,7 @@ object CoevalMemoizeOnSuccessSuite extends BaseTestSuite { assertEquals(result2, Success(4)) } - test("Coeval.suspend.memoizeOnSuccess effects") { implicit s => + test("Coeval.suspend.memoizeOnSuccess effects") { _ => var effect = 0 val coeval1 = Coeval.defer { effect += 1; Coeval.now(3) }.memoizeOnSuccess val coeval2 = coeval1.map { x => @@ -110,7 +112,7 @@ object CoevalMemoizeOnSuccessSuite extends BaseTestSuite { assertEquals(result2, Success(4)) } - test("Coeval.suspend.flatMap.memoizeOnSuccess effects") { implicit s => + test("Coeval.suspend.flatMap.memoizeOnSuccess effects") { _ => var effect = 0 val coeval1 = Coeval.defer { effect += 1; Coeval.now(2) } .flatMap(x => Coeval.now(x + 1)) @@ -128,7 +130,7 @@ object CoevalMemoizeOnSuccessSuite extends BaseTestSuite { assertEquals(result2, Success(4)) } - test("Coeval.eval(throw).memoizeOnSuccess should not cache errors") { implicit s => + test("Coeval.eval(throw).memoizeOnSuccess should not cache errors") { _ => var effect = 0 val dummy = DummyException("dummy") val coeval = Coeval.eval { @@ -145,7 +147,7 @@ object CoevalMemoizeOnSuccessSuite extends BaseTestSuite { assertEquals(effect, 3) } - test("Coeval.eval(throw).map.memoizeOnSuccess should not cache errors") { implicit s => + test("Coeval.eval(throw).map.memoizeOnSuccess should not cache errors") { _ => var effect = 0 val dummy = DummyException("dummy") val coeval = @@ -163,32 +165,32 @@ object CoevalMemoizeOnSuccessSuite extends BaseTestSuite { assertEquals(effect, 3) } - test("Coeval.evalOnce eq Coeval.evalOnce.memoizeOnSuccess") { implicit s => + test("Coeval.evalOnce eq Coeval.evalOnce.memoizeOnSuccess") { _ => val coeval = Coeval.evalOnce(1) assertEquals(coeval, coeval.memoizeOnSuccess) } - test("Coeval.eval.memoizeOnSuccess eq Coeval.eval.memoizeOnSuccess.memoizeOnSuccess") { implicit s => + test("Coeval.eval.memoizeOnSuccess eq Coeval.eval.memoizeOnSuccess.memoizeOnSuccess") { _ => val coeval = Coeval.eval(1).memoizeOnSuccess assertEquals(coeval, coeval.memoizeOnSuccess) } - test("Coeval.eval.memoize eq Coeval.eval.memoize.memoizeOnSuccess") { implicit s => + test("Coeval.eval.memoize eq Coeval.eval.memoize.memoizeOnSuccess") { _ => val coeval = Coeval.eval(1).memoize assertEquals(coeval, coeval.memoizeOnSuccess) } - test("Coeval.eval.map.memoize eq Coeval.eval.map.memoize.memoizeOnSuccess") { implicit s => + test("Coeval.eval.map.memoize eq Coeval.eval.map.memoize.memoizeOnSuccess") { _ => val coeval = Coeval.eval(1).map(_ + 1).memoize assertEquals(coeval, coeval.memoizeOnSuccess) } - test("Coeval.now.memoizeOnSuccess eq Coeval.now") { implicit s => + test("Coeval.now.memoizeOnSuccess eq Coeval.now") { _ => val coeval = Coeval.now(1) assertEquals(coeval, coeval.memoizeOnSuccess) } - test("Coeval.raiseError.memoizeOnSuccess eq Coeval.raiseError") { implicit s => + test("Coeval.raiseError.memoizeOnSuccess eq Coeval.raiseError") { _ => val coeval = Coeval.raiseError(DummyException("dummy")) assertEquals(coeval, coeval.memoizeOnSuccess) } diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalMemoizeSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalMemoizeSuite.scala index e18fc0897..be1abcc89 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalMemoizeSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalMemoizeSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,14 +16,16 @@ */ package monix.eval +import scala.annotation.nowarn import monix.execution.exceptions.DummyException import monix.execution.internal.Platform import scala.util.Success +@nowarn object CoevalMemoizeSuite extends BaseTestSuite { - test("Coeval.eval.memoize should work for first subscriber") { implicit s => + test("Coeval.eval.memoize should work for first subscriber") { _ => var effect = 0 val coeval = Coeval.eval { effect += 1; effect }.memoize @@ -31,7 +33,7 @@ object CoevalMemoizeSuite extends BaseTestSuite { assertEquals(f, Success(1)) } - test("Coeval.eval.memoize should work for next subscribers") { implicit s => + test("Coeval.eval.memoize should work for next subscribers") { _ => var effect = 0 val coeval = Coeval.eval { effect += 1; effect }.memoize coeval.runTry() @@ -42,7 +44,7 @@ object CoevalMemoizeSuite extends BaseTestSuite { assertEquals(f2, Success(1)) } - test("Coeval.evalOnce.memoize should work for first subscriber") { implicit s => + test("Coeval.evalOnce.memoize should work for first subscriber") { _ => var effect = 0 val coeval = Coeval.evalOnce { effect += 1; effect }.memoize @@ -50,7 +52,7 @@ object CoevalMemoizeSuite extends BaseTestSuite { assertEquals(f, Success(1)) } - test("Coeval.evalOnce.memoize should work for next subscribers") { implicit s => + test("Coeval.evalOnce.memoize should work for next subscribers") { _ => var effect = 0 val coeval = Coeval.evalOnce { effect += 1; effect }.memoize coeval.runTry() @@ -61,16 +63,16 @@ object CoevalMemoizeSuite extends BaseTestSuite { assertEquals(f2, Success(1)) } - test("Coeval.now.memoize should return self") { implicit s => + test("Coeval.now.memoize should return self") { _ => assertEquals(Coeval.now(10), Coeval.now(10).memoize) } - test("Coeval.error.memoize should return self") { implicit s => + test("Coeval.error.memoize should return self") { _ => val dummy = DummyException("dummy") assertEquals(Coeval.raiseError(dummy), Coeval.raiseError(dummy).memoize) } - test("Coeval.memoize should be stack safe") { implicit s => + test("Coeval.memoize should be stack safe") { _ => var effect = 0 var coeval = Coeval { effect += 1; effect } val count = if (Platform.isJVM) 100000 else 5000 @@ -78,7 +80,7 @@ object CoevalMemoizeSuite extends BaseTestSuite { assertEquals(coeval.runTry(), Success(1)) } - test("Coeval.apply.memoize effects") { implicit s => + test("Coeval.apply.memoize effects") { _ => var effect = 0 val coeval1 = Coeval { effect += 1; 3 }.memoize val coeval2 = coeval1.map { x => @@ -94,7 +96,7 @@ object CoevalMemoizeSuite extends BaseTestSuite { assertEquals(result2, Success(4)) } - test("Coeval.suspend.memoize effects") { implicit s => + test("Coeval.suspend.memoize effects") { _ => var effect = 0 val coeval1 = Coeval.defer { effect += 1; Coeval.now(3) }.memoize val coeval2 = coeval1.map { x => @@ -110,7 +112,7 @@ object CoevalMemoizeSuite extends BaseTestSuite { assertEquals(result2, Success(4)) } - test("Coeval.suspend.flatMap.memoize effects") { implicit s => + test("Coeval.suspend.flatMap.memoize effects") { _ => var effect = 0 val coeval1 = Coeval.defer { effect += 1; Coeval.now(2) } .flatMap(x => Coeval.now(x + 1)) diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalMiscSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalMiscSuite.scala index db75bc6b4..8edca0181 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalMiscSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalMiscSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,26 +16,28 @@ */ package monix.eval +import scala.annotation.nowarn import cats.laws._ import cats.laws.discipline._ import monix.execution.exceptions.DummyException -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object CoevalMiscSuite extends BaseTestSuite { - test("Coeval.now.attempt should succeed") { implicit s => + test("Coeval.now.attempt should succeed") { _ => val result = Coeval.now(1).attempt.value() assertEquals(result, Right(1)) } - test("Coeval.raiseError.attempt should expose error") { implicit s => + test("Coeval.raiseError.attempt should expose error") { _ => val ex = DummyException("dummy") val result = Coeval.raiseError[Int](ex).attempt.value() assertEquals(result, Left(ex)) } - test("Coeval.fail should expose error") { implicit s => + test("Coeval.fail should expose error") { _ => val dummy = DummyException("dummy") check1 { (fa: Coeval[Int]) => val r = fa.map(_ => throw dummy).failed.value() @@ -43,7 +45,7 @@ object CoevalMiscSuite extends BaseTestSuite { } } - test("Coeval.fail should fail for successful values") { implicit s => + test("Coeval.fail should fail for successful values") { _ => intercept[NoSuchElementException] { Coeval.eval(10).failed.value() () @@ -51,24 +53,24 @@ object CoevalMiscSuite extends BaseTestSuite { () } - test("Coeval.map protects against user code") { implicit s => + test("Coeval.map protects against user code") { _ => val ex = DummyException("dummy") val result = Coeval.now(1).map(_ => throw ex).runTry() assertEquals(result, Failure(ex)) } - test("Coeval.now.dematerialize") { implicit s => + test("Coeval.now.dematerialize") { _ => val result = Coeval.now(1).materialize.dematerialize.runTry() assertEquals(result, Success(1)) } - test("Coeval.raiseError.dematerialize") { implicit s => + test("Coeval.raiseError.dematerialize") { _ => val ex = DummyException("dummy") val result = Coeval.raiseError[Int](ex).materialize.dematerialize.runTry() assertEquals(result, Failure(ex)) } - test("Coeval.restartUntil") { implicit s => + test("Coeval.restartUntil") { _ => var i = 0 val r = Coeval { i += 1; i @@ -76,7 +78,7 @@ object CoevalMiscSuite extends BaseTestSuite { assertEquals(r, 11) } - test("Coeval.pure is an alias of now") { implicit s => + test("Coeval.pure is an alias of now") { _ => assertEquals(Coeval.pure(1), Coeval.now(1)) } @@ -89,14 +91,14 @@ object CoevalMiscSuite extends BaseTestSuite { assertEquals(fa.value(), 3) } - test("Coeval.flatten is equivalent with flatMap") { implicit s => + test("Coeval.flatten is equivalent with flatMap") { _ => check1 { (nr: Int) => val ref = Coeval(Coeval(nr)) ref.flatten <-> ref.flatMap(x => x) } } - test("Coeval.error.flatten is equivalent with flatMap") { implicit s => + test("Coeval.error.flatten is equivalent with flatMap") { _ => val ex = DummyException("dummy") val ref = Coeval(Coeval.raiseError[Int](ex)) assertEquals(ref.flatten.runTry(), ref.flatMap(x => x).runTry()) diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalNowSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalNowSuite.scala index 96aa2a782..9144e6d87 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalNowSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalNowSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,15 +16,17 @@ */ package monix.eval +import scala.annotation.nowarn import cats.laws._ import cats.laws.discipline._ import monix.execution.exceptions.DummyException -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object CoevalNowSuite extends BaseTestSuite { - test("Coeval.now should work") { implicit s => + test("Coeval.now should work") { _ => var wasTriggered = false def trigger(): String = { wasTriggered = true; "result" } @@ -34,12 +36,12 @@ object CoevalNowSuite extends BaseTestSuite { assertEquals(r, Success("result")) } - test("Coeval.now.isSuccess") { implicit s => + test("Coeval.now.isSuccess") { _ => assert(Coeval.Now(1).isSuccess, "isSuccess") assert(!Coeval.Now(1).isError, "!isFailure") } - test("Coeval.error should work synchronously") { implicit s => + test("Coeval.error should work synchronously") { _ => var wasTriggered = false val dummy = DummyException("dummy") def trigger(): Throwable = { wasTriggered = true; dummy } @@ -50,28 +52,28 @@ object CoevalNowSuite extends BaseTestSuite { assertEquals(r, Failure(dummy)) } - test("Coeval.now.map should work") { implicit s => + test("Coeval.now.map should work") { _ => Coeval.now(1).map(_ + 1).value() check1 { (a: Int) => Coeval.now(a).map(_ + 1) <-> Coeval.now(a + 1) } } - test("Coeval.error.map should be the same as Coeval.error") { implicit s => + test("Coeval.error.map should be the same as Coeval.error") { _ => check { val dummy = DummyException("dummy") Coeval.raiseError[Int](dummy).map(_ + 1) <-> Coeval.raiseError[Int](dummy) } } - test("Coeval.error.flatMap should be the same as Coeval.flatMap") { implicit s => + test("Coeval.error.flatMap should be the same as Coeval.flatMap") { _ => check { val dummy = DummyException("dummy") Coeval.raiseError[Int](dummy).flatMap(Coeval.now) <-> Coeval.raiseError(dummy) } } - test("Coeval.error.flatMap should be protected") { implicit s => + test("Coeval.error.flatMap should be protected") { _ => check { val dummy = DummyException("dummy") val err = DummyException("err") @@ -79,13 +81,13 @@ object CoevalNowSuite extends BaseTestSuite { } } - test("Coeval.now.flatMap should protect against user code") { implicit s => + test("Coeval.now.flatMap should protect against user code") { _ => val ex = DummyException("dummy") val t = Coeval.now(1).flatMap[Int](_ => throw ex) check(t <-> Coeval.raiseError(ex)) } - test("Coeval.now.flatMap should be tail recursive") { implicit s => + test("Coeval.now.flatMap should be tail recursive") { s => def loop(n: Int, idx: Int): Coeval[Int] = Coeval.now(idx).flatMap { _ => if (idx < n) loop(n, idx + 1).map(_ + 1) @@ -98,12 +100,12 @@ object CoevalNowSuite extends BaseTestSuite { assertEquals(r, Success(iterations * 2)) } - test("Coeval.now.materialize should work") { implicit s => + test("Coeval.now.materialize should work") { _ => val task = Coeval.now(1).materialize assertEquals(task.value(), Success(1)) } - test("Coeval.error.materialize should work") { implicit s => + test("Coeval.error.materialize should work") { _ => val dummy = DummyException("dummy") val task = Coeval.raiseError(dummy).materialize assertEquals(task.value(), Failure(dummy)) diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalOptionSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalOptionSuite.scala index 6417ffa5e..46731e30a 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalOptionSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalOptionSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,13 +18,13 @@ package monix.eval object CoevalOptionSuite extends BaseTestSuite { - test("Coeval.none should return a Now with a None") { implicit s => + test("Coeval.none should return a Now with a None") { _ => val c = Coeval.none[Int] assertEquals(c.value(), None) } - test("Coeval.some should return a Now with a Some") { implicit s => + test("Coeval.some should return a Now with a Some") { _ => val c = Coeval.some[Int](1) assertEquals(c.value(), Some(1)) diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalRightSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalRightSuite.scala index acf2b2040..43ec02979 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalRightSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalRightSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.eval object CoevalRightSuite extends BaseTestSuite { - test("Coeval.right should return a Now with a Right") { implicit s => + test("Coeval.right should return a Now with a Right") { _ => val t = Coeval.right[Int, String]("t") t.value() match { case Right(_: String) => diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalRunSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalRunSuite.scala index ef9c677e9..edfd97edc 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalRunSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalRunSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,10 +16,12 @@ */ package monix.eval +import scala.annotation.nowarn import monix.execution.exceptions.DummyException -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } +@nowarn object CoevalRunSuite extends BaseTestSuite { def testRun(build: (() => Int) => Coeval[Int]): Unit = { val fa1 = build(() => 10 + 20) diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalSequenceSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalSequenceSuite.scala index 417e6d813..e0fc6d2c0 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalSequenceSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalSequenceSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,28 +16,30 @@ */ package monix.eval +import scala.annotation.nowarn import cats.laws._ import cats.laws.discipline._ +@nowarn object CoevalSequenceSuite extends BaseTestSuite { - test("Coeval.sequence") { implicit s => + test("Coeval.sequence") { _ => check1 { (numbers: List[Int]) => val coeval = Coeval.sequence(numbers.map(x => Coeval(x))) coeval <-> Coeval(numbers) } } - test("Coeval.traverse") { implicit s => + test("Coeval.traverse") { _ => check1 { (numbers: List[Int]) => val coeval = Coeval.traverse(numbers)(x => Coeval(x)) coeval <-> Coeval(numbers) } } - test("Coeval.zipList") { implicit s => + test("Coeval.zipList") { _ => check1 { (numbers: List[Int]) => - val coeval = Coeval.zipList(numbers.map(x => Coeval(x)): _*) + val coeval = Coeval.zipList(numbers.map(x => Coeval(x))*) coeval <-> Coeval(numbers) } } diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalToStringSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalToStringSuite.scala index cfbcf9525..23d85ff4d 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalToStringSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalToStringSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/test/scala/monix/eval/CoevalZipSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/CoevalZipSuite.scala index 35b8c6649..91e5dfb5f 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/CoevalZipSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/CoevalZipSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,73 +20,73 @@ package monix.eval import scala.util.Success object CoevalZipSuite extends BaseTestSuite { - test("Coeval#zip works") { implicit s => + test("Coeval#zip works") { _ => def n(n: Int) = Coeval.now(n) val t = n(1).zip(n(2)) assertEquals(t.runTry(), Success((1, 2))) } - test("Coeval#zipMap works") { implicit s => + test("Coeval#zipMap works") { _ => def n(n: Int) = Coeval.now(n) val t = n(1).zipMap(n(2))((_, _)) assertEquals(t.runTry(), Success((1, 2))) } - test("Coeval#zip2 works") { implicit s => + test("Coeval#zip2 works") { _ => def n(n: Int) = Coeval.now(n) val t = Coeval.zip2(n(1), n(2)) assertEquals(t.runTry(), Success((1, 2))) } - test("Coeval#zipWith2 works") { implicit s => + test("Coeval#zipWith2 works") { _ => def n(n: Int) = Coeval.now(n) val t = Coeval.map2(n(1), n(2))((_, _)) assertEquals(t.runTry(), Success((1, 2))) } - test("Coeval#zip3 works") { implicit s => + test("Coeval#zip3 works") { _ => def n(n: Int) = Coeval.now(n) val t = Coeval.zip3(n(1), n(2), n(3)) assertEquals(t.runTry(), Success((1, 2, 3))) } - test("Coeval#zipMap3 works") { implicit s => + test("Coeval#zipMap3 works") { _ => def n(n: Int) = Coeval.now(n) val t = Coeval.map3(n(1), n(2), n(3))((_, _, _)) assertEquals(t.runTry(), Success((1, 2, 3))) } - test("Coeval#zip4 works") { implicit s => + test("Coeval#zip4 works") { _ => def n(n: Int) = Coeval.now(n) val t = Coeval.zip4(n(1), n(2), n(3), n(4)) assertEquals(t.runTry(), Success((1, 2, 3, 4))) } - test("Coeval#zipMap4 works") { implicit s => + test("Coeval#zipMap4 works") { _ => def n(n: Int) = Coeval.now(n) val t = Coeval.map4(n(1), n(2), n(3), n(4))((_, _, _, _)) assertEquals(t.runTry(), Success((1, 2, 3, 4))) } - test("Coeval#zip5 works") { implicit s => + test("Coeval#zip5 works") { _ => def n(n: Int) = Coeval.now(n) val t = Coeval.zip5(n(1), n(2), n(3), n(4), n(5)) assertEquals(t.runTry(), Success((1, 2, 3, 4, 5))) } - test("Coeval#zipMap5 works") { implicit s => + test("Coeval#zipMap5 works") { _ => def n(n: Int) = Coeval.now(n) val t = Coeval.map5(n(1), n(2), n(3), n(4), n(5))((_, _, _, _, _)) assertEquals(t.runTry(), Success((1, 2, 3, 4, 5))) } - test("Coeval#zip6 works") { implicit s => + test("Coeval#zip6 works") { _ => def n(n: Int) = Coeval.now(n) val t = Coeval.zip6(n(1), n(2), n(3), n(4), n(5), n(6)) assertEquals(t.runTry(), Success((1, 2, 3, 4, 5, 6))) } - test("Coeval#zipMap6 works") { implicit s => + test("Coeval#zipMap6 works") { _ => def n(n: Int) = Coeval.now(n) val t = Coeval.map6(n(1), n(2), n(3), n(4), n(5), n(6))((_, _, _, _, _, _)) assertEquals(t.runTry(), Success((1, 2, 3, 4, 5, 6))) diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskAppSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskAppSuite.scala index c7ba712aa..aee16a0d8 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskAppSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskAppSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.eval -import cats.effect.{ExitCode, IO} +import cats.effect.{ ExitCode, IO } import minitest.SimpleTestSuite import monix.eval.Task.Options import monix.execution.Scheduler.Implicits.global diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskAsyncBoundarySuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskAsyncBoundarySuite.scala index 9932a2e5e..25106c3ec 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskAsyncBoundarySuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskAsyncBoundarySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskAsyncSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskAsyncSuite.scala index a55559902..5c0a6392b 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskAsyncSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskAsyncSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.eval import monix.execution.exceptions.DummyException -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } import scala.concurrent.duration._ object TaskAsyncSuite extends BaseTestSuite { diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskBracketSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskBracketSuite.scala index 43afc87de..7a30d42a4 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskBracketSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskBracketSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,16 +16,18 @@ */ package monix.eval +import scala.annotation.nowarn import cats.effect.concurrent.Deferred import cats.laws._ import cats.laws.discipline._ import cats.syntax.all._ -import monix.execution.exceptions.{CompositeException, DummyException} +import monix.execution.exceptions.{ CompositeException, DummyException } import monix.execution.internal.Platform import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object TaskBracketSuite extends BaseTestSuite { test("equivalence with onErrorHandleWith") { implicit sc => check2 { (task: Task[Int], f: Throwable => Task[Unit]) => @@ -241,10 +243,10 @@ object TaskBracketSuite extends BaseTestSuite { test("cancel should wait for already started finalizers on success") { implicit sc => val fa = for { - pa <- Deferred[Task, Unit] + pa <- Deferred[Task, Unit] fiber <- Task.unit.guarantee(pa.complete(()) >> Task.sleep(1.second)).start - _ <- pa.get - _ <- fiber.cancel + _ <- pa.get + _ <- fiber.cancel } yield () val f = fa.runToFuture @@ -260,10 +262,10 @@ object TaskBracketSuite extends BaseTestSuite { val dummy = new RuntimeException("dummy") val fa = for { - pa <- Deferred[Task, Unit] + pa <- Deferred[Task, Unit] fiber <- Task.unit.guarantee(pa.complete(()) >> Task.sleep(1.second) >> Task.raiseError(dummy)).start - _ <- pa.get - _ <- fiber.cancel + _ <- pa.get + _ <- fiber.cancel } yield () val f = fa.runToFuture @@ -280,9 +282,7 @@ object TaskBracketSuite extends BaseTestSuite { val fa = for { pa <- Deferred[Task, Unit] fibA <- Task.unit - .bracket( - _ => Task.unit.guarantee(pa.complete(()) >> Task.sleep(2.second)) - )(_ => Task.unit) + .bracket(_ => Task.unit.guarantee(pa.complete(()) >> Task.sleep(2.second)))(_ => Task.unit) .start _ <- pa.get _ <- fibA.cancel @@ -302,9 +302,7 @@ object TaskBracketSuite extends BaseTestSuite { val fa = for { pa <- Deferred[Task, Unit] fiber <- Task.unit - .bracket( - _ => (pa.complete(()) >> Task.never).guarantee(Task.sleep(2.second)) - )(_ => Task.unit) + .bracket(_ => (pa.complete(()) >> Task.never).guarantee(Task.sleep(2.second)))(_ => Task.unit) .start _ <- pa.get _ <- Task.race(fiber.cancel, fiber.cancel) @@ -367,8 +365,8 @@ object TaskBracketSuite extends BaseTestSuite { val fa = for { fiber <- Task.sleep(1.second).start - _ <- fiber.cancel - _ <- fiber.cancel + _ <- fiber.cancel + _ <- fiber.cancel } yield () val f = fa.runToFuture diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskCallbackSafetySuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskCallbackSafetySuite.scala index 0a97709b1..8cb968a7f 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskCallbackSafetySuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskCallbackSafetySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,12 +16,14 @@ */ package monix.eval +import scala.annotation.nowarn import monix.execution.Callback import monix.execution.exceptions.CallbackCalledMultipleTimesException import monix.execution.schedulers.TestScheduler -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object TaskCallbackSafetySuite extends BaseTestSuite { test("Task.async's callback can be called multiple times") { implicit sc => runTestCanCallMultipleTimes(Task.async) @@ -39,14 +41,16 @@ object TaskCallbackSafetySuite extends BaseTestSuite { runTestCanCallMultipleTimes(r => Task.cancelable { cb => r(cb); Task.unit - }) + } + ) } test("Task.cancelable0's callback can be called multiple times") { implicit sc => runTestCanCallMultipleTimes(r => Task.cancelable0 { (_, cb) => r(cb); Task.unit - }) + } + ) } test("Task.async's register throwing is signaled as error") { implicit sc => @@ -69,14 +73,16 @@ object TaskCallbackSafetySuite extends BaseTestSuite { runTestRegisterCanThrow(r => Task.cancelable { cb => r(cb); Task.unit - }) + } + ) } test("Task.cancelable0's register throwing is signaled as error") { implicit sc => runTestRegisterCanThrow(r => Task.cancelable0 { (_, cb) => r(cb); Task.unit - }) + } + ) } test("Task.async's register throwing, after result, is reported") { implicit sc => @@ -99,18 +105,21 @@ object TaskCallbackSafetySuite extends BaseTestSuite { runTestRegisterThrowingCanBeReported(r => Task.cancelable { cb => r(cb); Task.unit - }) + } + ) } test("Task.cancelable0's register throwing, after result, is reported") { implicit sc => runTestRegisterThrowingCanBeReported(r => Task.cancelable0 { (_, cb) => r(cb); Task.unit - }) + } + ) } def runTestRegisterCanThrow(create: (Callback[Throwable, Int] => Unit) => Task[Int])( - implicit sc: TestScheduler): Unit = { + implicit sc: TestScheduler + ): Unit = { var effect = 0 val task = create { _ => @@ -129,7 +138,8 @@ object TaskCallbackSafetySuite extends BaseTestSuite { } def runTestRegisterThrowingCanBeReported(create: (Callback[Throwable, Int] => Unit) => Task[Int])( - implicit sc: TestScheduler): Unit = { + implicit sc: TestScheduler + ): Unit = { var effect = 0 val task = create { cb => @@ -149,7 +159,8 @@ object TaskCallbackSafetySuite extends BaseTestSuite { } def runTestCanCallMultipleTimes(create: (Callback[Throwable, Int] => Unit) => Task[Int])( - implicit sc: TestScheduler): Unit = { + implicit sc: TestScheduler + ): Unit = { def run(expected: Int)(trySignal: Callback[Throwable, Int] => Boolean) = { var effect = 0 @@ -177,15 +188,18 @@ object TaskCallbackSafetySuite extends BaseTestSuite { run(1)(cb => try { cb.onSuccess(1); true - } catch { case _: CallbackCalledMultipleTimesException => false }) + } catch { case _: CallbackCalledMultipleTimesException => false } + ) run(1)(cb => try { cb(Right(1)); true - } catch { case _: CallbackCalledMultipleTimesException => false }) + } catch { case _: CallbackCalledMultipleTimesException => false } + ) run(1)(cb => try { cb(Success(1)); true - } catch { case _: CallbackCalledMultipleTimesException => false }) + } catch { case _: CallbackCalledMultipleTimesException => false } + ) run(10)(_.tryOnError(WrappedEx(10))) run(10)(_.tryApply(Failure(WrappedEx(10)))) @@ -194,15 +208,18 @@ object TaskCallbackSafetySuite extends BaseTestSuite { run(10)(cb => try { cb.onError(WrappedEx(10)); true - } catch { case _: CallbackCalledMultipleTimesException => false }) + } catch { case _: CallbackCalledMultipleTimesException => false } + ) run(10)(cb => try { cb(Left(WrappedEx(10))); true - } catch { case _: CallbackCalledMultipleTimesException => false }) + } catch { case _: CallbackCalledMultipleTimesException => false } + ) run(10)(cb => try { cb(Failure(WrappedEx(10))); true - } catch { case _: CallbackCalledMultipleTimesException => false }) + } catch { case _: CallbackCalledMultipleTimesException => false } + ) } case class WrappedEx(nr: Int) extends RuntimeException diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskCancelableSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskCancelableSuite.scala index 36dfa6d9c..45f6fbaeb 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskCancelableSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskCancelableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,14 +16,16 @@ */ package monix.eval +import scala.annotation.nowarn import cats.effect.ExitCase import monix.execution.Callback import monix.execution.cancelables.BooleanCancelable import monix.execution.exceptions.DummyException -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } +@nowarn object TaskCancelableSuite extends BaseTestSuite { test("Task.cancelable0 should be stack safe on repeated, right-associated binds") { implicit s => def signal[A](a: A): Task[A] = Task.cancelable0[A] { (_, cb) => diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskCancellationSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskCancellationSuite.scala index 5582f5098..c7b2196aa 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskCancellationSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskCancellationSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +16,7 @@ */ package monix.eval +import scala.annotation.nowarn import java.util.concurrent.CancellationException import cats.laws._ @@ -25,8 +26,9 @@ import monix.execution.exceptions.DummyException import monix.execution.internal.Platform import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object TaskCancellationSuite extends BaseTestSuite { test("cancellation works for async actions") { implicit ec => implicit val opts = Task.defaultOptions.disableAutoCancelableRunLoops diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskClockTimerAndContextShiftSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskClockTimerAndContextShiftSuite.scala index 90a49dc10..a69119cc8 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskClockTimerAndContextShiftSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskClockTimerAndContextShiftSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,12 +19,12 @@ package monix.eval import java.util.concurrent.TimeUnit -import cats.effect.{Clock, ContextShift, Timer} +import cats.effect.{ Clock, ContextShift, Timer } import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object TaskClockTimerAndContextShiftSuite extends BaseTestSuite { test("Task.clock is implicit") { _ => @@ -69,7 +69,7 @@ object TaskClockTimerAndContextShiftSuite extends BaseTestSuite { assertEquals(f.value, Some(Success(1))) } - test("Task.timer is implicit") { implicit s => + test("Task.timer is implicit") { _ => assertEquals(Task.timer, implicitly[Timer[Task]]) assertEquals(Task.timer.clock, implicitly[Clock[Task]]) } @@ -104,7 +104,7 @@ object TaskClockTimerAndContextShiftSuite extends BaseTestSuite { assertEquals(f.value, Some(Success(1))) } - test("Task.contextShift is implicit") { implicit s => + test("Task.contextShift is implicit") { _ => assertEquals(Task.contextShift, implicitly[ContextShift[Task]]) } @@ -160,9 +160,7 @@ object TaskClockTimerAndContextShiftSuite extends BaseTestSuite { val s2 = TestScheduler() var wasScheduled = false - val runnable = new Runnable { - override def run(): Unit = wasScheduled = true - } + val runnable: Runnable = () => wasScheduled = true val f = Task.contextShift.evalOn(s2)(Task.deferAction(scheduler => Task(scheduler.execute(runnable)))).runToFuture @@ -225,14 +223,15 @@ object TaskClockTimerAndContextShiftSuite extends BaseTestSuite { test("Task.contextShift(s).evalOn(s2) injects s2 to Task.deferAction") { implicit s => val s2 = TestScheduler() - var wasScheduled = false - val runnable = new Runnable { - override def run(): Unit = wasScheduled = true - } + val runnable: Runnable = () => wasScheduled = true val f = - Task.contextShift(s).evalOn(s2)(Task.deferAction(scheduler => Task(scheduler.execute(runnable)))).runToFuture + Task.contextShift(s).evalOn(s2)( + Task.deferAction { scheduler => + Task(scheduler.execute(runnable)) + } + ).runToFuture assertEquals(f.value, None) s.tick() diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskCoevalDoOnFinishSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskCoevalDoOnFinishSuite.scala index 2a17ff069..d9722d3a5 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskCoevalDoOnFinishSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskCoevalDoOnFinishSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.eval import monix.execution.exceptions.DummyException import scala.concurrent.Promise -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object TaskCoevalDoOnFinishSuite extends BaseTestSuite { test("Task.doOnFinish should work for successful values") { implicit s => @@ -44,7 +44,7 @@ object TaskCoevalDoOnFinishSuite extends BaseTestSuite { assertEquals(p.future.value, Some(Success(Some(ex)))) } - test("Coeval.doOnFinish should work for successful values") { implicit s => + test("Coeval.doOnFinish should work for successful values") { _ => val p = Promise[Option[Throwable]]() val coeval = Coeval(10).doOnFinish(s => Coeval { p.success(s); () }) @@ -54,7 +54,7 @@ object TaskCoevalDoOnFinishSuite extends BaseTestSuite { assertEquals(p.future.value, Some(Success(None))) } - test("Coeval.doOnFinish should work for failures values") { implicit s => + test("Coeval.doOnFinish should work for failures values") { _ => val ex = DummyException("dummy") val p = Promise[Option[Throwable]]() diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskCoevalForeachSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskCoevalForeachSuite.scala index d8aaa47bf..022c6dba8 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskCoevalForeachSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskCoevalForeachSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,11 +16,13 @@ */ package monix.eval +import scala.annotation.nowarn import minitest.TestSuite import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler +@nowarn object TaskCoevalForeachSuite extends TestSuite[TestScheduler] { def setup(): TestScheduler = TestScheduler() def tearDown(env: TestScheduler): Unit = { diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskConnectionCompositeSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskConnectionCompositeSuite.scala index 8fdc806e3..c97937f7b 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskConnectionCompositeSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskConnectionCompositeSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskConnectionRefSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskConnectionRefSuite.scala index 62e916ec6..5f4bc8eaa 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskConnectionRefSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskConnectionRefSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +16,7 @@ */ package monix.eval +import scala.annotation.nowarn import monix.catnap.CancelableF import monix.catnap.cancelables.BooleanCancelableF @@ -23,6 +24,7 @@ import monix.execution.cancelables.BooleanCancelable import monix.eval.internal.TaskConnectionRef import monix.execution.ExecutionModel.SynchronousExecution +@nowarn object TaskConnectionRefSuite extends BaseTestSuite { test("assign and cancel a Cancelable") { implicit s => var effect = 0 diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskConnectionSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskConnectionSuite.scala index 766af03b9..c4b73cd75 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskConnectionSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskConnectionSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,20 +16,22 @@ */ package monix.eval +import scala.annotation.nowarn import monix.eval.internal.TaskConnection import monix.execution.Cancelable import monix.execution.cancelables.BooleanCancelable -import monix.execution.exceptions.{CompositeException, DummyException} +import monix.execution.exceptions.{ CompositeException, DummyException } import monix.execution.internal.Platform +@nowarn object TaskConnectionSuite extends BaseTestSuite { test("initial push") { implicit s => var effect = 0 val initial = Task { effect += 1 } val c = TaskConnection() - c push initial + c.push(initial) assert(!c.isCanceled, "!c.isCanceled") c.cancel.runAsyncAndForget @@ -47,7 +49,7 @@ object TaskConnectionSuite extends BaseTestSuite { c.cancel.runAsyncAndForget; s.tick() assert(c.isCanceled, "c.isCanceled") - c push initial + c.push(initial) s.tick() assertEquals(effect, 1) } @@ -62,7 +64,7 @@ object TaskConnectionSuite extends BaseTestSuite { c.cancel.runAsyncAndForget; s.tick() assert(c.isCanceled, "c.isCanceled") - c push initial + c.push(initial) s.tick() assertEquals(effect, 1) } @@ -74,7 +76,7 @@ object TaskConnectionSuite extends BaseTestSuite { c.cancel.runAsyncAndForget; s.tick() assert(c.isCanceled, "c.isCanceled") - c push initial + c.push(initial) s.tick() assert(initial.isCanceled, "initial.isCanceled") } @@ -186,7 +188,7 @@ object TaskConnectionSuite extends BaseTestSuite { assert(bc.isCanceled, "bc.isCanceled") } - test("pop when self is empty") { implicit s => + test("pop when self is empty") { _ => val sc = TaskConnection() assertEquals(sc.pop(), Task.unit) } @@ -207,7 +209,7 @@ object TaskConnectionSuite extends BaseTestSuite { val tasks = (0 until count).map(_ => Task { effect += 1 }) val sc = TaskConnection() - sc.pushConnections(connections1: _*) + sc.pushConnections(connections1*) for (bc <- cancelables) sc.push(bc) for (tk <- tasks) sc.push(tk) for (cn <- connections2) sc.push(cn) @@ -241,7 +243,7 @@ object TaskConnectionSuite extends BaseTestSuite { for (r <- connections2) assert(!r.isCanceled, "r.isCanceled") assertEquals(effect, 0) - sc.pushConnections(connections1: _*) + sc.pushConnections(connections1*) for (bc <- cancelables) sc.push(bc) for (tk <- tasks) sc.push(tk) for (cn <- connections2) sc.push(cn) @@ -289,7 +291,7 @@ object TaskConnectionSuite extends BaseTestSuite { assert(c1.isCanceled, "c1.isCanceled") } - test("uncancelable ref is shared") { implicit s => + test("uncancelable ref is shared") { _ => val t = TaskConnection.uncancelable assertEquals(t, TaskConnection.uncancelable) } diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskConversionsKSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskConversionsKSuite.scala index a4e5bd489..6a3b89d12 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskConversionsKSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskConversionsKSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,12 +16,14 @@ */ package monix.eval +import scala.annotation.nowarn -import cats.effect.{ContextShift, IO} +import cats.effect.{ ContextShift, IO } import monix.catnap.SchedulerEffect import scala.util.Success +@nowarn object TaskConversionsKSuite extends BaseTestSuite { test("Task.liftTo[IO]") { implicit s => var effect = 0 diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskConversionsSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskConversionsSuite.scala index ea57f335a..6bef8111d 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskConversionsSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskConversionsSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,21 +16,23 @@ */ package monix.eval +import scala.annotation.nowarn import cats.effect._ import cats.laws._ import cats.laws.discipline._ import cats.syntax.all._ -import cats.{effect, Eval} +import cats.{ effect, Eval } import monix.catnap.SchedulerEffect import monix.execution.CancelablePromise import monix.execution.exceptions.DummyException import monix.execution.internal.Platform -import org.reactivestreams.{Publisher, Subscriber, Subscription} +import org.reactivestreams.{ Publisher, Subscriber, Subscription } import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object TaskConversionsSuite extends BaseTestSuite { test("Task.from(task.to[IO]) == task") { implicit s => check1 { (task: Task[Int]) => @@ -384,7 +386,7 @@ object TaskConversionsSuite extends BaseTestSuite { val dummy = DummyException("dummy") val pub = new Publisher[Int] { - def subscribe(s: Subscriber[_ >: Int]): Unit = { + def subscribe(s: Subscriber[? >: Int]): Unit = { s.onSubscribe(new Subscription { def request(n: Long): Unit = throw dummy def cancel(): Unit = throw dummy @@ -397,7 +399,7 @@ object TaskConversionsSuite extends BaseTestSuite { test("Task.fromReactivePublisher yields expected input") { implicit s => val pub = new Publisher[Int] { - def subscribe(s: Subscriber[_ >: Int]): Unit = { + def subscribe(s: Subscriber[? >: Int]): Unit = { s.onSubscribe(new Subscription { var isActive = true def request(n: Long): Unit = { @@ -447,7 +449,8 @@ object TaskConversionsSuite extends BaseTestSuite { override def liftIO[A](ioa: IO[A]): CIO[A] = CIO(ioa) override def bracketCase[A, B](acquire: CIO[A])(use: A => CIO[B])( - release: (A, ExitCase[Throwable]) => CIO[Unit]): CIO[B] = + release: (A, ExitCase[Throwable]) => CIO[Unit] + ): CIO[B] = CIO(acquire.io.bracketCase(a => use(a).io)((a, e) => release(a, e).io)) } diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskCreateSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskCreateSuite.scala index bc2a5188d..ac99556f3 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskCreateSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskCreateSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,14 +16,16 @@ */ package monix.eval +import scala.annotation.nowarn import cats.effect.IO import monix.execution.Cancelable import monix.execution.exceptions.DummyException -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } import scala.concurrent.duration._ +@nowarn object TaskCreateSuite extends BaseTestSuite { test("can use Unit as return type") { implicit sc => val task = Task.create[Int]((_, cb) => cb.onSuccess(1)) diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskDeferActionSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskDeferActionSuite.scala index 32d9a0595..69bb8df83 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskDeferActionSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskDeferActionSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.eval import monix.execution.exceptions.DummyException import concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object TaskDeferActionSuite extends BaseTestSuite { test("Task.deferAction works") { implicit s => diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskDelaySuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskDelaySuite.scala index ff6607881..0b701580f 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskDelaySuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskDelaySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import monix.execution.exceptions.DummyException import monix.execution.internal.Platform import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object TaskDelaySuite extends BaseTestSuite { test("Task#delayExecution should work") { implicit s => diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskDoOnCancelSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskDoOnCancelSuite.scala index a5e586de9..7d535c831 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskDoOnCancelSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskDoOnCancelSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.eval import monix.execution.exceptions.DummyException import concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object TaskDoOnCancelSuite extends BaseTestSuite { test("doOnCancel should normally mirror the source") { implicit s => diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskEffectInstanceSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskEffectInstanceSuite.scala index 4529832b7..d5b38ee40 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskEffectInstanceSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskEffectInstanceSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.eval -import cats.effect.{Effect, IO} +import cats.effect.{ Effect, IO } import monix.execution.schedulers.TracingScheduler import scala.concurrent.duration._ diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskErrorSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskErrorSuite.scala index 32ce7acbe..95fb5c6a4 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskErrorSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskErrorSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,13 +16,15 @@ */ package monix.eval +import scala.annotation.nowarn import monix.execution.exceptions.DummyException import monix.execution.internal.Platform import scala.concurrent.TimeoutException import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object TaskErrorSuite extends BaseTestSuite { test("Task.attempt should expose error") { implicit s => val dummy = DummyException("dummy") @@ -282,7 +284,7 @@ object TaskErrorSuite extends BaseTestSuite { test("Task.onErrorRestartIf should mirror the source onSuccess") { implicit s => var tries = 0 - val task = Task.eval { tries += 1; 1 }.onErrorRestartIf(ex => tries < 10) + val task = Task.eval { tries += 1; 1 }.onErrorRestartIf(_ => tries < 10) val f = task.runToFuture assertEquals(f.value, Some(Success(1))) diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskEvalAlwaysSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskEvalAlwaysSuite.scala index bb77f6366..68f9ded16 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskEvalAlwaysSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskEvalAlwaysSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ import cats.laws.discipline._ import monix.execution.exceptions.DummyException -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object TaskEvalAlwaysSuite extends BaseTestSuite { test("Task.eval should work synchronously") { implicit s => @@ -75,7 +75,7 @@ object TaskEvalAlwaysSuite extends BaseTestSuite { test("Task.eval.flatMap should be tail recursive") { implicit s => def loop(n: Int, idx: Int): Task[Int] = - Task.eval(idx).flatMap { a => + Task.eval(idx).flatMap { _ => if (idx < n) loop(n, idx + 1).map(_ + 1) else Task.eval(idx) diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskEvalAsyncSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskEvalAsyncSuite.scala index cdcabae5e..ae573d953 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskEvalAsyncSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskEvalAsyncSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.eval import cats.laws._ import cats.laws.discipline._ import monix.execution.exceptions.DummyException -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object TaskEvalAsyncSuite extends BaseTestSuite { test("Task.evalAsync should work, on different thread") { implicit s => diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskEvalOnceSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskEvalOnceSuite.scala index 5087413e2..65e9d2c4f 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskEvalOnceSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskEvalOnceSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.eval import cats.laws._ import cats.laws.discipline._ import monix.execution.exceptions.DummyException -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object TaskEvalOnceSuite extends BaseTestSuite { test("Task.evalOnce should work synchronously") { implicit s => diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskExecuteAsyncSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskExecuteAsyncSuite.scala index e098e0b0f..7e9ae2aaa 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskExecuteAsyncSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskExecuteAsyncSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskExecuteOnSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskExecuteOnSuite.scala index 49fcfc72b..6efa35c0c 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskExecuteOnSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskExecuteOnSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskExecuteWithModelSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskExecuteWithModelSuite.scala index db8bc668a..0591f688c 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskExecuteWithModelSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskExecuteWithModelSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.eval import monix.execution.ExecutionModel -import monix.execution.ExecutionModel.{AlwaysAsyncExecution, SynchronousExecution} +import monix.execution.ExecutionModel.{ AlwaysAsyncExecution, SynchronousExecution } import scala.util.Success object TaskExecuteWithModelSuite extends BaseTestSuite { diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskExecuteWithOptionsSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskExecuteWithOptionsSuite.scala index 4e5cad600..c8d8956b8 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskExecuteWithOptionsSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskExecuteWithOptionsSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,9 +16,11 @@ */ package monix.eval +import scala.annotation.nowarn import scala.util.Success +@nowarn object TaskExecuteWithOptionsSuite extends BaseTestSuite { test("executeWithOptions works") { implicit s => val task = Task diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskExecutionModelSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskExecutionModelSuite.scala index f0da538bd..8f7d169e7 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskExecutionModelSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskExecutionModelSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskFlatMapSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskFlatMapSuite.scala index 111c79817..0ee6a7055 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskFlatMapSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskFlatMapSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,15 +16,17 @@ */ package monix.eval +import scala.annotation.nowarn import cats.laws._ import cats.laws.discipline._ import monix.execution.Callback -import monix.execution.atomic.{Atomic, AtomicInt} +import monix.execution.atomic.{ Atomic, AtomicInt } import monix.execution.exceptions.DummyException import monix.execution.internal.Platform -import scala.util.{Failure, Random, Success, Try} +import scala.util.{ Failure, Random, Success, Try } +@nowarn object TaskFlatMapSuite extends BaseTestSuite { test("runAsync flatMap loop is not cancelable if autoCancelableRunLoops=false") { implicit s => implicit val opts = Task.defaultOptions.disableAutoCancelableRunLoops diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskFromEitherSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskFromEitherSuite.scala index 6cb57c89d..33ef8cc22 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskFromEitherSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskFromEitherSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,17 +16,19 @@ */ package monix.eval +import scala.annotation.nowarn -import monix.eval.Task.{Error, Now} +import monix.eval.Task.{ Error, Now } import monix.execution.exceptions.DummyException import monix.execution.internal.Platform -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object TaskFromEitherSuite extends BaseTestSuite { - test("Task.fromEither (`E <: Throwable` version) should returns a Now with a Right") { implicit s => + test("Task.fromEither (`E <: Throwable` version) should returns a Now with a Right") { _ => val t = Task.fromEither(Right(10)) - assert(t.isInstanceOf[Now[_]]) + assert(t.isInstanceOf[Now[?]]) } test("Task.fromEither (`E <: Throwable` version) should succeed with a Right") { implicit s => @@ -35,10 +37,10 @@ object TaskFromEitherSuite extends BaseTestSuite { assertEquals(f.value, Some(Success(10))) } - test("Task.fromEither (`E <: Throwable` version) should returns an Error with a Left") { implicit s => + test("Task.fromEither (`E <: Throwable` version) should returns an Error with a Left") { _ => val dummy = DummyException("dummy") val t = Task.fromEither(Left(dummy)) - assert(t.isInstanceOf[Error[_]]) + assert(t.isInstanceOf[Error[?]]) } test("Task.fromEither (`E <: Throwable` version) should fail with a Left") { implicit s => @@ -62,9 +64,9 @@ object TaskFromEitherSuite extends BaseTestSuite { assertEquals(result.value, Some(Failure(DummyException("dummy")))) } - test("Task.fromEither (free `E` version) should returns a Now with a Right") { implicit s => + test("Task.fromEither (free `E` version) should returns a Now with a Right") { _ => val t = Task.fromEither(DummyException(_))(Right(10)) - assert(t.isInstanceOf[Now[_]]) + assert(t.isInstanceOf[Now[?]]) } test("Task.fromEither (free `E` version) should succeed with a Right") { implicit s => @@ -73,9 +75,9 @@ object TaskFromEitherSuite extends BaseTestSuite { assertEquals(f.value, Some(Success(10))) } - test("Task.fromEither (free `E` version) should returns an Error with a Left") { implicit s => + test("Task.fromEither (free `E` version) should returns an Error with a Left") { _ => val t = Task.fromEither(DummyException(_))(Left("dummy")) - assert(t.isInstanceOf[Error[_]]) + assert(t.isInstanceOf[Error[?]]) } test("Task.fromEither (free `E` version) should fail with a Left") { implicit s => diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskFromFutureSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskFromFutureSuite.scala index 6e226d9e6..60fbbc558 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskFromFutureSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskFromFutureSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,14 +16,16 @@ */ package monix.eval +import scala.annotation.nowarn -import monix.execution.{Cancelable, CancelableFuture} +import monix.execution.{ Cancelable, CancelableFuture } import monix.execution.exceptions.DummyException import monix.execution.internal.Platform -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object TaskFromFutureSuite extends BaseTestSuite { test("Task.fromFuture should be faster for completed futures, success") { implicit s => val t = Task.fromFuture(Future.successful(10)) diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskGuaranteeSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskGuaranteeSuite.scala index 181c52ba8..06a78164b 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskGuaranteeSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskGuaranteeSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,14 +16,16 @@ */ package monix.eval +import scala.annotation.nowarn import cats.implicits._ import monix.execution.atomic.Atomic -import monix.execution.exceptions.{CompositeException, DummyException} +import monix.execution.exceptions.{ CompositeException, DummyException } import monix.execution.internal.Platform -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } import scala.concurrent.duration._ +@nowarn object TaskGuaranteeSuite extends BaseTestSuite { test("finalizer is evaluated on success") { implicit sc => @@ -117,7 +119,8 @@ object TaskGuaranteeSuite extends BaseTestSuite { Task.Async[Unit]((ctx, cb) => { println(ctx.connection) cb.onSuccess(()) - })) + }) + ) .flatMap(_ => Task.sleep(10.seconds)) val f = task.runToFuture diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskLeftSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskLeftSuite.scala index b40bd3a4b..b1e9438db 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskLeftSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskLeftSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskLiftSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskLiftSuite.scala index b1b85d2d0..ef4e5fcc0 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskLiftSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskLiftSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,14 +16,17 @@ */ package monix.eval -import cats.effect.{ContextShift, IO} +import scala.annotation.nowarn + +import cats.effect.{ ContextShift, IO } import monix.catnap.SchedulerEffect import monix.execution.exceptions.DummyException -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object TaskLiftSuite extends BaseTestSuite { - import TaskConversionsSuite.{CIO, CustomConcurrentEffect, CustomEffect} + import TaskConversionsSuite.{ CIO, CustomConcurrentEffect, CustomEffect } test("task.to[Task]") { _ => val task = Task(1) diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskLikeConversionsSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskLikeConversionsSuite.scala index 1d67dcc00..937f53a2e 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskLikeConversionsSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskLikeConversionsSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,18 +16,20 @@ */ package monix.eval +import scala.annotation.nowarn import cats.Eval -import cats.effect.{ContextShift, IO, SyncIO} +import cats.effect.{ ContextShift, IO, SyncIO } import monix.catnap.SchedulerEffect import monix.execution.CancelablePromise import monix.execution.exceptions.DummyException import scala.concurrent.Promise -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } +@nowarn object TaskLikeConversionsSuite extends BaseTestSuite { - import TaskConversionsSuite.{CIO, CustomConcurrentEffect, CustomEffect} + import TaskConversionsSuite.{ CIO, CustomConcurrentEffect, CustomEffect } test("Task.from(future)") { implicit s => val p = Promise[Int]() diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskLocalSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskLocalSuite.scala index e30c6645e..832f8763d 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskLocalSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskLocalSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,17 +16,19 @@ */ package monix.eval +import scala.annotation.nowarn import scala.concurrent.Future import scala.concurrent.duration._ import minitest.SimpleTestSuite -import monix.execution.{BufferCapacity, Scheduler} +import monix.execution.{ BufferCapacity, Scheduler } import monix.execution.exceptions.DummyException import monix.execution.misc.Local import cats.implicits._ -import monix.catnap.{ConcurrentChannel, ConsumerF} +import monix.catnap.{ ConcurrentChannel, ConsumerF } +@nowarn object TaskLocalSuite extends SimpleTestSuite { implicit val ec: Scheduler = monix.execution.Scheduler.Implicits.global implicit val opts: Task.Options = Task.defaultOptions.enableLocalContextPropagation @@ -176,9 +178,7 @@ object TaskLocalSuite extends SimpleTestSuite { testAsync("TaskLocals get restored in Task.create on error") { val dummy = DummyException("dummy") val task = Task.create[Int] { (_, cb) => - ec.execute(new Runnable { - def run() = cb.onError(dummy) - }) + ec.execute(() => cb.onError(dummy)) } val t = for { @@ -277,12 +277,11 @@ object TaskLocalSuite extends SimpleTestSuite { l: TaskLocal[String], ch: ConcurrentChannel[Task, Unit, Int] ) { - private[this] def produceLoop(n: Int): Task[Unit] = - if (n == 0) Task.unit - else - ch.push(n) >> l.read.flatMap { s => - Task(assertEquals(s, "producer")) - } >> produceLoop(n - 1) + private def produceLoop(n: Int): Task[Unit] = if (n == 0) Task.unit + else + ch.push(n) >> l.read.flatMap { s => + Task(assertEquals(s, "producer")) + } >> produceLoop(n - 1) def produce: Task[Unit] = for { @@ -308,7 +307,8 @@ object TaskLocalSuite extends SimpleTestSuite { ch <- ConcurrentChannel[Task].withConfig[Unit, Int]( ConsumerF.Config( capacity = BufferCapacity.Bounded(bufferSize).some - )) + ) + ) test = new Test(tl, ch) _ <- TaskLocal.isolate(test.produce) &> TaskLocal.isolate(test.consume) } yield () diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskMapBothSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskMapBothSuite.scala index 4978e1978..d4af15231 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskMapBothSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskMapBothSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.eval import cats.laws._ import cats.laws.discipline._ import monix.execution.internal.Platform -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object TaskMapBothSuite extends BaseTestSuite { test("if both tasks are synchronous, then mapBoth forks") { implicit s => diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskMemoizeOnSuccessSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskMemoizeOnSuccessSuite.scala index 4f1ade877..06ce5bb1b 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskMemoizeOnSuccessSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskMemoizeOnSuccessSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,15 +16,17 @@ */ package monix.eval +import scala.annotation.nowarn import monix.execution.Callback import monix.execution.atomic.AtomicInt import monix.execution.exceptions.DummyException import monix.execution.internal.Platform import scala.concurrent.Promise -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } import concurrent.duration._ +@nowarn object TaskMemoizeOnSuccessSuite extends BaseTestSuite { test("Task.memoizeOnSuccess should work asynchronously for first subscriber") { implicit s => var effect = 0 @@ -56,7 +58,7 @@ object TaskMemoizeOnSuccessSuite extends BaseTestSuite { test("Task.memoizeOnSuccess should be stack safe") { implicit s => val count = if (Platform.isJVM) 50000 else 5000 var task = Task.evalAsync(1) - for (i <- 0 until count) task = task.memoizeOnSuccess + for (_ <- 0 until count) task = task.memoizeOnSuccess val f = task.runToFuture assertEquals(f.value, None) @@ -68,7 +70,7 @@ object TaskMemoizeOnSuccessSuite extends BaseTestSuite { val count = if (Platform.isJVM) 50000 else 5000 var task = Task.evalAsync(1) - for (i <- 0 until count) { + for (_ <- 0 until count) { task = task.memoizeOnSuccess.flatMap(x => Task.now(x)) } @@ -81,7 +83,7 @@ object TaskMemoizeOnSuccessSuite extends BaseTestSuite { test("Task.flatMap.memoizeOnSuccess should be stack safe, test 2") { implicit s => val count = if (Platform.isJVM) 50000 else 5000 var task = Task.evalAsync(1) - for (i <- 0 until count) { + for (_ <- 0 until count) { task = task.memoizeOnSuccess.flatMap(x => Task.evalAsync(x)) } @@ -171,7 +173,7 @@ object TaskMemoizeOnSuccessSuite extends BaseTestSuite { test("Task.eval.memoizeOnSuccess should be stack safe") { implicit s => val count = if (Platform.isJVM) 50000 else 5000 var task = Task.eval(1) - for (i <- 0 until count) + for (_ <- 0 until count) task = task.memoizeOnSuccess val f = task.runToFuture; s.tick() @@ -181,7 +183,7 @@ object TaskMemoizeOnSuccessSuite extends BaseTestSuite { test("Task.eval.flatMap.memoizeOnSuccess should be stack safe") { implicit s => val count = if (Platform.isJVM) 50000 else 5000 var task = Task.eval(1) - for (i <- 0 until count) { + for (_ <- 0 until count) { task = task.memoizeOnSuccess.flatMap(x => Task.eval(x)) } @@ -242,7 +244,7 @@ object TaskMemoizeOnSuccessSuite extends BaseTestSuite { test("Task.evalOnce.memoizeOnSuccess should be stack safe") { implicit s => val count = if (Platform.isJVM) 50000 else 5000 var task = Task.eval(1) - for (i <- 0 until count) { + for (_ <- 0 until count) { task = task.memoizeOnSuccess } @@ -253,7 +255,7 @@ object TaskMemoizeOnSuccessSuite extends BaseTestSuite { test("Task.evalOnce.flatMap.memoizeOnSuccess should be stack safe") { implicit s => val count = if (Platform.isJVM) 50000 else 5000 var task = Task.eval(1) - for (i <- 0 until count) { + for (_ <- 0 until count) { task = task.memoizeOnSuccess.flatMap(x => Task.evalOnce(x)) } @@ -297,7 +299,7 @@ object TaskMemoizeOnSuccessSuite extends BaseTestSuite { test("Task.now.memoizeOnSuccess should be stack safe") { implicit s => val count = if (Platform.isJVM) 50000 else 5000 var task = Task.now(1) - for (i <- 0 until count) { + for (_ <- 0 until count) { task = task.memoizeOnSuccess } @@ -308,7 +310,7 @@ object TaskMemoizeOnSuccessSuite extends BaseTestSuite { test("Task.now.flatMap.memoizeOnSuccess should be stack safe") { implicit s => val count = if (Platform.isJVM) 50000 else 5000 var task = Task.now(1) - for (i <- 0 until count) { + for (_ <- 0 until count) { task = task.memoizeOnSuccess.flatMap(x => Task.now(x)) } @@ -321,7 +323,7 @@ object TaskMemoizeOnSuccessSuite extends BaseTestSuite { test("Task.suspend.memoizeOnSuccess should be stack safe") { implicit s => val count = if (Platform.isJVM) 50000 else 5000 var task = Task.defer(Task.now(1)) - for (i <- 0 until count) { + for (_ <- 0 until count) { task = task.memoizeOnSuccess.map(x => x) } @@ -616,32 +618,32 @@ object TaskMemoizeOnSuccessSuite extends BaseTestSuite { assertEquals(effect, 2) } - test("Task.evalOnce eq Task.evalOnce.memoizeOnSuccess") { implicit s => + test("Task.evalOnce eq Task.evalOnce.memoizeOnSuccess") { _ => val task = Task.evalOnce(1) assertEquals(task, task.memoizeOnSuccess) } - test("Task.eval.memoizeOnSuccess eq Task.eval.memoizeOnSuccess.memoizeOnSuccess") { implicit s => + test("Task.eval.memoizeOnSuccess eq Task.eval.memoizeOnSuccess.memoizeOnSuccess") { _ => val task = Task.eval(1).memoizeOnSuccess assertEquals(task, task.memoizeOnSuccess) } - test("Task.eval.memoize eq Task.eval.memoize.memoizeOnSuccess") { implicit s => + test("Task.eval.memoize eq Task.eval.memoize.memoizeOnSuccess") { _ => val task = Task.eval(1).memoize assertEquals(task, task.memoizeOnSuccess) } - test("Task.eval.map.memoize eq Task.eval.map.memoize.memoizeOnSuccess") { implicit s => + test("Task.eval.map.memoize eq Task.eval.map.memoize.memoizeOnSuccess") { _ => val task = Task.eval(1).map(_ + 1).memoize assertEquals(task, task.memoizeOnSuccess) } - test("Task.now.memoizeOnSuccess eq Task.now") { implicit s => + test("Task.now.memoizeOnSuccess eq Task.now") { _ => val task = Task.now(1) assertEquals(task, task.memoizeOnSuccess) } - test("Task.raiseError.memoizeOnSuccess eq Task.raiseError") { implicit s => + test("Task.raiseError.memoizeOnSuccess eq Task.raiseError") { _ => val task = Task.raiseError(DummyException("dummy")) assertEquals(task, task.memoizeOnSuccess) } diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskMemoizeSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskMemoizeSuite.scala index b09e544ab..bcbc74d61 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskMemoizeSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskMemoizeSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +16,7 @@ */ package monix.eval +import scala.annotation.nowarn import monix.execution.Callback import monix.execution.atomic.AtomicInt @@ -23,9 +24,10 @@ import monix.execution.exceptions.DummyException import monix.execution.internal.Platform import scala.concurrent.Promise -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } import concurrent.duration._ +@nowarn object TaskMemoizeSuite extends BaseTestSuite { test("Task.memoize should work asynchronously for first subscriber") { implicit s => var effect = 0 @@ -620,32 +622,32 @@ object TaskMemoizeSuite extends BaseTestSuite { assertEquals(effect, 1) } - test("Task.evalOnce eq Task.evalOnce.memoize") { implicit s => + test("Task.evalOnce eq Task.evalOnce.memoize") { _ => val task = Task.evalOnce(1) assertEquals(task, task.memoize) } - test("Task.eval.memoize eq Task.eval.memoize.memoize") { implicit s => + test("Task.eval.memoize eq Task.eval.memoize.memoize") { _ => val task = Task.eval(1).memoize assertEquals(task, task.memoize) } - test("Task.eval.map.memoize eq Task.eval.map.memoize.memoize") { implicit s => + test("Task.eval.map.memoize eq Task.eval.map.memoize.memoize") { _ => val task = Task.eval(1).map(_ + 1).memoize assertEquals(task, task.memoize) } - test("Task.now.memoize eq Task.now") { implicit s => + test("Task.now.memoize eq Task.now") { _ => val task = Task.now(1) assertEquals(task, task.memoize) } - test("Task.raiseError.memoize eq Task.raiseError") { implicit s => + test("Task.raiseError.memoize eq Task.raiseError") { _ => val task = Task.raiseError(DummyException("dummy")) assertEquals(task, task.memoize) } - test("Task.eval.memoizeOnSuccess.memoize !== Task.eval.memoizeOnSuccess") { implicit s => + test("Task.eval.memoizeOnSuccess.memoize !== Task.eval.memoizeOnSuccess") { _ => val task = Task.eval(1).memoizeOnSuccess assert(task != task.memoize, "task != task.memoize") } diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskMiscSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskMiscSuite.scala index a942468d2..7d9b4b079 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskMiscSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskMiscSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,14 +16,16 @@ */ package monix.eval +import scala.annotation.nowarn import monix.execution.Callback import monix.execution.exceptions.DummyException -import org.reactivestreams.{Subscriber, Subscription} +import org.reactivestreams.{ Subscriber, Subscription } import scala.concurrent.Promise -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object TaskMiscSuite extends BaseTestSuite { test("Task.attempt should succeed") { implicit s => val result = Task.now(1).attempt.runToFuture @@ -158,7 +160,7 @@ object TaskMiscSuite extends BaseTestSuite { assert(s.state.tasks.isEmpty, "should not have tasks left to execute") } - test("Task.pure is an alias of now") { implicit s => + test("Task.pure is an alias of now") { _ => assertEquals(Task.pure(1), Task.now(1)) } diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskNowSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskNowSuite.scala index 354b8078b..a06646828 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskNowSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskNowSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,14 +16,16 @@ */ package monix.eval +import scala.annotation.nowarn import cats.laws._ import cats.laws.discipline._ import monix.execution.Callback import monix.execution.ExecutionModel.AlwaysAsyncExecution import monix.execution.exceptions.DummyException -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } +@nowarn object TaskNowSuite extends BaseTestSuite { test("Task.now should work synchronously") { implicit s => var wasTriggered = false @@ -168,7 +170,7 @@ object TaskNowSuite extends BaseTestSuite { test("Task.now.flatMap should be tail recursive") { implicit s => def loop(n: Int, idx: Int): Task[Int] = - Task.now(idx).flatMap { a => + Task.now(idx).flatMap { _ => if (idx < n) loop(n, idx + 1).map(_ + 1) else Task.now(idx) diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskOptionSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskOptionSuite.scala index ca013d472..bc0b4e206 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskOptionSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskOptionSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskOptionsSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskOptionsSuite.scala index 7a554d942..78267b123 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskOptionsSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskOptionsSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +16,7 @@ */ package monix.eval +import scala.annotation.nowarn import minitest.SimpleTestSuite import monix.eval.Task.Options @@ -23,16 +24,17 @@ import monix.execution.Callback import monix.execution.Scheduler.Implicits.global import scala.concurrent.Promise +@nowarn object TaskOptionsSuite extends SimpleTestSuite { implicit val opts: Options = Task.defaultOptions.enableLocalContextPropagation - def extractOptions[A](fa: Task[A]): Task[Options] = + def extractOptions: Task[Options] = Task.Async { (ctx, cb) => cb.onSuccess(ctx.options) } testAsync("change options with future") { - val task = extractOptions(Task.now(1)).map { r => + val task = extractOptions.map { r => assertEquals(r, opts) } task.runToFutureOpt @@ -40,7 +42,7 @@ object TaskOptionsSuite extends SimpleTestSuite { testAsync("change options with callback") { val p = Promise[Options]() - extractOptions(Task.now(1)).runAsyncOpt(Callback.fromPromise(p)) + extractOptions.runAsyncOpt(Callback.fromPromise(p)) for (r <- p.future) yield { assertEquals(r, opts) diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskOrCoevalTransformWithSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskOrCoevalTransformWithSuite.scala index 952586886..ca441f96d 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskOrCoevalTransformWithSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskOrCoevalTransformWithSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,13 +16,15 @@ */ package monix.eval +import scala.annotation.nowarn import monix.execution.Callback import monix.execution.exceptions.DummyException import monix.execution.internal.Platform import scala.concurrent.Promise -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object TaskOrCoevalTransformWithSuite extends BaseTestSuite { test("Task.materialize flatMap loop") { implicit s => val count = if (Platform.isJVM) 10000 else 1000 diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskOverloadsSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskOverloadsSuite.scala index f764cb206..ea172aac2 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskOverloadsSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskOverloadsSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,13 +16,15 @@ */ package monix.eval +import scala.annotation.nowarn import monix.execution.Callback import monix.execution.ExecutionModel.AlwaysAsyncExecution import monix.execution.exceptions.DummyException import scala.concurrent.Promise -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object TaskOverloadsSuite extends BaseTestSuite { test("Now.runAsync(scheduler)") { implicit s => val task = Task.now(1) diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskParSequenceNSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskParSequenceNSuite.scala index aac31935c..ebb47d5af 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskParSequenceNSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskParSequenceNSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,14 +16,16 @@ */ package monix.eval +import scala.annotation.nowarn import monix.execution.atomic.AtomicInt import monix.execution.exceptions.DummyException import monix.execution.internal.Platform import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +@nowarn object TaskParSequenceNSuite extends BaseTestSuite { test("Task.parSequenceN should execute in parallel bounded by parallelism") { implicit s => @@ -121,7 +123,7 @@ object TaskParSequenceNSuite extends BaseTestSuite { test("Task.parSequenceN runAsync multiple times") { implicit s => var effect = 0 val task1 = Task.evalAsync { effect += 1; 3 }.memoize - val task2 = task1 map { x => + val task2 = task1.map { x => effect += 1; x + 1 } val task3 = Task.parSequenceN(2)(List(task2, task2, task2)) diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskParSequenceSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskParSequenceSuite.scala index 1ac764028..93f7cb036 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskParSequenceSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskParSequenceSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,14 +20,15 @@ package monix.eval import monix.execution.exceptions.DummyException import monix.execution.internal.Platform import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object TaskParSequenceSuite extends BaseTestSuite { test("Task.parSequence should execute in parallel for async tasks") { implicit s => val seq = Seq( Task.evalAsync(1).delayExecution(2.seconds), Task.evalAsync(2).delayExecution(1.second), - Task.evalAsync(3).delayExecution(3.seconds)) + Task.evalAsync(3).delayExecution(3.seconds) + ) val f = Task.parSequence(seq).runToFuture s.tick() @@ -59,7 +60,8 @@ object TaskParSequenceSuite extends BaseTestSuite { val seq = Seq( Task.evalAsync(1).delayExecution(2.seconds), Task.evalAsync(2).delayExecution(1.second), - Task.evalAsync(3).delayExecution(3.seconds)) + Task.evalAsync(3).delayExecution(3.seconds) + ) val f = Task.parSequence(seq).runToFuture s.tick() @@ -84,7 +86,7 @@ object TaskParSequenceSuite extends BaseTestSuite { test("Task.parSequence runAsync multiple times") { implicit s => var effect = 0 val task1 = Task.evalAsync { effect += 1; 3 }.memoize - val task2 = task1 map { x => + val task2 = task1.map { x => effect += 1; x + 1 } val task3 = Task.parSequence(List(task2, task2, task2)) diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskParSequenceUnorderedSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskParSequenceUnorderedSuite.scala index a7d066c64..af40bece1 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskParSequenceUnorderedSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskParSequenceUnorderedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +16,7 @@ */ package monix.eval +import scala.annotation.nowarn import monix.execution.Callback import monix.execution.exceptions.DummyException @@ -23,14 +24,16 @@ import monix.execution.internal.Platform import scala.collection.mutable.ListBuffer import scala.concurrent.duration._ -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } +@nowarn object TaskParSequenceUnorderedSuite extends BaseTestSuite { test("Task.parSequenceUnordered should execute in parallel") { implicit s => val seq = Seq( Task.evalAsync(1).delayExecution(2.seconds), Task.evalAsync(2).delayExecution(1.second), - Task.evalAsync(3).delayExecution(3.seconds)) + Task.evalAsync(3).delayExecution(3.seconds) + ) val f = Task.parSequenceUnordered(seq).runToFuture s.tick() @@ -62,7 +65,8 @@ object TaskParSequenceUnorderedSuite extends BaseTestSuite { val seq = Seq( Task.evalAsync(1).delayExecution(2.seconds), Task.evalAsync(2).delayExecution(1.second), - Task.evalAsync(3).delayExecution(3.seconds)) + Task.evalAsync(3).delayExecution(3.seconds) + ) val f = Task.parSequenceUnordered(seq).runToFuture s.tick() @@ -98,7 +102,7 @@ object TaskParSequenceUnorderedSuite extends BaseTestSuite { def fold[A, B](ta: Task[ListBuffer[A]], tb: Task[A]): Task[ListBuffer[A]] = Task.parSequenceUnordered(List(ta, tb)).map { case a :: b :: Nil => - val (accR, valueR) = if (a.isInstanceOf[ListBuffer[_]]) (a, b) else (b, a) + val (accR, valueR) = if (a.isInstanceOf[ListBuffer[?]]) (a, b) else (b, a) val acc = accR.asInstanceOf[ListBuffer[A]] val value = valueR.asInstanceOf[A] acc += value @@ -165,7 +169,7 @@ object TaskParSequenceUnorderedSuite extends BaseTestSuite { test("Task.parSequenceUnordered runAsync multiple times") { implicit s => var effect = 0 val task1 = Task.evalAsync { effect += 1; 3 }.memoize - val task2 = task1 map { x => + val task2 = task1.map { x => effect += 1; x + 1 } val task3 = Task.parSequenceUnordered(List(task2, task2, task2)) diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskParTraverseSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskParTraverseSuite.scala index 609d6ff91..94e0f1bb6 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskParTraverseSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskParTraverseSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ import monix.execution.internal.Platform import concurrent.duration._ import scala.annotation.nowarn -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object TaskParTraverseSuite extends BaseTestSuite { test("Task.parTraverse should execute in parallel for async tasks") { implicit s => @@ -93,7 +93,7 @@ object TaskParTraverseSuite extends BaseTestSuite { val task1 = Task.evalAsync { effect += 1; 3 }.memoize val task2 = Task.parTraverse(Seq(0, 0, 0)) { _ => - task1 map { x => + task1.map { x => effect += 1; x + 1 } } diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskParTraverseUnorderedSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskParTraverseUnorderedSuite.scala index ed2473213..1a9702f3c 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskParTraverseUnorderedSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskParTraverseUnorderedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +16,7 @@ */ package monix.eval +import scala.annotation.nowarn import monix.execution.Callback import monix.execution.exceptions.DummyException @@ -23,8 +24,9 @@ import monix.execution.internal.Platform import scala.collection.mutable.ListBuffer import scala.concurrent.duration._ -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } +@nowarn object TaskParTraverseUnorderedSuite extends BaseTestSuite { test("Task.parTraverseUnordered should execute in parallel") { implicit s => val seq = Seq((1, 2), (2, 1), (3, 3)) @@ -99,13 +101,13 @@ object TaskParTraverseUnorderedSuite extends BaseTestSuite { test("Task.parTraverseUnordered should be stack safe on success") { implicit s => def fold[A](ta: Task[ListBuffer[A]], next: A): Task[ListBuffer[A]] = - ta flatMap { acc => + ta.flatMap { acc => Task.parTraverseUnordered(Seq(acc, next)) { v => Task.eval(v) } - } map { + }.map { case a :: b :: Nil => - val (accR, valueR) = if (a.isInstanceOf[ListBuffer[_]]) (a, b) else (b, a) + val (accR, valueR) = if (a.isInstanceOf[ListBuffer[?]]) (a, b) else (b, a) val acc = accR.asInstanceOf[ListBuffer[A]] val value = valueR.asInstanceOf[A] acc += value @@ -167,7 +169,7 @@ object TaskParTraverseUnorderedSuite extends BaseTestSuite { effect += 1; 3 }.memoize - val task2 = task1 map { x => + val task2 = task1.map { x => effect += 1; x + 1 } diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskParZipSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskParZipSuite.scala index dcc5c69f0..60cb2155c 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskParZipSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskParZipSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,11 +16,13 @@ */ package monix.eval +import scala.annotation.nowarn import monix.execution.exceptions.DummyException import concurrent.duration._ -import scala.util.{Failure, Random, Success} +import scala.util.{ Failure, Random, Success } +@nowarn object TaskParZipSuite extends BaseTestSuite { test("Task.parZip2 should work if source finishes first") { implicit s => val f = Task.parZip2(Task(1), Task(2).delayExecution(1.second)).runToFuture diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskRaceSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskRaceSuite.scala index ab56f6f0f..5d3ec07eb 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskRaceSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskRaceSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,15 +16,17 @@ */ package monix.eval +import scala.annotation.nowarn import monix.execution.CancelableFuture import monix.execution.exceptions.DummyException import monix.execution.internal.Platform -import scala.concurrent.{Promise, TimeoutException} +import scala.concurrent.{ Promise, TimeoutException } import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } import monix.execution.atomic.Atomic +@nowarn object TaskRaceSuite extends BaseTestSuite { test("Task.raceMany should switch to other") { implicit s => val task = @@ -40,7 +42,8 @@ object TaskRaceSuite extends BaseTestSuite { test("Task.raceMany should onError from other") { implicit s => val ex = DummyException("dummy") val task = Task.raceMany( - Seq(Task.evalAsync(1).delayExecution(10.seconds), Task.evalAsync(throw ex).delayExecution(1.second))) + Seq(Task.evalAsync(1).delayExecution(10.seconds), Task.evalAsync(throw ex).delayExecution(1.second)) + ) val f = task.runToFuture s.tick() @@ -64,7 +67,8 @@ object TaskRaceSuite extends BaseTestSuite { test("Task.raceMany should onError from the source") { implicit s => val ex = DummyException("dummy") val task = Task.raceMany( - Seq(Task.evalAsync(throw ex).delayExecution(1.seconds), Task.evalAsync(99).delayExecution(10.second))) + Seq(Task.evalAsync(throw ex).delayExecution(1.seconds), Task.evalAsync(99).delayExecution(10.second)) + ) val f = task.runToFuture s.tick() @@ -475,7 +479,8 @@ object TaskRaceSuite extends BaseTestSuite { Task.racePair(acc, t).map { case Left((a, _)) => a case Right((_, b)) => b - }) + } + ) sum.runToFuture s.tick() @@ -490,7 +495,8 @@ object TaskRaceSuite extends BaseTestSuite { Task.racePair(acc, t).map { case Left((a, _)) => a case Right((_, b)) => b - }) + } + ) sum.runToFuture s.tick() @@ -505,7 +511,8 @@ object TaskRaceSuite extends BaseTestSuite { Task.racePair(acc, t).flatMap { case Left((a, fb)) => fb.cancel.map(_ => a) case Right((fa, b)) => fa.cancel.map(_ => b) - }) + } + ) val f = Task .racePair(Task.fromFuture(p.future), all) @@ -631,7 +638,8 @@ object TaskRaceSuite extends BaseTestSuite { Task.race(acc, t).map { case Left(a) => a case Right(b) => b - }) + } + ) sum.runToFuture s.tick() @@ -646,7 +654,8 @@ object TaskRaceSuite extends BaseTestSuite { Task.race(acc, t).map { case Left(a) => a case Right(b) => b - }) + } + ) sum.runToFuture s.tick() @@ -661,7 +670,8 @@ object TaskRaceSuite extends BaseTestSuite { Task.race(acc, t).map { case Left(a) => a case Right(b) => b - }) + } + ) val f = Task.race(Task.fromFuture(p.future), all).map { case Left(a) => a; case Right(b) => b }.runToFuture diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskRightSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskRightSuite.scala index 118259d50..9b59ca998 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskRightSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskRightSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskRunAsyncSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskRunAsyncSuite.scala index a1dd44067..2122975a8 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskRunAsyncSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskRunAsyncSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,15 +16,17 @@ */ package monix.eval +import scala.annotation.nowarn import monix.execution.Callback import monix.execution.ExecutionModel.AlwaysAsyncExecution import monix.execution.exceptions.DummyException import scala.concurrent.Promise -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } import scala.concurrent.duration._ +@nowarn object TaskRunAsyncSuite extends BaseTestSuite { test("runAsync") { implicit s => val task = Task(1).flatMap(x => Task(x + 2)).executeAsync.map(_ + 1) diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskSequenceSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskSequenceSuite.scala index 322f44885..8968c2954 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskSequenceSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskSequenceSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,14 +20,15 @@ package monix.eval import monix.execution.exceptions.DummyException import concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object TaskSequenceSuite extends BaseTestSuite { test("Task.sequence should not execute in parallel") { implicit s => val seq = Seq( Task.evalAsync(1).delayExecution(2.seconds), Task.evalAsync(2).delayExecution(1.second), - Task.evalAsync(3).delayExecution(3.seconds)) + Task.evalAsync(3).delayExecution(3.seconds) + ) val f = Task.sequence(seq).runToFuture s.tick() @@ -63,7 +64,8 @@ object TaskSequenceSuite extends BaseTestSuite { val seq = Seq( Task.evalAsync(1).delayExecution(2.seconds), Task.evalAsync(2).delayExecution(1.second), - Task.evalAsync(3).delayExecution(3.seconds)) + Task.evalAsync(3).delayExecution(3.seconds) + ) val f = Task.sequence(seq).runToFuture s.tick() diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskStartAndForgetSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskStartAndForgetSuite.scala index 68c21ed88..57f34f329 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskStartAndForgetSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskStartAndForgetSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskStartSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskStartSuite.scala index 6817fc305..f8661d900 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskStartSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskStartSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskTimedSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskTimedSuite.scala index 07cfce745..a941606b1 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskTimedSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskTimedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.eval import monix.execution.exceptions.DummyException import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object TaskTimedSuite extends BaseTestSuite { diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskToFutureSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskToFutureSuite.scala index d0618ae20..222fba782 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskToFutureSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskToFutureSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import monix.execution.exceptions.DummyException import scala.concurrent.Future import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object TaskToFutureSuite extends BaseTestSuite { test("Task.fromFuture for already completed references") { implicit s => @@ -46,7 +46,7 @@ object TaskToFutureSuite extends BaseTestSuite { test("Task.deferFutureAction for already completed references") { implicit s => def sum(list: List[Int]): Task[Int] = - Task.deferFutureAction(implicit s => Future.successful(list.sum)) + Task.deferFutureAction(_ => Future.successful(list.sum)) val f = sum((0 until 100).toList).runToFuture @@ -104,10 +104,10 @@ object TaskToFutureSuite extends BaseTestSuite { def loop(n: Int, acc: Int): Task[Int] = if (n > 0) Task - .deferFutureAction(implicit s => Future.successful(acc + 1)) + .deferFutureAction(_ => Future.successful(acc + 1)) .flatMap(loop(n - 1, _)) else - Task.deferFutureAction(implicit s => Future.successful(acc)) + Task.deferFutureAction(_ => Future.successful(acc)) val f = loop(10000, 0).runToFuture; s.tick() assertEquals(f.value, Some(Success(10000))) @@ -222,7 +222,7 @@ object TaskToFutureSuite extends BaseTestSuite { test("Task.deferFutureAction(cancelable)") { implicit s => val f1 = Task.eval(1).delayExecution(1.second).runToFuture - val f2 = Task.deferFutureAction(implicit s => f1).runToFuture + val f2 = Task.deferFutureAction(_ => f1).runToFuture assertEquals(f2.value, None) s.tick(1.second) @@ -231,7 +231,7 @@ object TaskToFutureSuite extends BaseTestSuite { test("Task.deferFutureAction(cancelable) is cancelable") { implicit s => val f1 = Task.eval(1).delayExecution(1.second).runToFuture - val f2 = Task.deferFutureAction(implicit s => f1).runToFuture + val f2 = Task.deferFutureAction(_ => f1).runToFuture assertEquals(f2.value, None) f2.cancel() diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskToStringSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskToStringSuite.scala index f8a893bdc..33d9b7f98 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskToStringSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskToStringSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-eval/shared/src/test/scala/monix/eval/TaskTraverseSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TaskTraverseSuite.scala index c9f34f347..26f96ecd0 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TaskTraverseSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TaskTraverseSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.eval import monix.execution.exceptions.DummyException import concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object TaskTraverseSuite extends BaseTestSuite { test("Task.traverse should not execute in parallel") { implicit s => diff --git a/monix-eval/shared/src/test/scala/monix/eval/TypeClassLawsForCoevalSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TypeClassLawsForCoevalSuite.scala index b29587a67..353e611d4 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TypeClassLawsForCoevalSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TypeClassLawsForCoevalSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.eval import cats.effect.laws.discipline.SyncEffectTests import cats.kernel.laws.discipline.MonoidTests -import cats.laws.discipline.{CoflatMapTests, SemigroupKTests} +import cats.laws.discipline.{ CoflatMapTests, SemigroupKTests } object TypeClassLawsForCoevalSuite extends BaseLawsSuite { checkAll("SyncEffect[Coeval]", SyncEffectTests[Coeval].syncEffect[Int, Int, Int]) diff --git a/monix-eval/shared/src/test/scala/monix/eval/TypeClassLawsForParallelApplicativeSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TypeClassLawsForParallelApplicativeSuite.scala index ecd69fccb..5a38f8053 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TypeClassLawsForParallelApplicativeSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TypeClassLawsForParallelApplicativeSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,12 +16,14 @@ */ package monix.eval +import scala.annotation.nowarn import cats.CommutativeApplicative import cats.laws.discipline.CommutativeApplicativeTests import monix.catnap.internal.ParallelApplicative import monix.eval.instances.CatsParallelForTask +@nowarn object TypeClassLawsForParallelApplicativeSuite extends BaseLawsSuite { implicit val ap: CommutativeApplicative[Task] = ParallelApplicative(new CatsParallelForTask) diff --git a/monix-eval/shared/src/test/scala/monix/eval/TypeClassLawsForTaskSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TypeClassLawsForTaskSuite.scala index 0b3e0dc03..9db2a7157 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TypeClassLawsForTaskSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TypeClassLawsForTaskSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,11 +16,13 @@ */ package monix.eval +import scala.annotation.nowarn -import cats.effect.laws.discipline.{ConcurrentEffectTests, ConcurrentTests} +import cats.effect.laws.discipline.{ ConcurrentEffectTests, ConcurrentTests } import cats.kernel.laws.discipline.MonoidTests -import cats.laws.discipline.{CoflatMapTests, CommutativeApplicativeTests, ParallelTests, SemigroupKTests} +import cats.laws.discipline.{ CoflatMapTests, CommutativeApplicativeTests, ParallelTests, SemigroupKTests } +@nowarn object TypeClassLawsForTaskSuite extends BaseTypeClassLawsForTaskSuite()( Task.defaultOptions.disableAutoCancelableRunLoops diff --git a/monix-eval/shared/src/test/scala/monix/eval/TypeClassLawsForTaskWithCallbackSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/TypeClassLawsForTaskWithCallbackSuite.scala index b7c80ec46..5a6bb30ca 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/TypeClassLawsForTaskWithCallbackSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/TypeClassLawsForTaskWithCallbackSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,11 +16,12 @@ */ package monix.eval +import scala.annotation.nowarn import cats.Eq -import cats.effect.laws.discipline.{ConcurrentEffectTests, ConcurrentTests} +import cats.effect.laws.discipline.{ ConcurrentEffectTests, ConcurrentTests } import cats.kernel.laws.discipline.MonoidTests -import cats.laws.discipline.{CoflatMapTests, CommutativeApplicativeTests, ParallelTests} +import cats.laws.discipline.{ CoflatMapTests, CommutativeApplicativeTests, ParallelTests } import monix.eval.Task.Options import monix.execution.Callback import monix.execution.schedulers.TestScheduler @@ -31,6 +32,7 @@ import scala.concurrent.Promise * Type class tests for Task that use an alternative `Eq`, making * use of Task's `runAsync(callback)`. */ +@nowarn object TypeClassLawsForTaskWithCallbackSuite extends BaseTypeClassLawsForTaskWithCallbackSuite()( Task.defaultOptions.disableAutoCancelableRunLoops @@ -51,7 +53,8 @@ class BaseTypeClassLawsForTaskWithCallbackSuite(implicit opts: Task.Options) ext implicit A: Eq[A], ec: TestScheduler, - opts: Options): Eq[Task[A]] = { + opts: Options + ): Eq[Task[A]] = { Eq.by { task => val p = Promise[A]() @@ -64,7 +67,8 @@ class BaseTypeClassLawsForTaskWithCallbackSuite(implicit opts: Task.Options) ext implicit A: Eq[A], ec: TestScheduler, - opts: Options): Eq[Task.Par[A]] = { + opts: Options + ): Eq[Task.Par[A]] = { import Task.Par.unwrap Eq.by { task => diff --git a/monix-eval/shared/src/test/scala/monix/eval/tracing/StackTracedContextSuite.scala b/monix-eval/shared/src/test/scala/monix/eval/tracing/StackTracedContextSuite.scala index 8b3820f6f..038269e81 100644 --- a/monix-eval/shared/src/test/scala/monix/eval/tracing/StackTracedContextSuite.scala +++ b/monix-eval/shared/src/test/scala/monix/eval/tracing/StackTracedContextSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -55,4 +55,4 @@ object StackTracedContextSuite extends BaseTestSuite { assertEquals(trace.omitted, 10) } -} \ No newline at end of file +} diff --git a/monix-execution/js/src/main/scala_3.0-/monix/execution/atomic/Atomic.scala b/monix-execution/atomic/js/src/main/scala-2/monix/execution/atomic/Atomic.scala similarity index 55% rename from monix-execution/js/src/main/scala_3.0-/monix/execution/atomic/Atomic.scala rename to monix-execution/atomic/js/src/main/scala-2/monix/execution/atomic/Atomic.scala index c34947934..aed6d6717 100644 --- a/monix-execution/js/src/main/scala_3.0-/monix/execution/atomic/Atomic.scala +++ b/monix-execution/atomic/js/src/main/scala-2/monix/execution/atomic/Atomic.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,112 +17,81 @@ package monix.execution.atomic -import monix.execution.misc._ +import monix.execution.atomic.internal._ import scala.reflect.macros.whitebox import monix.execution.atomic.PaddingStrategy.NoPadding +import scala.annotation.unused /** * Base trait of all atomic references, no matter the type. */ -abstract class Atomic[A] extends Serializable { - /** Get the current value persisted by this Atomic. */ +abstract class Atomic[A] extends Serializable with internal.AtomicDocs { + /** $atomicGetDesc */ def get(): A - /** Get the current value persisted by this Atomic, an alias for `get()`. */ - final def apply(): A = macro Atomic.Macros.applyMacro[A] - - /** Updates the current value. - * - * @param update will be the new value returned by `get()` - */ + /** $atomicSetDesc */ def set(update: A): Unit - /** Alias for [[set]]. Updates the current value. - * - * @param value will be the new value returned by `get()` - */ - final def update(value: A): Unit = macro Atomic.Macros.setMacro[A] - - /** Alias for [[set]]. Updates the current value. - * - * @param value will be the new value returned by `get()` - */ - final def `:=`(value: A): Unit = macro Atomic.Macros.setMacro[A] - - /** Does a compare-and-set operation on the current value. For more info, checkout the related - * [[https://en.wikipedia.org/wiki/Compare-and-swap Compare-and-swap Wikipedia page]]. + /** $compareAndSetDesc + * + * $atomicBestPractices * - * It's an atomic, worry free operation. - * - * @param expect is the value you expect to be persisted when the operation happens - * @param update will be the new value, should the check for `expect` succeeds - * @return either true in case the operation succeeded or false otherwise + * @param expect $atomicCASExpectParam + * @param update $atomicCASUpdateParam + * @return $atomicCASReturn $atomicCASReturn */ def compareAndSet(expect: A, update: A): Boolean - /** Sets the persisted value to `update` and returns the old value that was in place. - * It's an atomic, worry free operation. + /** $atomicGetAndSetDesc + * + * @param update $atomicGetAndSetParam + * @return $atomicGetAndSetReturn */ def getAndSet(update: A): A - /** Eventually sets to the given value. - * Has weaker visibility guarantees than the normal `set()`. - */ + /** $atomicLazySetDesc */ final def lazySet(value: A): Unit = macro Atomic.Macros.setMacro[A] - /** Abstracts over `compareAndSet`. You specify a transformation by specifying a callback to be - * executed, a callback that transforms the current value. This method will loop until it will - * succeed in replacing the current value with the one produced by your callback. + /** $atomicTransformExtractDesc * - * Note that the callback will be executed on each iteration of the loop, so it can be called - * multiple times - don't do destructive I/O or operations that mutate global state in it. + * $atomicTransformBestPractices * - * @param cb is a callback that receives the current value as input and returns a tuple that specifies - * the update + what should this method return when the operation succeeds. - * @return whatever was specified by your callback, once the operation succeeds + * @param f $atomicTransformExtractParamF + * + * @return $atomicTransformExtractReturn */ - final def transformAndExtract[U](cb: (A) => (U, A)): U = + final def transformAndExtract[U](f: A => (U, A)): U = macro Atomic.Macros.transformAndExtractMacro[A, U] - /** Abstracts over `compareAndSet`. You specify a transformation by specifying a callback to be - * executed, a callback that transforms the current value. This method will loop until it will - * succeed in replacing the current value with the one produced by the given callback. + /** $atomicTransformAndGetDesc + * + * $atomicTransformBestPractices * - * Note that the callback will be executed on each iteration of the loop, so it can be called - * multiple times - don't do destructive I/O or operations that mutate global state in it. - * - * @param cb is a callback that receives the current value as input and returns the `update` which is the - * new value that should be persisted - * @return whatever the update is, after the operation succeeds + * @param f $atomicTransformParam + * + * @return $atomicTransformAndGetReturn */ - final def transformAndGet(cb: (A) => A): A = + final def transformAndGet(f: A => A): A = macro Atomic.Macros.transformAndGetMacro[A] - /** Abstracts over `compareAndSet`. You specify a transformation by specifying a callback to be - * executed, a callback that transforms the current value. This method will loop until it will - * succeed in replacing the current value with the one produced by the given callback. + /** $atomicGetAndTransformDesc * - * Note that the callback will be executed on each iteration of the loop, so it can be called - * multiple times - don't do destructive I/O or operations that mutate global state in it. + * $atomicTransformBestPractices * - * @param cb is a callback that receives the current value as input and returns the `update` which is the - * new value that should be persisted - * @return the old value, just prior to when the successful update happened + * @param f $atomicTransformParam + * + * @return $atomicGetAndTransformReturn */ - final def getAndTransform(cb: (A) => A): A = + final def getAndTransform(f: A => A): A = macro Atomic.Macros.getAndTransformMacro[A] - /** Abstracts over `compareAndSet`. You specify a transformation by specifying a callback to be - * executed, a callback that transforms the current value. This method will loop until it will - * succeed in replacing the current value with the one produced by the given callback. - * - * Note that the callback will be executed on each iteration of the loop, so it can be called - * multiple times - don't do destructive I/O or operations that mutate global state in it. + /** $atomicTransformDesc * - * @param cb is a callback that receives the current value as input and returns the `update` which is the - * new value that should be persisted + * $atomicTransformBestPractices + * + * @param f $atomicTransformParam */ - final def transform(cb: (A) => A): Unit = + final def transform(f: A => A): Unit = macro Atomic.Macros.transformMacro[A] } @@ -169,20 +138,49 @@ object Atomic { * best reference possible, based on our `initialValue` */ def withPadding[A, R <: Atomic[A]](initialValue: A, padding: PaddingStrategy)( - implicit builder: AtomicBuilder[A, R]): R = + implicit builder: AtomicBuilder[A, R] + ): R = macro Atomic.Macros.buildAnyWithPaddingMacro[A, R] /** Returns the builder that would be chosen to construct Atomic * references for the given `initialValue`. */ - def builderFor[A, R <: Atomic[A]](initialValue: A)(implicit builder: AtomicBuilder[A, R]): AtomicBuilder[A, R] = + def builderFor[A, R <: Atomic[A]](@unused initialValue: A)(implicit + builder: AtomicBuilder[A, R] + ): AtomicBuilder[A, R] = builder + implicit final class DeprecatedExtensions[A](val self: Atomic[A]) extends AnyVal { + /** DEPRECATED - switch to [[Atomic.get]]. */ + @deprecated("Switch to .get()", "4.0.0") + def apply(): A = { + // $COVERAGE-OFF$ + self.get() + // $COVERAGE-ON$ + } + + /** DEPRECATED — switch to [[Atomic.set]]. */ + @deprecated("Switch to .set()", "4.0.0") + def update(value: A): Unit = { + // $COVERAGE-OFF$ + self.set(value) + // $COVERAGE-ON$ + } + + /** DEPRECATED — switch to [[Atomic.set]]. */ + @deprecated("Switch to .set()", "4.0.0") + def `:=`(value: A): Unit = { + // $COVERAGE-OFF$ + self.set(value) + // $COVERAGE-ON$ + } + } + /** Macros implementations for the [[Atomic]] type */ class Macros(override val c: whitebox.Context) extends InlineMacros with HygieneUtilMacros { import c.universe._ - def transformMacro[A: c.WeakTypeTag](cb: c.Expr[A => A]): c.Expr[Unit] = { + def transformMacro[A](f: c.Expr[A => A]): c.Expr[Unit] = { val selfExpr = c.Expr[Atomic[A]](c.prefix.tree) val self = util.name("self") @@ -190,24 +188,23 @@ object Atomic { * then inline them directly, otherwise bind arguments to a val for safety. */ val tree = - if (util.isClean(cb)) + if (util.isClean(f)) q""" val $self = $selfExpr - $self.set($cb($self.get())) + $self.set($f($self.get())) """ else { val fn = util.name("fn") q""" val $self = $selfExpr - val $fn = $cb + val $fn = $f $self.set($fn($self.get())) """ } - inlineAndReset[Unit](tree) } - def transformAndGetMacro[A: c.WeakTypeTag](cb: c.Expr[A => A]): c.Expr[A] = { + def transformAndGetMacro[A](f: c.Expr[A => A]): c.Expr[A] = { val selfExpr = c.Expr[Atomic[A]](c.prefix.tree) val self = util.name("self") val current = util.name("current") @@ -217,11 +214,11 @@ object Atomic { * then inline them directly, otherwise bind arguments to a val for safety. */ val tree = - if (util.isClean(cb)) { + if (util.isClean(f)) { q""" val $self = $selfExpr val $current = $self.get() - val $update = $cb($current) + val $update = $f($current) $self.set($update) $update """ @@ -229,7 +226,7 @@ object Atomic { val fn = util.name("fn") q""" val $self = $selfExpr - val $fn = $cb + val $fn = $f val $current = $self.get() val $update = $fn($current) $self.set($update) @@ -240,7 +237,7 @@ object Atomic { inlineAndReset[A](tree) } - def getAndTransformMacro[A: c.WeakTypeTag](cb: c.Expr[A => A]): c.Expr[A] = { + def getAndTransformMacro[A](f: c.Expr[A => A]): c.Expr[A] = { val selfExpr = c.Expr[Atomic[A]](c.prefix.tree) val self = util.name("self") val current = util.name("current") @@ -250,11 +247,11 @@ object Atomic { * then inline them directly, otherwise bind arguments to a val for safety. */ val tree = - if (util.isClean(cb)) { + if (util.isClean(f)) { q""" val $self = $selfExpr val $current = $self.get() - val $update = $cb($current) + val $update = $f($current) $self.set($update) $current """ @@ -262,7 +259,7 @@ object Atomic { val fn = util.name("fn") q""" val $self = $selfExpr - val $fn = $cb + val $fn = $f val $current = $self.get() val $update = $fn($current) $self.set($update) @@ -273,8 +270,7 @@ object Atomic { inlineAndReset[A](tree) } - def transformAndExtractMacro[S: c.WeakTypeTag, A: c.WeakTypeTag](cb: c.Expr[S => (A, S)]): c.Expr[A] = { - + def transformAndExtractMacro[S, A](f: c.Expr[S => (A, S)]): c.Expr[A] = { val selfExpr = c.Expr[Atomic[S]](c.prefix.tree) val self = util.name("self") val current = util.name("current") @@ -285,11 +281,11 @@ object Atomic { * then inline them directly, otherwise bind arguments to a val for safety. */ val tree = - if (util.isClean(cb)) { + if (util.isClean(f)) { q""" val $self = $selfExpr val $current = $self.get() - val ($result, $update) = $cb($current) + val ($result, $update) = $f($current) $self.set($update) $result """ @@ -297,57 +293,54 @@ object Atomic { val fn = util.name("fn") q""" val $self = $selfExpr - val $fn = $cb + val $fn = $f val $current = $self.get() val ($result, $update) = $fn($current) $self.set($update) $result """ } - inlineAndReset[A](tree) } - def buildAnyMacro[A: c.WeakTypeTag, R <: Atomic[A]: c.WeakTypeTag](initialValue: c.Expr[A])( - builder: c.Expr[AtomicBuilder[A, R]]): c.Expr[R] = { - + def buildAnyMacro[A, R <: Atomic[A]](initialValue: c.Expr[A])( + builder: c.Expr[AtomicBuilder[A, R]] + ): c.Expr[R] = { val expr = reify { builder.splice.buildInstance(initialValue.splice, NoPadding, allowPlatformIntrinsics = true) } - inlineAndReset[R](expr.tree) } - def buildAnyWithPaddingMacro[A: c.WeakTypeTag, R <: Atomic[A]: c.WeakTypeTag]( + def buildAnyWithPaddingMacro[A, R <: Atomic[A]]( initialValue: c.Expr[A], - padding: c.Expr[PaddingStrategy])(builder: c.Expr[AtomicBuilder[A, R]]): c.Expr[R] = { - + padding: c.Expr[PaddingStrategy] + )(builder: c.Expr[AtomicBuilder[A, R]]): c.Expr[R] = { val expr = reify { builder.splice.buildInstance(initialValue.splice, padding.splice, allowPlatformIntrinsics = true) } - inlineAndReset[R](expr.tree) } - def applyMacro[A: c.WeakTypeTag](): c.Expr[A] = { + def applyMacro[A](): c.Expr[A] = { val selfExpr = c.Expr[Atomic[A]](c.prefix.tree) val tree = q"""$selfExpr.get()""" inlineAndReset[A](tree) } - def setMacro[A: c.WeakTypeTag](value: c.Expr[A]): c.Expr[Unit] = { + def setMacro[A](value: c.Expr[A]): c.Expr[Unit] = { val selfExpr = c.Expr[Atomic[A]](c.prefix.tree) val tree = q"""$selfExpr.set($value)""" inlineAndReset[Unit](tree) } - def addMacro[A: c.WeakTypeTag](value: c.Expr[A]): c.Expr[Unit] = { + def addMacro[A](value: c.Expr[A]): c.Expr[Unit] = { val selfExpr = c.Expr[Atomic[A]](c.prefix.tree) val tree = q"""$selfExpr.add($value)""" inlineAndReset[Unit](tree) } - def subtractMacro[A: c.WeakTypeTag](value: c.Expr[A]): c.Expr[Unit] = { + def subtractMacro[A](value: c.Expr[A]): c.Expr[Unit] = { val selfExpr = c.Expr[Atomic[A]](c.prefix.tree) val tree = q"""$selfExpr.subtract($value)""" inlineAndReset[Unit](tree) diff --git a/monix-execution/jvm/src/main/scala_3.0-/monix/execution/atomic/AtomicNumber.scala b/monix-execution/atomic/js/src/main/scala-2/monix/execution/atomic/AtomicNumber.scala similarity index 97% rename from monix-execution/jvm/src/main/scala_3.0-/monix/execution/atomic/AtomicNumber.scala rename to monix-execution/atomic/js/src/main/scala-2/monix/execution/atomic/AtomicNumber.scala index 191c18b4a..7cbeaaacf 100644 --- a/monix-execution/jvm/src/main/scala_3.0-/monix/execution/atomic/AtomicNumber.scala +++ b/monix-execution/atomic/js/src/main/scala-2/monix/execution/atomic/AtomicNumber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/atomic/js/src/main/scala-3/monix/execution/atomic/Atomic.scala b/monix-execution/atomic/js/src/main/scala-3/monix/execution/atomic/Atomic.scala new file mode 100644 index 000000000..096b2afc5 --- /dev/null +++ b/monix-execution/atomic/js/src/main/scala-3/monix/execution/atomic/Atomic.scala @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic + +/** + * Base trait of all atomic references, no matter the type. + */ +abstract class Atomic[A] extends Serializable with internal.AtomicDocs { + /** $atomicGetDesc */ + def get(): A + + /** $atomicSetDesc */ + def set(update: A): Unit + + /** $compareAndSetDesc + * + * $atomicBestPractices + * + * @param expect $atomicCASExpectParam + * @param update $atomicCASUpdateParam + * @return $atomicCASReturn $atomicCASReturn + */ + def compareAndSet(expect: A, update: A): Boolean + + /** $atomicGetAndSetDesc + * + * @param update $atomicGetAndSetParam + * @return $atomicGetAndSetReturn + */ + def getAndSet(update: A): A + + /** $atomicLazySetDesc */ + def lazySet(update: A): Unit = set(update) + + /** $atomicTransformExtractDesc + * + * $atomicTransformBestPractices + * + * @param f $atomicTransformExtractParamF + * + * @return $atomicTransformExtractReturn + */ + inline final def transformAndExtract[U](inline f: A => (U, A)): U = { + val current = get() + val (result, update) = f(current) + set(update) + result + } + + /** $atomicTransformAndGetDesc + * + * $atomicTransformBestPractices + * + * @param f $atomicTransformParam + * + * @return $atomicTransformAndGetReturn + */ + inline final def transformAndGet(inline f: (A) => A): A = { + val current = get() + val update = f(current) + set(update) + update + } + + /** $atomicGetAndTransformDesc + * + * $atomicTransformBestPractices + * + * @param f $atomicTransformParam + * + * @return $atomicGetAndTransformReturn + */ + inline final def getAndTransform(inline f: (A) => A): A = { + val current = get() + val update = f(current) + + set(update) + current + } + + /** $atomicTransformDesc + * + * $atomicTransformBestPractices + * + * @param f $atomicTransformParam + */ + inline final def transform(inline f: (A) => A): Unit = + set(f(get())) +} + +object Atomic { + /** Constructs an `Atomic[A]` reference. + * + * Based on the `initialValue`, it will return the best, most + * specific type. E.g. you give it a number, it will return + * something inheriting from `AtomicNumber[A]`. That's why it takes + * an `AtomicBuilder[T, R]` as an implicit parameter - but worry + * not about such details as it just works. + * + * @param initialValue is the initial value with which to + * initialize the Atomic reference + * + * @param builder is the builder that helps us to build the + * best reference possible, based on our `initialValue` + */ + inline def apply[A, R <: Atomic[A]](initialValue: A)(implicit builder: AtomicBuilder[A, R]): R = + builder.buildInstance(initialValue, PaddingStrategy.NoPadding, allowPlatformIntrinsics = true) + + /** Constructs an `Atomic[A]` reference, applying the provided + * [[PaddingStrategy]] in order to counter the "false sharing" + * problem. + * + * Based on the `initialValue`, it will return the best, most + * specific type. E.g. you give it a number, it will return + * something inheriting from `AtomicNumber[A]`. That's why it takes + * an `AtomicBuilder[A, R]` as an implicit parameter - but worry + * not about such details as it just works. + * + * Note that for ''Scala.js'' we aren't applying any padding, as it + * doesn't make much sense, since Javascript execution is single + * threaded, but this builder is provided for syntax compatibility + * anyway across the JVM and Javascript and we never know how + * Javascript engines will evolve. + * + * @param initialValue is the initial value with which to + * initialize the Atomic reference + * + * @param padding is the [[PaddingStrategy]] to apply + * + * @param builder is the builder that helps us to build the + * best reference possible, based on our `initialValue` + */ + inline def withPadding[A, R <: Atomic[A]](initialValue: A, padding: PaddingStrategy)( + implicit builder: AtomicBuilder[A, R] + ): R = + builder.buildInstance(initialValue, padding, allowPlatformIntrinsics = true) + + /** Returns the builder that would be chosen to construct Atomic + * references for the given `initialValue`. + */ + def builderFor[A, R <: Atomic[A]](initialValue: A)(implicit builder: AtomicBuilder[A, R]): AtomicBuilder[A, R] = { + val _ = initialValue + builder + } + + extension [A](self: Atomic[A]) { + /** DEPRECATED - switch to [[Atomic.get]]. */ + @deprecated("Switch to .get()", "4.0.0") + def apply(): A = { + // $COVERAGE-OFF$ + self.get() + // $COVERAGE-ON$ + } + + /** DEPRECATED — switch to [[Atomic.set]]. */ + @deprecated("Switch to .set()", "4.0.0") + def update(value: A): Unit = { + // $COVERAGE-OFF$ + self.set(value) + // $COVERAGE-ON$ + } + + /** DEPRECATED — switch to [[Atomic.set]]. */ + @deprecated("Switch to .set()", "4.0.0") + def `:=`(value: A): Unit = { + // $COVERAGE-OFF$ + self.set(value) + // $COVERAGE-ON$ + } + } +} diff --git a/monix-execution/js/src/main/scala_3.0/monix/execution/atomic/AtomicNumber.scala b/monix-execution/atomic/js/src/main/scala-3/monix/execution/atomic/AtomicNumber.scala similarity index 97% rename from monix-execution/js/src/main/scala_3.0/monix/execution/atomic/AtomicNumber.scala rename to monix-execution/atomic/js/src/main/scala-3/monix/execution/atomic/AtomicNumber.scala index 60040a1c7..bc5d20fd4 100644 --- a/monix-execution/js/src/main/scala_3.0/monix/execution/atomic/AtomicNumber.scala +++ b/monix-execution/atomic/js/src/main/scala-3/monix/execution/atomic/AtomicNumber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicAny.scala b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicAny.scala similarity index 88% rename from monix-execution/js/src/main/scala/monix/execution/atomic/AtomicAny.scala rename to monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicAny.scala index 4719035b4..06945711a 100644 --- a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicAny.scala +++ b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicAny.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,13 +17,15 @@ package monix.execution.atomic +import scala.annotation.unused + /** Atomic references wrapping `AnyRef` values. * * @tparam A is forced to be an `AnyRef` because the equality test is * by reference and not by value. */ final class AtomicAny[A <: AnyRef] private[atomic] (initialValue: A) extends Atomic[A] { - private[this] var ref = initialValue + private var ref = initialValue def getAndSet(update: A): A = { val current = ref @@ -71,7 +73,7 @@ object AtomicAny { * @param initialValue is the initial value with which to initialize the atomic * @param padding is the [[PaddingStrategy]] to apply */ - def withPadding[A <: AnyRef](initialValue: A, padding: PaddingStrategy): AtomicAny[A] = + def withPadding[A <: AnyRef](initialValue: A, @unused padding: PaddingStrategy): AtomicAny[A] = new AtomicAny(initialValue) /** $createDesc @@ -86,7 +88,11 @@ object AtomicAny { * the instance is allowed to use the Java 8 optimized operations * for `getAndSet` and for `getAndAdd` */ - def create[A <: AnyRef](initialValue: A, padding: PaddingStrategy, allowPlatformIntrinsics: Boolean): AtomicAny[A] = + def create[A <: AnyRef]( + initialValue: A, + @unused padding: PaddingStrategy, + @unused allowPlatformIntrinsics: Boolean + ): AtomicAny[A] = new AtomicAny(initialValue) /** $createDesc @@ -104,6 +110,6 @@ object AtomicAny { * @param initialValue is the initial value with which to initialize the atomic * @param padding is the [[PaddingStrategy]] to apply */ - def safe[A <: AnyRef](initialValue: A, padding: PaddingStrategy): AtomicAny[A] = + def safe[A <: AnyRef](initialValue: A, @unused padding: PaddingStrategy): AtomicAny[A] = new AtomicAny(initialValue) } diff --git a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicBoolean.scala b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicBoolean.scala similarity index 89% rename from monix-execution/js/src/main/scala/monix/execution/atomic/AtomicBoolean.scala rename to monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicBoolean.scala index fbc84ea07..c6ea45484 100644 --- a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicBoolean.scala +++ b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicBoolean.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,6 +17,8 @@ package monix.execution.atomic +import scala.annotation.unused + /** Atomic references wrapping `Boolean` values. * * Note that the equality test in `compareAndSet` is value based, @@ -24,7 +26,7 @@ package monix.execution.atomic */ final class AtomicBoolean private[atomic] (initialValue: Boolean) extends Atomic[Boolean] { - private[this] var ref = initialValue + private var ref = initialValue def getAndSet(update: Boolean): Boolean = { val current = ref @@ -69,7 +71,7 @@ object AtomicBoolean { * @param initialValue is the initial value with which to initialize the atomic * @param padding is the [[PaddingStrategy]] to apply */ - def withPadding(initialValue: Boolean, padding: PaddingStrategy): AtomicBoolean = + def withPadding(initialValue: Boolean, @unused padding: PaddingStrategy): AtomicBoolean = new AtomicBoolean(initialValue) /** $createDesc @@ -84,7 +86,11 @@ object AtomicBoolean { * the instance is allowed to use the Java 8 optimized operations * for `getAndSet` and for `getAndAdd` */ - def create(initialValue: Boolean, padding: PaddingStrategy, allowPlatformIntrinsics: Boolean): AtomicBoolean = + def create( + initialValue: Boolean, + @unused padding: PaddingStrategy, + @unused allowPlatformIntrinsics: Boolean + ): AtomicBoolean = new AtomicBoolean(initialValue) /** $createDesc @@ -102,6 +108,6 @@ object AtomicBoolean { * @param initialValue is the initial value with which to initialize the atomic * @param padding is the [[PaddingStrategy]] to apply */ - def safe(initialValue: Boolean, padding: PaddingStrategy): AtomicBoolean = + def safe(initialValue: Boolean, @unused padding: PaddingStrategy): AtomicBoolean = new AtomicBoolean(initialValue) } diff --git a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicBuilder.scala b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicBuilder.scala similarity index 98% rename from monix-execution/js/src/main/scala/monix/execution/atomic/AtomicBuilder.scala rename to monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicBuilder.scala index efdbc90c3..17d4373fd 100644 --- a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicBuilder.scala +++ b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicBuilder.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -125,7 +125,8 @@ object AtomicBuilder extends Implicits.Level2 { def buildInstance( initialValue: Double, strategy: PaddingStrategy, - allowPlatformIntrinsics: Boolean): AtomicDouble = + allowPlatformIntrinsics: Boolean + ): AtomicDouble = AtomicDouble(initialValue) def buildSafeInstance(initialValue: Double, strategy: PaddingStrategy): AtomicDouble = AtomicDouble(initialValue) diff --git a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicByte.scala b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicByte.scala similarity index 78% rename from monix-execution/js/src/main/scala/monix/execution/atomic/AtomicByte.scala rename to monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicByte.scala index 64482d056..363523250 100644 --- a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicByte.scala +++ b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicByte.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,6 +17,8 @@ package monix.execution.atomic +import scala.annotation.unused + /** Atomic references wrapping `Byte` values. * * Note that the equality test in `compareAndSet` is value based, @@ -24,8 +26,8 @@ package monix.execution.atomic */ final class AtomicByte private[atomic] (initialValue: Byte) extends AtomicNumber[Byte] { - private[this] var ref = initialValue - private[this] val mask = 255 + private var ref = initialValue + private val mask = 255 def getAndSet(update: Byte): Byte = { val current = ref @@ -116,10 +118,11 @@ object AtomicByte { /** $createDesc * - * @param initialValue is the initial value with which to initialize the atomic - * @param padding is the [[PaddingStrategy]] to apply + * @param initialValue is the initial value with which to initialize the atomic; + * @param padding is the [[PaddingStrategy]] to apply — NOT USED on top of JavaScript, + * this being provided only for backwards compatibility with the JVM; */ - def withPadding(initialValue: Byte, padding: PaddingStrategy): AtomicByte = + def withPadding(initialValue: Byte, @unused padding: PaddingStrategy): AtomicByte = new AtomicByte(initialValue) /** $createDesc @@ -129,12 +132,16 @@ object AtomicByte { * `getAndSet` and for `getAndAdd`. * * @param initialValue is the initial value with which to initialize the atomic - * @param padding is the [[PaddingStrategy]] to apply - * @param allowPlatformIntrinsics is a boolean parameter that specifies whether - * the instance is allowed to use the Java 8 optimized operations - * for `getAndSet` and for `getAndAdd` + * @param padding is the [[PaddingStrategy]] to apply — NOT USED on top of JavaScript, + * this being provided only for backwards compatibility with the JVM; + * @param allowPlatformIntrinsics — NOT USED on top of JavaScript, this + * being provided only for backwards compatibility with the JVM; */ - def create(initialValue: Byte, padding: PaddingStrategy, allowPlatformIntrinsics: Boolean): AtomicByte = + def create( + initialValue: Byte, + @unused padding: PaddingStrategy, + @unused allowPlatformIntrinsics: Boolean + ): AtomicByte = new AtomicByte(initialValue) /** $createDesc @@ -150,8 +157,10 @@ object AtomicByte { * recommended, because the "safe" atomic instances have overhead. * * @param initialValue is the initial value with which to initialize the atomic - * @param padding is the [[PaddingStrategy]] to apply + * @param padding is the [[PaddingStrategy]] to apply — NOT USED on top + * of JavaScript, this being provided only for backwards compatibility + * with the JVM; */ - def safe(initialValue: Byte, padding: PaddingStrategy): AtomicByte = + def safe(initialValue: Byte, @unused padding: PaddingStrategy): AtomicByte = new AtomicByte(initialValue) } diff --git a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicChar.scala b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicChar.scala similarity index 84% rename from monix-execution/js/src/main/scala/monix/execution/atomic/AtomicChar.scala rename to monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicChar.scala index cbd555501..22141f67c 100644 --- a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicChar.scala +++ b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicChar.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,6 +17,8 @@ package monix.execution.atomic +import scala.annotation.unused + /** Atomic references wrapping `Char` values. * * Note that the equality test in `compareAndSet` is value based, @@ -24,8 +26,8 @@ package monix.execution.atomic */ final class AtomicChar private[atomic] (initialValue: Char) extends AtomicNumber[Char] { - private[this] var ref = initialValue - private[this] val mask = 255 + 255 * 256 + private var ref = initialValue + private val mask = 255 + 255 * 256 def getAndSet(update: Char): Char = { val current = ref @@ -120,9 +122,9 @@ object AtomicChar { /** $createDesc * * @param initialValue is the initial value with which to initialize the atomic - * @param padding is the [[PaddingStrategy]] to apply + * @param padding — NOT USED on top of JavaScript; */ - def withPadding(initialValue: Char, padding: PaddingStrategy): AtomicChar = + def withPadding(initialValue: Char, @unused padding: PaddingStrategy): AtomicChar = new AtomicChar(initialValue) /** $createDesc @@ -132,12 +134,14 @@ object AtomicChar { * `getAndSet` and for `getAndAdd`. * * @param initialValue is the initial value with which to initialize the atomic - * @param padding is the [[PaddingStrategy]] to apply - * @param allowPlatformIntrinsics is a boolean parameter that specifies whether - * the instance is allowed to use the Java 8 optimized operations - * for `getAndSet` and for `getAndAdd` + * @param padding — NOT USED on top of JavaScript; + * @param allowPlatformIntrinsics — NOT USED on top of JavaScript; */ - def create(initialValue: Char, padding: PaddingStrategy, allowPlatformIntrinsics: Boolean): AtomicChar = + def create( + initialValue: Char, + @unused padding: PaddingStrategy, + @unused allowPlatformIntrinsics: Boolean + ): AtomicChar = new AtomicChar(initialValue) /** $createDesc @@ -153,8 +157,8 @@ object AtomicChar { * recommended, because the "safe" atomic instances have overhead. * * @param initialValue is the initial value with which to initialize the atomic - * @param padding is the [[PaddingStrategy]] to apply + * @param padding — NOT USED on top of JavaScript; */ - def safe(initialValue: Char, padding: PaddingStrategy): AtomicChar = + def safe(initialValue: Char, @unused padding: PaddingStrategy): AtomicChar = new AtomicChar(initialValue) } diff --git a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicDouble.scala b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicDouble.scala similarity index 82% rename from monix-execution/js/src/main/scala/monix/execution/atomic/AtomicDouble.scala rename to monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicDouble.scala index b99fa4d14..c740f06ce 100644 --- a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicDouble.scala +++ b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicDouble.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,6 +17,8 @@ package monix.execution.atomic +import scala.annotation.unused + /** Atomic references wrapping `Double` values. * * Note that the equality test in `compareAndSet` is value based, @@ -24,7 +26,7 @@ package monix.execution.atomic */ final class AtomicDouble private[atomic] (initialValue: Double) extends AtomicNumber[Double] { - private[this] var ref = initialValue + private var ref = initialValue def getAndSet(update: Double): Double = { val current = ref @@ -107,9 +109,9 @@ object AtomicDouble { /** $createDesc * * @param initialValue is the initial value with which to initialize the atomic - * @param padding is the [[PaddingStrategy]] to apply + * @param padding — NOT USED on top of JavaScript; */ - def withPadding(initialValue: Double, padding: PaddingStrategy): AtomicDouble = + def withPadding(initialValue: Double, @unused padding: PaddingStrategy): AtomicDouble = new AtomicDouble(initialValue) /** $createDesc @@ -119,12 +121,14 @@ object AtomicDouble { * `getAndSet` and for `getAndAdd`. * * @param initialValue is the initial value with which to initialize the atomic - * @param padding is the [[PaddingStrategy]] to apply - * @param allowPlatformIntrinsics is a boolean parameter that specifies whether - * the instance is allowed to use the Java 8 optimized operations - * for `getAndSet` and for `getAndAdd` + * @param padding — NOT USED on top of JavaScript; + * @param allowPlatformIntrinsics — NOT USED on top of JavaScript; */ - def create(initialValue: Double, padding: PaddingStrategy, allowPlatformIntrinsics: Boolean): AtomicDouble = + def create( + initialValue: Double, + @unused padding: PaddingStrategy, + @unused allowPlatformIntrinsics: Boolean + ): AtomicDouble = new AtomicDouble(initialValue) /** $createDesc @@ -140,8 +144,8 @@ object AtomicDouble { * recommended, because the "safe" atomic instances have overhead. * * @param initialValue is the initial value with which to initialize the atomic - * @param padding is the [[PaddingStrategy]] to apply + * @param padding — NOT USED on top of JavaScript; */ - def safe(initialValue: Double, padding: PaddingStrategy): AtomicDouble = + def safe(initialValue: Double, @unused padding: PaddingStrategy): AtomicDouble = new AtomicDouble(initialValue) } diff --git a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicFloat.scala b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicFloat.scala similarity index 89% rename from monix-execution/js/src/main/scala/monix/execution/atomic/AtomicFloat.scala rename to monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicFloat.scala index 5a503428f..9be4606a7 100644 --- a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicFloat.scala +++ b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicFloat.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,6 +17,8 @@ package monix.execution.atomic +import scala.annotation.unused + /** Atomic references wrapping `Float` values. * * Note that the equality test in `compareAndSet` is value based, @@ -24,7 +26,7 @@ package monix.execution.atomic */ final class AtomicFloat private[atomic] (initialValue: Float) extends AtomicNumber[Float] { - private[this] var ref = initialValue + private var ref = initialValue def getAndSet(update: Float): Float = { val current = ref @@ -121,7 +123,7 @@ object AtomicFloat { * @param initialValue is the initial value with which to initialize the atomic * @param padding is the [[PaddingStrategy]] to apply */ - def withPadding(initialValue: Float, padding: PaddingStrategy): AtomicFloat = + def withPadding(initialValue: Float, @unused padding: PaddingStrategy): AtomicFloat = new AtomicFloat(initialValue) /** $createDesc @@ -136,7 +138,11 @@ object AtomicFloat { * the instance is allowed to use the Java 8 optimized operations * for `getAndSet` and for `getAndAdd` */ - def create(initialValue: Float, padding: PaddingStrategy, allowPlatformIntrinsics: Boolean): AtomicFloat = + def create( + initialValue: Float, + @unused padding: PaddingStrategy, + @unused allowPlatformIntrinsics: Boolean + ): AtomicFloat = new AtomicFloat(initialValue) /** $createDesc @@ -151,9 +157,9 @@ object AtomicFloat { * supports `sun.misc.Unsafe` and if it does, then its usage is * recommended, because the "safe" atomic instances have overhead. * - * @param initialValue is the initial value with which to initialize the atomic - * @param padding is the [[PaddingStrategy]] to apply + * @param initialValue is the initial value with which to initialize the atomic; + * @param padding — NOT USED on top of JavaScript; */ - def safe(initialValue: Float, padding: PaddingStrategy): AtomicFloat = + def safe(initialValue: Float, @unused padding: PaddingStrategy): AtomicFloat = new AtomicFloat(initialValue) } diff --git a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicInt.scala b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicInt.scala similarity index 84% rename from monix-execution/js/src/main/scala/monix/execution/atomic/AtomicInt.scala rename to monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicInt.scala index 1d8d66ae3..62d18087d 100644 --- a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicInt.scala +++ b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicInt.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,6 +17,8 @@ package monix.execution.atomic +import scala.annotation.unused + /** Atomic references wrapping `Int` values. * * Note that the equality test in `compareAndSet` is value based, @@ -24,7 +26,7 @@ package monix.execution.atomic */ final class AtomicInt private[atomic] (initialValue: Int) extends AtomicNumber[Int] { - private[this] var ref = initialValue + private var ref = initialValue def getAndSet(update: Int): Int = { val current = ref @@ -119,9 +121,9 @@ object AtomicInt { /** $createDesc * * @param initialValue is the initial value with which to initialize the atomic - * @param padding is the [[PaddingStrategy]] to apply + * @param padding — NOT USED on top of JavaScript; */ - def withPadding(initialValue: Int, padding: PaddingStrategy): AtomicInt = + def withPadding(initialValue: Int, @unused padding: PaddingStrategy): AtomicInt = new AtomicInt(initialValue) /** $createDesc @@ -131,12 +133,10 @@ object AtomicInt { * `getAndSet` and for `getAndAdd`. * * @param initialValue is the initial value with which to initialize the atomic - * @param padding is the [[PaddingStrategy]] to apply - * @param allowPlatformIntrinsics is a boolean parameter that specifies whether - * the instance is allowed to use the Java 8 optimized operations - * for `getAndSet` and for `getAndAdd` + * @param padding — NOT USED on top of JavaScript; + * @param allowPlatformIntrinsics — NOT USED on top of JavaScript; */ - def create(initialValue: Int, padding: PaddingStrategy, allowPlatformIntrinsics: Boolean): AtomicInt = + def create(initialValue: Int, @unused padding: PaddingStrategy, @unused allowPlatformIntrinsics: Boolean): AtomicInt = new AtomicInt(initialValue) /** $createDesc @@ -152,8 +152,8 @@ object AtomicInt { * recommended, because the "safe" atomic instances have overhead. * * @param initialValue is the initial value with which to initialize the atomic - * @param padding is the [[PaddingStrategy]] to apply + * @param padding — NOT USED on top of JavaScript; */ - def safe(initialValue: Int, padding: PaddingStrategy): AtomicInt = + def safe(initialValue: Int, @unused padding: PaddingStrategy): AtomicInt = new AtomicInt(initialValue) } diff --git a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicLong.scala b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicLong.scala similarity index 84% rename from monix-execution/js/src/main/scala/monix/execution/atomic/AtomicLong.scala rename to monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicLong.scala index d26713984..584ac308c 100644 --- a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicLong.scala +++ b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicLong.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,6 +17,8 @@ package monix.execution.atomic +import scala.annotation.unused + /** Atomic references wrapping `Long` values. * * Note that the equality test in `compareAndSet` is value based, @@ -24,7 +26,7 @@ package monix.execution.atomic */ final class AtomicLong private[atomic] (initialValue: Long) extends AtomicNumber[Long] { - private[this] var ref = initialValue + private var ref = initialValue def getAndSet(update: Long): Long = { val current = ref @@ -119,9 +121,9 @@ object AtomicLong { /** $createDesc * * @param initialValue is the initial value with which to initialize the atomic - * @param padding is the [[PaddingStrategy]] to apply + * @param padding — NOT USED on top of JavaScript; */ - def withPadding(initialValue: Long, padding: PaddingStrategy): AtomicLong = + def withPadding(initialValue: Long, @unused padding: PaddingStrategy): AtomicLong = new AtomicLong(initialValue) /** $createDesc @@ -131,12 +133,14 @@ object AtomicLong { * `getAndSet` and for `getAndAdd`. * * @param initialValue is the initial value with which to initialize the atomic - * @param padding is the [[PaddingStrategy]] to apply - * @param allowPlatformIntrinsics is a boolean parameter that specifies whether - * the instance is allowed to use the Java 8 optimized operations - * for `getAndSet` and for `getAndAdd` + * @param padding — NOT USED on top of JavaScript; + * @param allowPlatformIntrinsics — NOT USED on top of JavaScript; */ - def create(initialValue: Long, padding: PaddingStrategy, allowPlatformIntrinsics: Boolean): AtomicLong = + def create( + initialValue: Long, + @unused padding: PaddingStrategy, + @unused allowPlatformIntrinsics: Boolean + ): AtomicLong = new AtomicLong(initialValue) /** $createDesc @@ -152,8 +156,8 @@ object AtomicLong { * recommended, because the "safe" atomic instances have overhead. * * @param initialValue is the initial value with which to initialize the atomic - * @param padding is the [[PaddingStrategy]] to apply + * @param padding — NOT USED on top of JavaScript; */ - def safe(initialValue: Long, padding: PaddingStrategy): AtomicLong = + def safe(initialValue: Long, @unused padding: PaddingStrategy): AtomicLong = new AtomicLong(initialValue) } diff --git a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicNumberAny.scala b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicNumberAny.scala similarity index 85% rename from monix-execution/js/src/main/scala/monix/execution/atomic/AtomicNumberAny.scala rename to monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicNumberAny.scala index 45cd29da4..4a632f67f 100644 --- a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicNumberAny.scala +++ b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicNumberAny.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,6 +17,8 @@ package monix.execution.atomic +import scala.annotation.unused + /** Atomic references wrapping any values implementing * Scala's `Numeric` type class. * @@ -27,8 +29,8 @@ package monix.execution.atomic */ final class AtomicNumberAny[A <: AnyRef: Numeric] private[atomic] (initialValue: A) extends AtomicNumber[A] { - private[this] val ev = implicitly[Numeric[A]] - private[this] var ref = initialValue + private val ev = implicitly[Numeric[A]] + private var ref = initialValue def getAndSet(update: A): A = { val current = ref @@ -126,7 +128,7 @@ object AtomicNumberAny { * @param initialValue is the initial value with which to initialize the atomic * @param padding is the [[PaddingStrategy]] to apply */ - def withPadding[A <: AnyRef: Numeric](initialValue: A, padding: PaddingStrategy): AtomicNumberAny[A] = + def withPadding[A <: AnyRef: Numeric](initialValue: A, @unused padding: PaddingStrategy): AtomicNumberAny[A] = new AtomicNumberAny[A](initialValue) /** $createDesc @@ -136,15 +138,14 @@ object AtomicNumberAny { * `getAndSet` and for `getAndAdd`. * * @param initialValue is the initial value with which to initialize the atomic - * @param padding is the [[PaddingStrategy]] to apply - * @param allowPlatformIntrinsics is a boolean parameter that specifies whether - * the instance is allowed to use the Java 8 optimized operations - * for `getAndSet` and for `getAndAdd` + * @param padding — NOT USED on top of JavaScript; + * @param allowPlatformIntrinsics — NOT USED on top of JavaScript; */ def create[A <: AnyRef: Numeric]( initialValue: A, - padding: PaddingStrategy, - allowPlatformIntrinsics: Boolean): AtomicNumberAny[A] = + @unused padding: PaddingStrategy, + @unused allowPlatformIntrinsics: Boolean + ): AtomicNumberAny[A] = new AtomicNumberAny[A](initialValue) /** $createDesc @@ -160,8 +161,8 @@ object AtomicNumberAny { * recommended, because the "safe" atomic instances have overhead. * * @param initialValue is the initial value with which to initialize the atomic - * @param padding is the [[PaddingStrategy]] to apply + * @param padding — NOT USED on top of JavaScript; */ - def safe[A <: AnyRef: Numeric](initialValue: A, padding: PaddingStrategy): AtomicNumberAny[A] = + def safe[A <: AnyRef: Numeric](initialValue: A, @unused padding: PaddingStrategy): AtomicNumberAny[A] = new AtomicNumberAny[A](initialValue) } diff --git a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicShort.scala b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicShort.scala similarity index 91% rename from monix-execution/js/src/main/scala/monix/execution/atomic/AtomicShort.scala rename to monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicShort.scala index 1bc29c968..386cdeb48 100644 --- a/monix-execution/js/src/main/scala/monix/execution/atomic/AtomicShort.scala +++ b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/AtomicShort.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,6 +17,8 @@ package monix.execution.atomic +import scala.annotation.unused + /** Atomic references wrapping `Short` values. * * Note that the equality test in `compareAndSet` is value based, @@ -24,8 +26,8 @@ package monix.execution.atomic */ final class AtomicShort private[atomic] (initialValue: Short) extends AtomicNumber[Short] { - private[this] var ref = initialValue - private[this] val mask = 255 + 255 * 256 + private var ref = initialValue + private val mask = 255 + 255 * 256 def getAndSet(update: Short): Short = { val current = ref @@ -122,7 +124,7 @@ object AtomicShort { * @param initialValue is the initial value with which to initialize the atomic * @param padding is the [[PaddingStrategy]] to apply */ - def withPadding(initialValue: Short, padding: PaddingStrategy): AtomicShort = + def withPadding(initialValue: Short, @unused padding: PaddingStrategy): AtomicShort = new AtomicShort(initialValue) /** $createDesc @@ -137,7 +139,11 @@ object AtomicShort { * the instance is allowed to use the Java 8 optimized operations * for `getAndSet` and for `getAndAdd` */ - def create(initialValue: Short, padding: PaddingStrategy, allowPlatformIntrinsics: Boolean): AtomicShort = + def create( + initialValue: Short, + @unused padding: PaddingStrategy, + @unused allowPlatformIntrinsics: Boolean + ): AtomicShort = new AtomicShort(initialValue) /** $createDesc @@ -155,6 +161,6 @@ object AtomicShort { * @param initialValue is the initial value with which to initialize the atomic * @param padding is the [[PaddingStrategy]] to apply */ - def safe(initialValue: Short, padding: PaddingStrategy): AtomicShort = + def safe(initialValue: Short, @unused padding: PaddingStrategy): AtomicShort = new AtomicShort(initialValue) } diff --git a/monix-execution/js/src/main/scala/monix/execution/atomic/package.scala b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/package.scala similarity index 82% rename from monix-execution/js/src/main/scala/monix/execution/atomic/package.scala rename to monix-execution/atomic/js/src/main/scala/monix/execution/atomic/package.scala index 0ffd2d776..86d8a5813 100644 --- a/monix-execution/js/src/main/scala/monix/execution/atomic/package.scala +++ b/monix-execution/atomic/js/src/main/scala/monix/execution/atomic/package.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,10 +22,7 @@ package monix.execution * On top of the JVM, this means dealing with lock-free thread-safe programming. Also works on top of Javascript, * with Scala.js, for API compatibility purposes and because it's a useful way to box a value. * - * The backbone of Atomic references is this method: - * {{{ - * def compareAndSet(expect: T, update: T): Boolean - * }}} + * The backbone of Atomic references is [[Atomic.compareAndSet]]. * * This method atomically sets a variable to the `update` value if it currently holds * the `expect` value, reporting `true` on success or `false` on failure. The classes in this package @@ -35,14 +32,16 @@ package monix.execution * return the most specific type needed (in the following sample, that's an `AtomicDouble`, * inheriting from `AtomicNumber[A]`): * {{{ + * import monix.execution.atomic._ + * * val atomicNumber = Atomic(12.2) - * * atomicNumber.incrementAndGet() * // => 13.2 * }}} * * These also provide useful helpers for atomically mutating of values - * (i.e. `transform`, `transformAndGet`, `getAndTransform`, etc...) or of numbers of any kind - * (`incrementAndGet`, `getAndAdd`, etc...). + * (i.e. [[Atomic.transform]], [[Atomic.transformAndGet]], [[Atomic.transformAndExtract]], + * etc.) or of numbers of any kind ([[AtomicNumber.incrementAndGet]], + * [[AtomicNumber.getAndAdd]], etc.). */ package object atomic diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/BoxPaddingStrategy.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/BoxPaddingStrategy.java similarity index 84% rename from monix-execution/jvm/src/main/java/monix/execution/internal/atomic/BoxPaddingStrategy.java rename to monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/BoxPaddingStrategy.java index c51f0e17b..afb63a4fe 100644 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/BoxPaddingStrategy.java +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/BoxPaddingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,9 +15,7 @@ * limitations under the License. */ -package monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; +package monix.execution.atomic.internal; /** * INTERNAL API — used in the implementation of @@ -28,7 +26,7 @@ * because Java does not provide the capability of marking classes as * "internal" to a package and all its sub-packages. */ -@InternalApi public enum BoxPaddingStrategy { +public enum BoxPaddingStrategy { NO_PADDING, LEFT_64, RIGHT_64, LEFT_RIGHT_128, LEFT_128, RIGHT_128, LEFT_RIGHT_256 } diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/BoxedInt.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/BoxedInt.java similarity index 86% rename from monix-execution/jvm/src/main/java/monix/execution/internal/atomic/BoxedInt.java rename to monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/BoxedInt.java index d8c358d8e..956473a33 100644 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/BoxedInt.java +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/BoxedInt.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,9 +15,7 @@ * limitations under the License. */ -package monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; +package monix.execution.atomic.internal; /** * INTERNAL API — used in the implementation of @@ -28,7 +26,7 @@ * because Java does not provide the capability of marking classes as * "internal" to a package and all its sub-packages. */ -@InternalApi public interface BoxedInt { +public interface BoxedInt { int volatileGet(); void volatileSet(int update); void lazySet(int update); diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/BoxedLong.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/BoxedLong.java similarity index 86% rename from monix-execution/jvm/src/main/java/monix/execution/internal/atomic/BoxedLong.java rename to monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/BoxedLong.java index cb5bf3fb0..d5571d75a 100644 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/BoxedLong.java +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/BoxedLong.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,9 +15,7 @@ * limitations under the License. */ -package monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; +package monix.execution.atomic.internal; /** * INTERNAL API — used in the implementation of @@ -28,7 +26,7 @@ * because Java does not provide the capability of marking classes as * "internal" to a package and all its sub-packages. */ -@InternalApi public interface BoxedLong { +public interface BoxedLong { long volatileGet(); void volatileSet(long update); void lazySet(long update); diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/BoxedObject.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/BoxedObject.java similarity index 85% rename from monix-execution/jvm/src/main/java/monix/execution/internal/atomic/BoxedObject.java rename to monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/BoxedObject.java index 91b916657..f557abcb7 100644 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/BoxedObject.java +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/BoxedObject.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,9 +15,7 @@ * limitations under the License. */ -package monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; +package monix.execution.atomic.internal; /** * INTERNAL API — used in the implementation of @@ -28,7 +26,7 @@ * because Java does not provide the capability of marking classes as * "internal" to a package and all its sub-packages. */ -@InternalApi public interface BoxedObject { +public interface BoxedObject { Object volatileGet(); void volatileSet(Object update); void lazySet(Object update); diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Factory.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Factory.java new file mode 100644 index 000000000..a97290bc6 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Factory.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import scala.MatchError; + +/** + * INTERNAL API — used in the implementation of + * `monix.execution.atomic.Atomic`. + * + * Being internal it can always change between minor versions, + * providing no backwards compatibility guarantees and is only public + * because Java does not provide the capability of marking classes as + * "internal" to a package and all its sub-packages. + */ +public final class Factory { + public static BoxedObject newBoxedObject(Object initial, BoxPaddingStrategy padding, boolean allowUnsafe, boolean allowJava8Intrinsics) { + switch (padding) { + case NO_PADDING: + return new NormalJavaXBoxedObject(initial); + + case LEFT_64: + return new Left64JavaXBoxedObject(initial); + + case RIGHT_64: + return new Right64JavaXBoxedObject(initial); + + case LEFT_RIGHT_128: + return new LeftRight128JavaXBoxedObject(initial); + + case LEFT_128: + return new Left128JavaXBoxedObject(initial); + + case RIGHT_128: + return new Right128JavaXBoxedObject(initial); + + case LEFT_RIGHT_256: + return new LeftRight256JavaXBoxedObject(initial); + + default: + throw new MatchError(padding); + } + } + + public static BoxedInt newBoxedInt(int initial, BoxPaddingStrategy padding, boolean allowUnsafe, boolean allowJava8Intrinsics) { + switch (padding) { + case NO_PADDING: + return new NormalJavaXBoxedInt(initial); + + case LEFT_64: + return new Left64JavaXBoxedInt(initial); + + case RIGHT_64: + return new Right64JavaXBoxedInt(initial); + + case LEFT_RIGHT_128: + return new LeftRight128JavaXBoxedInt(initial); + + case LEFT_128: + return new Left128JavaXBoxedInt(initial); + + case RIGHT_128: + return new Right128JavaXBoxedInt(initial); + + case LEFT_RIGHT_256: + return new LeftRight256JavaXBoxedInt(initial); + + default: + throw new MatchError(padding); + } + } + + public static BoxedLong newBoxedLong(long initial, BoxPaddingStrategy padding, boolean allowUnsafe, boolean allowJava8Intrinsics) { + switch (padding) { + case NO_PADDING: + return new NormalJavaXBoxedLong(initial); + + case LEFT_64: + return new Left64JavaXBoxedLong(initial); + + case RIGHT_64: + return new Right64JavaXBoxedLong(initial); + + case LEFT_RIGHT_128: + return new LeftRight128JavaXBoxedLong(initial); + + case LEFT_128: + return new Left128JavaXBoxedLong(initial); + + case RIGHT_128: + return new Right128JavaXBoxedLong(initial); + + case LEFT_RIGHT_256: + return new LeftRight256JavaXBoxedLong(initial); + + default: + throw new MatchError(padding); + } + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Left128JavaXBoxedInt.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Left128JavaXBoxedInt.java new file mode 100644 index 000000000..5944a69b6 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Left128JavaXBoxedInt.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class Left128JavaXBoxedInt extends LeftPadding120 implements VarHandleBoxedInt { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(Left128JavaXBoxedInt.class, "value", int.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private int value; + + Left128JavaXBoxedInt(int initialValue) { + this.value = initialValue; + } + + public VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Left128JavaXBoxedLong.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Left128JavaXBoxedLong.java new file mode 100644 index 000000000..25a44b24f --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Left128JavaXBoxedLong.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class Left128JavaXBoxedLong extends LeftPadding120 implements VarHandleBoxedLong { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(Left128JavaXBoxedLong.class, "value", long.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private long value; + + Left128JavaXBoxedLong(long initialValue) { + this.value = initialValue; + } + + public VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Left128JavaXBoxedObject.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Left128JavaXBoxedObject.java new file mode 100644 index 000000000..c20dc8218 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Left128JavaXBoxedObject.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class Left128JavaXBoxedObject extends LeftPadding120 implements VarHandleBoxedObject { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(Left128JavaXBoxedObject.class, "value", Object.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private Object value; + + Left128JavaXBoxedObject(Object initialValue) { + this.value = initialValue; + } + + public VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Left64JavaXBoxedInt.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Left64JavaXBoxedInt.java new file mode 100644 index 000000000..0eba03d29 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Left64JavaXBoxedInt.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class Left64JavaXBoxedInt extends LeftPadding56 implements VarHandleBoxedInt { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(Left64JavaXBoxedInt.class, "value", int.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private int value; + + Left64JavaXBoxedInt(int initialValue) { + this.value = initialValue; + } + + public VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Left64JavaXBoxedLong.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Left64JavaXBoxedLong.java new file mode 100644 index 000000000..7851fe5d3 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Left64JavaXBoxedLong.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class Left64JavaXBoxedLong extends LeftPadding56 implements VarHandleBoxedLong { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(Left64JavaXBoxedLong.class, "value", long.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private long value; + + Left64JavaXBoxedLong(long initialValue) { + this.value = initialValue; + } + + public VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Left64JavaXBoxedObject.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Left64JavaXBoxedObject.java new file mode 100644 index 000000000..0dcd3576d --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Left64JavaXBoxedObject.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class Left64JavaXBoxedObject extends LeftPadding56 implements VarHandleBoxedObject { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(Left64JavaXBoxedObject.class, "value", Object.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private Object value; + + Left64JavaXBoxedObject(Object initialValue) { + this.value = initialValue; + } + + public VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftPadding120.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftPadding120.java similarity index 88% rename from monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftPadding120.java rename to monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftPadding120.java index 623ff561b..46a68c44e 100644 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftPadding120.java +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftPadding120.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,9 +15,7 @@ * limitations under the License. */ -package monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; +package monix.execution.atomic.internal; /** * INTERNAL API — used in the implementation of @@ -28,7 +26,6 @@ * because Java does not provide the capability of marking classes as * "internal" to a package and all its sub-packages. */ -@InternalApi abstract class LeftPadding120 { public volatile long p01, p02, p03, p04, p05, p06, p07, p08 = 7; public volatile long p09, p10, p11, p12, p13, p14, p15 = 8; diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftPadding56.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftPadding56.java similarity index 87% rename from monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftPadding56.java rename to monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftPadding56.java index a84fc320d..be839b0cf 100644 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftPadding56.java +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftPadding56.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,9 +15,7 @@ * limitations under the License. */ -package monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; +package monix.execution.atomic.internal; /** * INTERNAL API — used in the implementation of @@ -28,7 +26,6 @@ * because Java does not provide the capability of marking classes as * "internal" to a package and all its sub-packages. */ -@InternalApi abstract class LeftPadding56 { public volatile long p1, p2, p3, p4, p5, p6, p7 = 7; public long sum() { return p1 + p2 + p3 + p4 + p5 + p6 + p7; } diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftRight128JavaXBoxedInt.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftRight128JavaXBoxedInt.java new file mode 100644 index 000000000..9f4ceb6c2 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftRight128JavaXBoxedInt.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class LeftRight128JavaXBoxedInt extends LeftRight128JavaXBoxedIntImpl { + public volatile long r1, r2, r3, r4, r5, r6, r7, r8 = 11; + @Override public long sum() { + return p1 + p2 + p3 + p4 + p5 + p6 + p7 + + r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8; + } + + LeftRight128JavaXBoxedInt(int initialValue) { + super(initialValue); + } +} + +abstract class LeftRight128JavaXBoxedIntImpl extends LeftPadding56 implements VarHandleBoxedInt { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(LeftRight128JavaXBoxedIntImpl.class, "value", int.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private int value; + + LeftRight128JavaXBoxedIntImpl(int initialValue) { + this.value = initialValue; + } + + public final VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftRight128JavaXBoxedLong.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftRight128JavaXBoxedLong.java new file mode 100644 index 000000000..e408c89dd --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftRight128JavaXBoxedLong.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class LeftRight128JavaXBoxedLong extends LeftRight128JavaXBoxedLongImpl { + public volatile long r1, r2, r3, r4, r5, r6, r7, r8 = 11; + @Override public long sum() { + return p1 + p2 + p3 + p4 + p5 + p6 + p7 + + r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8; + } + + LeftRight128JavaXBoxedLong(long initialValue) { + super(initialValue); + } +} + +abstract class LeftRight128JavaXBoxedLongImpl extends LeftPadding56 implements VarHandleBoxedLong { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(LeftRight128JavaXBoxedLongImpl.class, "value", long.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private long value; + + LeftRight128JavaXBoxedLongImpl(long initialValue) { + this.value = initialValue; + } + + public final VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftRight128JavaXBoxedObject.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftRight128JavaXBoxedObject.java new file mode 100644 index 000000000..15d5841e3 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftRight128JavaXBoxedObject.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class LeftRight128JavaXBoxedObject extends LeftRight128JavaXBoxedObjectImpl { + public volatile long r1, r2, r3, r4, r5, r6, r7, r8 = 11; + @Override public long sum() { + return p1 + p2 + p3 + p4 + p5 + p6 + p7 + + r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8; + } + + LeftRight128JavaXBoxedObject(Object initialValue) { + super(initialValue); + } +} + +abstract class LeftRight128JavaXBoxedObjectImpl extends LeftPadding56 implements VarHandleBoxedObject { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(LeftRight128JavaXBoxedObjectImpl.class, "value", Object.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private Object value; + + LeftRight128JavaXBoxedObjectImpl(Object initialValue) { + this.value = initialValue; + } + + public final VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftRight256JavaXBoxedInt.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftRight256JavaXBoxedInt.java new file mode 100644 index 000000000..477a5c34d --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftRight256JavaXBoxedInt.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class LeftRight256JavaXBoxedInt extends LeftRight256JavaXBoxedIntImpl { + public volatile long r01, r02, r03, r04, r05, r06, r07, r08 = 7; + public volatile long r09, r10, r11, r12, r13, r14, r15, r16 = 8; + @Override public long sum() { + return + p01 + p02 + p03 + p04 + p05 + p06 + p07 + p08 + + p09 + p10 + p11 + p12 + p13 + p14 + p15 + + r01 + r02 + r03 + r04 + r05 + r06 + r07 + r08 + + r09 + r10 + r11 + r12 + r13 + r14 + r15 + r16; + } + + LeftRight256JavaXBoxedInt(int initialValue) { + super(initialValue); + } +} + +abstract class LeftRight256JavaXBoxedIntImpl extends LeftPadding120 implements VarHandleBoxedInt { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(LeftRight256JavaXBoxedIntImpl.class, "value", int.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private int value; + + LeftRight256JavaXBoxedIntImpl(int initialValue) { + this.value = initialValue; + } + + public final VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftRight256JavaXBoxedLong.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftRight256JavaXBoxedLong.java new file mode 100644 index 000000000..9b34c41c1 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftRight256JavaXBoxedLong.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class LeftRight256JavaXBoxedLong extends LeftRight256JavaXBoxedLongImpl { + public volatile long r01, r02, r03, r04, r05, r06, r07, r08 = 7; + public volatile long r09, r10, r11, r12, r13, r14, r15, r16 = 8; + @Override public long sum() { + return + p01 + p02 + p03 + p04 + p05 + p06 + p07 + p08 + + p09 + p10 + p11 + p12 + p13 + p14 + p15 + + r01 + r02 + r03 + r04 + r05 + r06 + r07 + r08 + + r09 + r10 + r11 + r12 + r13 + r14 + r15 + r16; + } + + LeftRight256JavaXBoxedLong(long initialValue) { + super(initialValue); + } +} + +abstract class LeftRight256JavaXBoxedLongImpl extends LeftPadding120 implements VarHandleBoxedLong { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(LeftRight256JavaXBoxedLongImpl.class, "value", long.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private long value; + + LeftRight256JavaXBoxedLongImpl(long initialValue) { + this.value = initialValue; + } + + public final VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftRight256JavaXBoxedObject.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftRight256JavaXBoxedObject.java new file mode 100644 index 000000000..5add612ed --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/LeftRight256JavaXBoxedObject.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class LeftRight256JavaXBoxedObject extends LeftRight256JavaXBoxedObjectImpl { + public volatile long r01, r02, r03, r04, r05, r06, r07, r08 = 7; + public volatile long r09, r10, r11, r12, r13, r14, r15, r16 = 8; + @Override public long sum() { + return + p01 + p02 + p03 + p04 + p05 + p06 + p07 + p08 + + p09 + p10 + p11 + p12 + p13 + p14 + p15 + + r01 + r02 + r03 + r04 + r05 + r06 + r07 + r08 + + r09 + r10 + r11 + r12 + r13 + r14 + r15 + r16; + } + + LeftRight256JavaXBoxedObject(Object initialValue) { + super(initialValue); + } +} + +abstract class LeftRight256JavaXBoxedObjectImpl extends LeftPadding120 implements VarHandleBoxedObject { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(LeftRight256JavaXBoxedObjectImpl.class, "value", Object.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private Object value; + + LeftRight256JavaXBoxedObjectImpl(Object initialValue) { + this.value = initialValue; + } + + public final VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/NormalJavaXBoxedInt.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/NormalJavaXBoxedInt.java new file mode 100644 index 000000000..240a34531 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/NormalJavaXBoxedInt.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class NormalJavaXBoxedInt implements VarHandleBoxedInt { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(NormalJavaXBoxedInt.class, "value", int.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private int value; + + NormalJavaXBoxedInt(int initialValue) { + this.value = initialValue; + } + + public VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/NormalJavaXBoxedLong.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/NormalJavaXBoxedLong.java new file mode 100644 index 000000000..764444135 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/NormalJavaXBoxedLong.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class NormalJavaXBoxedLong implements VarHandleBoxedLong { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(NormalJavaXBoxedLong.class, "value", long.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private long value; + + NormalJavaXBoxedLong(long initialValue) { + this.value = initialValue; + } + + public VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/NormalJavaXBoxedObject.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/NormalJavaXBoxedObject.java new file mode 100644 index 000000000..a918ebd02 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/NormalJavaXBoxedObject.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class NormalJavaXBoxedObject implements VarHandleBoxedObject { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(NormalJavaXBoxedObject.class, "value", Object.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private Object value; + + NormalJavaXBoxedObject(Object initialValue) { + this.value = initialValue; + } + + public VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Right128JavaXBoxedInt.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Right128JavaXBoxedInt.java new file mode 100644 index 000000000..b9d7407d6 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Right128JavaXBoxedInt.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class Right128JavaXBoxedInt extends Right128JavaXBoxedIntImpl { + public volatile long p1, p2, p3, p4, p5, p6, p7, p8 = 7; + public volatile long p9, p10, p11, p12, p13, p14, p15 = 7; + public long sum() { + return p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + + p9 + p10 + p11 + p12 + p13 + p14 + p15; + } + + Right128JavaXBoxedInt(int initialValue) { + super(initialValue); + } +} + +abstract class Right128JavaXBoxedIntImpl implements VarHandleBoxedInt { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(Right128JavaXBoxedIntImpl.class, "value", int.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private int value; + + Right128JavaXBoxedIntImpl(int initialValue) { + this.value = initialValue; + } + + public final VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Right128JavaXBoxedLong.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Right128JavaXBoxedLong.java new file mode 100644 index 000000000..4f3170dea --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Right128JavaXBoxedLong.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class Right128JavaXBoxedLong extends Right128JavaXBoxedLongImpl { + public volatile long p1, p2, p3, p4, p5, p6, p7, p8 = 7; + public volatile long p9, p10, p11, p12, p13, p14, p15 = 7; + public long sum() { + return p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + + p9 + p10 + p11 + p12 + p13 + p14 + p15; + } + + Right128JavaXBoxedLong(long initialValue) { + super(initialValue); + } +} + +abstract class Right128JavaXBoxedLongImpl implements VarHandleBoxedLong { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(Right128JavaXBoxedLongImpl.class, "value", long.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private long value; + + Right128JavaXBoxedLongImpl(long initialValue) { + this.value = initialValue; + } + + public final VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Right128JavaXBoxedObject.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Right128JavaXBoxedObject.java new file mode 100644 index 000000000..e6051bd75 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Right128JavaXBoxedObject.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class Right128JavaXBoxedObject extends Right128JavaXBoxedObjectImpl { + public volatile long p1, p2, p3, p4, p5, p6, p7, p8 = 7; + public volatile long p9, p10, p11, p12, p13, p14, p15 = 7; + public long sum() { + return p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + + p9 + p10 + p11 + p12 + p13 + p14 + p15; + } + + Right128JavaXBoxedObject(Object initialValue) { + super(initialValue); + } +} + +abstract class Right128JavaXBoxedObjectImpl implements VarHandleBoxedObject { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(Right128JavaXBoxedObjectImpl.class, "value", Object.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private Object value; + + Right128JavaXBoxedObjectImpl(Object initialValue) { + this.value = initialValue; + } + + public final VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Right64JavaXBoxedInt.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Right64JavaXBoxedInt.java new file mode 100644 index 000000000..011920957 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Right64JavaXBoxedInt.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class Right64JavaXBoxedInt extends Right64JavaXBoxedIntImpl { + public volatile long p1, p2, p3, p4, p5, p6, p7 = 7; + public long sum() { return p1 + p2 + p3 + p4 + p5 + p6 + p7; } + + Right64JavaXBoxedInt(int initialValue) { + super(initialValue); + } +} + +abstract class Right64JavaXBoxedIntImpl implements VarHandleBoxedInt { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(Right64JavaXBoxedIntImpl.class, "value", int.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private int value; + + Right64JavaXBoxedIntImpl(int initialValue) { + this.value = initialValue; + } + + public final VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Right64JavaXBoxedLong.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Right64JavaXBoxedLong.java new file mode 100644 index 000000000..c59a4cae8 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Right64JavaXBoxedLong.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class Right64JavaXBoxedLong extends Right64JavaXBoxedLongImpl { + public volatile long p1, p2, p3, p4, p5, p6, p7 = 7; + public long sum() { return p1 + p2 + p3 + p4 + p5 + p6 + p7; } + + Right64JavaXBoxedLong(long initialValue) { + super(initialValue); + } +} + +abstract class Right64JavaXBoxedLongImpl implements VarHandleBoxedLong { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(Right64JavaXBoxedLongImpl.class, "value", long.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private long value; + + Right64JavaXBoxedLongImpl(long initialValue) { + this.value = initialValue; + } + + public final VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Right64JavaXBoxedObject.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Right64JavaXBoxedObject.java new file mode 100644 index 000000000..c1893d357 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/Right64JavaXBoxedObject.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; + +final class Right64JavaXBoxedObject extends Right64JavaXBoxedObjectImpl { + public volatile long p1, p2, p3, p4, p5, p6, p7 = 7; + public long sum() { return p1 + p2 + p3 + p4 + p5 + p6 + p7; } + + Right64JavaXBoxedObject(Object initialValue) { + super(initialValue); + } +} + +abstract class Right64JavaXBoxedObjectImpl implements VarHandleBoxedObject { + private static final VarHandle VALUE_VH; + + static { + try { + VALUE_VH = MethodHandles.lookup().findVarHandle(Right64JavaXBoxedObjectImpl.class, "value", Object.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new AssertionError(e); + } + } + + private Object value; + + Right64JavaXBoxedObjectImpl(Object initialValue) { + this.value = initialValue; + } + + public final VarHandle valueHandle() { + return VALUE_VH; + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/UnsafeAccess.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/UnsafeAccess.java new file mode 100644 index 000000000..f57ea6f32 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/UnsafeAccess.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +public final class UnsafeAccess { + public static final boolean IS_AVAILABLE = false; + public static final boolean IS_ALLOWED = false; + public static final boolean HAS_JAVA8_INTRINSICS = false; + public static final boolean IS_OPENJDK_COMPATIBLE = false; + + public static Object getInstance() { + throw new UnsupportedOperationException( + "Legacy unsafe access is not used by monix.execution.atomic.internal on JDK 17+" + ); + } + + private UnsafeAccess() {} +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/VarHandleBoxedInt.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/VarHandleBoxedInt.java new file mode 100644 index 000000000..3ec6f68dd --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/VarHandleBoxedInt.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.VarHandle; + +interface VarHandleBoxedInt extends BoxedInt { + VarHandle valueHandle(); + + @Override + default int volatileGet() { + return (int) valueHandle().getVolatile(this); + } + + @Override + default void volatileSet(int update) { + valueHandle().setVolatile(this, update); + } + + @Override + default void lazySet(int update) { + valueHandle().setRelease(this, update); + } + + @Override + default boolean compareAndSet(int current, int update) { + return valueHandle().compareAndSet(this, current, update); + } + + @Override + default int getAndAdd(int delta) { + return (int) valueHandle().getAndAdd(this, delta); + } + + @Override + default int getAndSet(int update) { + return (int) valueHandle().getAndSet(this, update); + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/VarHandleBoxedLong.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/VarHandleBoxedLong.java new file mode 100644 index 000000000..3390dcab6 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/VarHandleBoxedLong.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.VarHandle; + +interface VarHandleBoxedLong extends BoxedLong { + VarHandle valueHandle(); + + @Override + default long volatileGet() { + return (long) valueHandle().getVolatile(this); + } + + @Override + default void volatileSet(long update) { + valueHandle().setVolatile(this, update); + } + + @Override + default void lazySet(long update) { + valueHandle().setRelease(this, update); + } + + @Override + default boolean compareAndSet(long current, long update) { + return valueHandle().compareAndSet(this, current, update); + } + + @Override + default long getAndSet(long update) { + return (long) valueHandle().getAndSet(this, update); + } + + @Override + default long getAndAdd(long delta) { + return (long) valueHandle().getAndAdd(this, delta); + } +} diff --git a/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/VarHandleBoxedObject.java b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/VarHandleBoxedObject.java new file mode 100644 index 000000000..030107f63 --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/java/monix/execution/atomic/internal/VarHandleBoxedObject.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic.internal; + +import java.lang.invoke.VarHandle; + +interface VarHandleBoxedObject extends BoxedObject { + VarHandle valueHandle(); + + @Override + default Object volatileGet() { + return valueHandle().getVolatile(this); + } + + @Override + default void volatileSet(Object update) { + valueHandle().setVolatile(this, update); + } + + @Override + default void lazySet(Object update) { + valueHandle().setRelease(this, update); + } + + @Override + default boolean compareAndSet(Object current, Object update) { + return valueHandle().compareAndSet(this, current, update); + } + + @Override + default Object getAndSet(Object update) { + return valueHandle().getAndSet(this, update); + } +} diff --git a/monix-execution/jvm/src/main/scala_3.0-/monix/execution/atomic/Atomic.scala b/monix-execution/atomic/jvm/src/main/scala-2/monix/execution/atomic/Atomic.scala similarity index 55% rename from monix-execution/jvm/src/main/scala_3.0-/monix/execution/atomic/Atomic.scala rename to monix-execution/atomic/jvm/src/main/scala-2/monix/execution/atomic/Atomic.scala index 62a3a07d7..b784838fd 100644 --- a/monix-execution/jvm/src/main/scala_3.0-/monix/execution/atomic/Atomic.scala +++ b/monix-execution/atomic/jvm/src/main/scala-2/monix/execution/atomic/Atomic.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,109 +18,79 @@ package monix.execution.atomic import monix.execution.atomic.PaddingStrategy.NoPadding -import monix.execution.misc._ - +import monix.execution.atomic.internal._ import scala.reflect.macros.whitebox +import scala.annotation.unused /** * Base trait of all atomic references, no matter the type. */ -abstract class Atomic[A] extends Serializable { - /** Get the current value persisted by this Atomic. */ +abstract class Atomic[A] extends Serializable with internal.AtomicDocs { + /** $atomicGetDesc */ def get(): A - /** Get the current value persisted by this Atomic, an alias for `get()`. */ - final def apply(): A = macro Atomic.Macros.applyMacro[A] - - /** Updates the current value. - * - * @param update will be the new value returned by `get()` - */ + /** $atomicSetDesc */ def set(update: A): Unit - /** Alias for [[set]]. Updates the current value. - * - * @param value will be the new value returned by `get()` - */ - final def update(value: A): Unit = macro Atomic.Macros.setMacro[A] - - /** Alias for [[set]]. Updates the current value. + /** $compareAndSetDesc + * + * $atomicBestPractices * - * @param value will be the new value returned by `get()` - */ - final def `:=`(value: A): Unit = macro Atomic.Macros.setMacro[A] - - /** Does a compare-and-set operation on the current value. For more info, checkout the related - * [[https://en.wikipedia.org/wiki/Compare-and-swap Compare-and-swap Wikipedia page]]. - * - * It's an atomic, worry free operation. - * - * @param expect is the value you expect to be persisted when the operation happens - * @param update will be the new value, should the check for `expect` succeeds - * @return either true in case the operation succeeded or false otherwise + * @param expect $atomicCASExpectParam + * @param update $atomicCASUpdateParam + * @return $atomicCASReturn $atomicCASReturn */ def compareAndSet(expect: A, update: A): Boolean - /** Sets the persisted value to `update` and returns the old value that was in place. - * It's an atomic, worry free operation. + /** $atomicGetAndSetDesc + * + * @param update $atomicGetAndSetParam + * @return $atomicGetAndSetReturn */ def getAndSet(update: A): A - /** Eventually sets to the given value. - * Has weaker visibility guarantees than the normal `set()`. - */ + /** $atomicLazySetDesc */ def lazySet(update: A): Unit - /** Abstracts over `compareAndSet`. You specify a transformation by specifying a callback to be - * executed, a callback that transforms the current value. This method will loop until it will - * succeed in replacing the current value with the one produced by your callback. + /** $atomicTransformExtractDesc * - * Note that the callback will be executed on each iteration of the loop, so it can be called - * multiple times - don't do destructive I/O or operations that mutate global state in it. + * $atomicTransformBestPractices * - * @param cb is a callback that receives the current value as input and returns a tuple that specifies - * the update + what should this method return when the operation succeeds. - * @return whatever was specified by your callback, once the operation succeeds + * @param f $atomicTransformExtractParamF + * + * @return $atomicTransformExtractReturn */ - def transformAndExtract[U](cb: (A) => (U, A)): U = macro Atomic.Macros.transformAndExtractMacro[A, U] + def transformAndExtract[U](f: (A) => (U, A)): U = + macro Atomic.Macros.transformAndExtractMacro[A, U] - /** Abstracts over `compareAndSet`. You specify a transformation by specifying a callback to be - * executed, a callback that transforms the current value. This method will loop until it will - * succeed in replacing the current value with the one produced by the given callback. + /** $atomicTransformAndGetDesc * - * Note that the callback will be executed on each iteration of the loop, so it can be called - * multiple times - don't do destructive I/O or operations that mutate global state in it. + * $atomicTransformBestPractices * - * @param cb is a callback that receives the current value as input and returns the `update` which is the - * new value that should be persisted - * @return whatever the update is, after the operation succeeds + * @param f $atomicTransformParam + * + * @return $atomicTransformAndGetReturn */ - def transformAndGet(cb: (A) => A): A = macro Atomic.Macros.transformAndGetMacro[A] + def transformAndGet(f: A => A): A = + macro Atomic.Macros.transformAndGetMacro[A] - /** Abstracts over `compareAndSet`. You specify a transformation by specifying a callback to be - * executed, a callback that transforms the current value. This method will loop until it will - * succeed in replacing the current value with the one produced by the given callback. - * - * Note that the callback will be executed on each iteration of the loop, so it can be called - * multiple times - don't do destructive I/O or operations that mutate global state in it. + /** $atomicGetAndTransformDesc * - * @param cb is a callback that receives the current value as input and returns the `update` which is the - * new value that should be persisted - * @return the old value, just prior to when the successful update happened + * @param f $atomicTransformParam + * + * @return $atomicGetAndTransformReturn */ - final def getAndTransform(cb: (A) => A): A = macro Atomic.Macros.getAndTransformMacro[A] + final def getAndTransform(f: A => A): A = + macro Atomic.Macros.getAndTransformMacro[A] - /** Abstracts over `compareAndSet`. You specify a transformation by specifying a callback to be - * executed, a callback that transforms the current value. This method will loop until it will - * succeed in replacing the current value with the one produced by the given callback. + /** $atomicTransformDesc * - * Note that the callback will be executed on each iteration of the loop, so it can be called - * multiple times - don't do destructive I/O or operations that mutate global state in it. - * - * @param cb is a callback that receives the current value as input and returns the `update` which is the - * new value that should be persisted + * $atomicTransformBestPractices + * + * @param f $atomicTransformParam */ - final def transform(cb: (A) => A): Unit = macro Atomic.Macros.transformMacro[A] + final def transform(f: A => A): Unit = + macro Atomic.Macros.transformMacro[A] } object Atomic { @@ -138,7 +108,8 @@ object Atomic { * @param builder is the builder that helps us to build the * best reference possible, based on our `initialValue` */ - def apply[A, R <: Atomic[A]](initialValue: A)(implicit builder: AtomicBuilder[A, R]): R = macro Atomic.Macros.buildAnyMacro[A, R] + def apply[A, R <: Atomic[A]](initialValue: A)(implicit builder: AtomicBuilder[A, R]): R = + macro Atomic.Macros.buildAnyMacro[A, R] /** Constructs an `Atomic[A]` reference, applying the provided * [[PaddingStrategy]] in order to counter the "false sharing" @@ -164,20 +135,49 @@ object Atomic { * @param builder is the builder that helps us to build the * best reference possible, based on our `initialValue` */ - def withPadding[A, R <: Atomic[A]](initialValue: A, padding: PaddingStrategy)( - implicit builder: AtomicBuilder[A, R]): R = macro Atomic.Macros.buildAnyWithPaddingMacro[A, R] + def withPadding[A, R <: Atomic[A]](initialValue: A, padding: PaddingStrategy)(implicit + builder: AtomicBuilder[A, R] + ): R = macro Atomic.Macros.buildAnyWithPaddingMacro[A, R] /** Returns the builder that would be chosen to construct Atomic * references for the given `initialValue`. */ - def builderFor[A, R <: Atomic[A]](initialValue: A)(implicit builder: AtomicBuilder[A, R]): AtomicBuilder[A, R] = + def builderFor[A, R <: Atomic[A]](@unused initialValue: A)(implicit + builder: AtomicBuilder[A, R] + ): AtomicBuilder[A, R] = builder + implicit final class DeprecatedExtensions[A](val self: Atomic[A]) extends AnyVal { + /** DEPRECATED - switch to [[Atomic.get]]. */ + @deprecated("Switch to .get()", "4.0.0") + def apply(): A = { + // $COVERAGE-OFF$ + self.get() + // $COVERAGE-ON$ + } + + /** DEPRECATED — switch to [[Atomic.set]]. */ + @deprecated("Switch to .set()", "4.0.0") + def update(value: A): Unit = { + // $COVERAGE-OFF$ + self.set(value) + // $COVERAGE-ON$ + } + + /** DEPRECATED — switch to [[Atomic.set]]. */ + @deprecated("Switch to .set()", "4.0.0") + def `:=`(value: A): Unit = { + // $COVERAGE-OFF$ + self.set(value) + // $COVERAGE-ON$ + } + } + /** Macros implementations for the [[Atomic]] type */ class Macros(override val c: whitebox.Context) extends HygieneUtilMacros with InlineMacros { import c.universe._ - def transformMacro[A: c.WeakTypeTag](cb: c.Expr[A => A]): c.Expr[Unit] = { + def transformMacro[A](f: c.Expr[A => A]): c.Expr[Unit] = { val selfExpr = c.Expr[Atomic[A]](c.prefix.tree) val self = util.name("self") val current = util.name("current") @@ -187,22 +187,22 @@ object Atomic { * then inline them directly, otherwise bind arguments to a val for safety. */ val tree = - if (util.isClean(cb)) { + if (util.isClean(f)) { q""" val $self = $selfExpr var $current = $self.get() - var $update = $cb($current) + var $update = $f($current) while (!$self.compareAndSet($current, $update)) { $current = $self.get() - $update = $cb($current) + $update = $f($current) } """ } else { val fn = util.name("fn") q""" val $self = $selfExpr - val $fn = $cb + val $fn = $f var $current = $self.get() var $update = $fn($current) @@ -217,7 +217,7 @@ object Atomic { inlineAndReset[Unit](tree) } - def transformAndGetMacro[A: c.WeakTypeTag](cb: c.Expr[A => A]): c.Expr[A] = { + def transformAndGetMacro[A](f: c.Expr[A => A]): c.Expr[A] = { val selfExpr = c.Expr[Atomic[A]](c.prefix.tree) val self = util.name("self") val current = util.name("current") @@ -227,15 +227,15 @@ object Atomic { * then inline them directly, otherwise bind arguments to a val for safety. */ val tree = - if (util.isClean(cb)) { + if (util.isClean(f)) { q""" val $self = $selfExpr var $current = $self.get() - var $update = $cb($current) + var $update = $f($current) while (!$self.compareAndSet($current, $update)) { $current = $self.get() - $update = $cb($current) + $update = $f($current) } $update @@ -244,7 +244,7 @@ object Atomic { val fn = util.name("fn") q""" val $self = $selfExpr - val $fn = $cb + val $fn = $f var $current = $self.get() var $update = $fn($current) @@ -260,7 +260,7 @@ object Atomic { inlineAndReset[A](tree) } - def getAndTransformMacro[A: c.WeakTypeTag](cb: c.Expr[A => A]): c.Expr[A] = { + def getAndTransformMacro[A](f: c.Expr[A => A]): c.Expr[A] = { val selfExpr = c.Expr[Atomic[A]](c.prefix.tree) val self = util.name("self") val current = util.name("current") @@ -270,15 +270,15 @@ object Atomic { * then inline them directly, otherwise bind arguments to a val for safety. */ val tree = - if (util.isClean(cb)) { + if (util.isClean(f)) { q""" val $self = $selfExpr var $current = $self.get() - var $update = $cb($current) + var $update = $f($current) while (!$self.compareAndSet($current, $update)) { $current = $self.get() - $update = $cb($current) + $update = $f($current) } $current @@ -287,7 +287,7 @@ object Atomic { val fn = util.name("fn") q""" val $self = $selfExpr - val $fn = $cb + val $fn = $f var $current = $self.get() var $update = $fn($current) @@ -303,8 +303,9 @@ object Atomic { inlineAndReset[A](tree) } - def transformAndExtractMacro[S: c.WeakTypeTag, A: c.WeakTypeTag](cb: c.Expr[S => (A, S)]): c.Expr[A] = { - + def transformAndExtractMacro[S, A]( + f: c.Expr[S => (A, S)] + ): c.Expr[A] = { val selfExpr = c.Expr[Atomic[S]](c.prefix.tree) val self = util.name("self") val current = util.name("current") @@ -317,15 +318,15 @@ object Atomic { * then inline them directly, otherwise bind arguments to a val for safety. */ val tree = - if (util.isClean(cb)) { + if (util.isClean(f)) { q""" val $self = $selfExpr var $current = $self.get() - var ($resultVar, $updateVar) = $cb($current) + var ($resultVar, $updateVar) = $f($current) while (!$self.compareAndSet($current, $updateVar)) { $current = $self.get() - val ($resultTmp, $updateTmp) = $cb($current) + val ($resultTmp, $updateTmp) = $f($current) $updateVar = $updateTmp $resultVar = $resultTmp } @@ -336,7 +337,7 @@ object Atomic { val fn = util.name("fn") q""" val $self = $selfExpr - val $fn = $cb + val $fn = $f var $current = $self.get() var ($resultVar, $updateVar) = $fn($current) @@ -355,46 +356,48 @@ object Atomic { inlineAndReset[A](tree) } - def buildAnyMacro[A: c.WeakTypeTag, R <: Atomic[A]: c.WeakTypeTag](initialValue: c.Expr[A])( - builder: c.Expr[AtomicBuilder[A, R]]): c.Expr[R] = { - + def buildAnyMacro[A, R <: Atomic[A]](initialValue: c.Expr[A])( + builder: c.Expr[AtomicBuilder[A, R]] + ): c.Expr[R] = { val expr = reify { - builder.splice.buildInstance(initialValue.splice, NoPadding, allowPlatformIntrinsics = true) + builder.splice.buildInstance( + initialValue.splice, + NoPadding, + allowPlatformIntrinsics = true + ) } - inlineAndReset[R](expr.tree) } - def buildAnyWithPaddingMacro[A: c.WeakTypeTag, R <: Atomic[A]: c.WeakTypeTag]( + def buildAnyWithPaddingMacro[A, R <: Atomic[A]]( initialValue: c.Expr[A], - padding: c.Expr[PaddingStrategy])(builder: c.Expr[AtomicBuilder[A, R]]): c.Expr[R] = { - + padding: c.Expr[PaddingStrategy] + )(builder: c.Expr[AtomicBuilder[A, R]]): c.Expr[R] = { val expr = reify { builder.splice.buildInstance(initialValue.splice, padding.splice, allowPlatformIntrinsics = true) } - inlineAndReset[R](expr.tree) } - def applyMacro[A: c.WeakTypeTag](): c.Expr[A] = { + def applyMacro[A](): c.Expr[A] = { val selfExpr = c.Expr[Atomic[A]](c.prefix.tree) val tree = q"""$selfExpr.get()""" inlineAndReset[A](tree) } - def setMacro[A: c.WeakTypeTag](value: c.Expr[A]): c.Expr[Unit] = { + def setMacro[A](value: c.Expr[A]): c.Expr[Unit] = { val selfExpr = c.Expr[Atomic[A]](c.prefix.tree) val tree = q"""$selfExpr.set($value)""" inlineAndReset[Unit](tree) } - def addMacro[A: c.WeakTypeTag](value: c.Expr[A]): c.Expr[Unit] = { + def addMacro[A](value: c.Expr[A]): c.Expr[Unit] = { val selfExpr = c.Expr[Atomic[A]](c.prefix.tree) val tree = q"""$selfExpr.add($value)""" inlineAndReset[Unit](tree) } - def subtractMacro[A: c.WeakTypeTag](value: c.Expr[A]): c.Expr[Unit] = { + def subtractMacro[A](value: c.Expr[A]): c.Expr[Unit] = { val selfExpr = c.Expr[Atomic[A]](c.prefix.tree) val tree = q"""$selfExpr.subtract($value)""" inlineAndReset[Unit](tree) diff --git a/monix-execution/js/src/main/scala_3.0-/monix/execution/atomic/AtomicNumber.scala b/monix-execution/atomic/jvm/src/main/scala-2/monix/execution/atomic/AtomicNumber.scala similarity index 97% rename from monix-execution/js/src/main/scala_3.0-/monix/execution/atomic/AtomicNumber.scala rename to monix-execution/atomic/jvm/src/main/scala-2/monix/execution/atomic/AtomicNumber.scala index ed966dff2..7cbeaaacf 100644 --- a/monix-execution/js/src/main/scala_3.0-/monix/execution/atomic/AtomicNumber.scala +++ b/monix-execution/atomic/jvm/src/main/scala-2/monix/execution/atomic/AtomicNumber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -53,4 +53,4 @@ abstract class AtomicNumber[A] extends Atomic[A] { def getAndDecrement(v: Int = 1): A /** Subtracts from the atomic number and returns the value before the update. */ def getAndSubtract(v: A): A -} \ No newline at end of file +} diff --git a/monix-execution/atomic/jvm/src/main/scala-3/monix/execution/atomic/Atomic.scala b/monix-execution/atomic/jvm/src/main/scala-3/monix/execution/atomic/Atomic.scala new file mode 100644 index 000000000..f69389cfe --- /dev/null +++ b/monix-execution/atomic/jvm/src/main/scala-3/monix/execution/atomic/Atomic.scala @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic + +/** + * Base trait of all atomic references, no matter the type. + */ +abstract class Atomic[A] extends Serializable with internal.AtomicDocs { + /** $atomicGetDesc */ + def get(): A + + /** $atomicSetDesc */ + def set(update: A): Unit + + /** $compareAndSetDesc + * + * $atomicBestPractices + * + * @param expect $atomicCASExpectParam + * @param update $atomicCASUpdateParam + * @return $atomicCASReturn $atomicCASReturn + */ + def compareAndSet(expect: A, update: A): Boolean + + /** $atomicGetAndSetDesc + * + * @param update $atomicGetAndSetParam + * @return $atomicGetAndSetReturn + */ + def getAndSet(update: A): A + + /** $atomicLazySetDesc */ + def lazySet(update: A): Unit + + /** $atomicTransformExtractDesc + * + * $atomicTransformBestPractices + * + * @param f $atomicTransformExtractParamF + * + * @return $atomicTransformExtractReturn + */ + inline final def transformAndExtract[U](inline f: A => (U, A)): U = { + var current = get() + var result = null.asInstanceOf[U] + var continue = true + + while (continue) { + val (resultTmp, update) = f(current) + if (compareAndSet(current, update)) { + result = resultTmp + continue = false + } else { + current = get() + } + } + result + } + + /** $atomicTransformAndGetDesc + * + * $atomicTransformBestPractices + * + * @param f $atomicTransformParam + * + * @return $atomicTransformAndGetReturn + */ + inline final def transformAndGet(inline cb: (A) => A): A = { + var current = get() + var update = null.asInstanceOf[A] + var continue = true + + while (continue) { + update = cb(current) + if (compareAndSet(current, update)) + continue = false + else + current = get() + } + update + } + + /** $atomicGetAndTransformDesc + * + * $atomicTransformBestPractices + * + * @param f $atomicTransformParam + * + * @return $atomicGetAndTransformReturn + */ + inline final def getAndTransform(inline f: A => A): A = { + var current = get() + var continue = true + + while (continue) { + val update = f(current) + if (compareAndSet(current, update)) + continue = false + else + current = get() + } + current + } + + /** $atomicTransformDesc + * + * $atomicTransformBestPractices + * + * @param f $atomicTransformParam + */ + inline final def transform(inline f: A => A): Unit = { + var continue = true + + while (continue) { + val current = get() + val update = f(current) + continue = !compareAndSet(current, update) + } + } +} + +object Atomic { + /** Constructs an `Atomic[A]` reference. + * + * Based on the `initialValue`, it will return the best, most + * specific type. E.g. you give it a number, it will return + * something inheriting from `AtomicNumber[A]`. That's why it takes + * an `AtomicBuilder[T, R]` as an implicit parameter - but worry + * not about such details as it just works. + * + * @param initialValue is the initial value with which to + * initialize the Atomic reference + * + * @param builder is the builder that helps us to build the + * best reference possible, based on our `initialValue` + */ + inline def apply[A, R <: Atomic[A]](initialValue: A)(implicit builder: AtomicBuilder[A, R]): R = + builder.buildInstance(initialValue, PaddingStrategy.NoPadding, allowPlatformIntrinsics = true) + + /** Constructs an `Atomic[A]` reference, applying the provided + * [[PaddingStrategy]] in order to counter the "false sharing" + * problem. + * + * Based on the `initialValue`, it will return the best, most + * specific type. E.g. you give it a number, it will return + * something inheriting from `AtomicNumber[A]`. That's why it takes + * an `AtomicBuilder[A, R]` as an implicit parameter - but worry + * not about such details as it just works. + * + * Note that for ''Scala.js'' we aren't applying any padding, as it + * doesn't make much sense, since Javascript execution is single + * threaded, but this builder is provided for syntax compatibility + * anyway across the JVM and Javascript and we never know how + * Javascript engines will evolve. + * + * @param initialValue is the initial value with which to + * initialize the Atomic reference + * + * @param padding is the [[PaddingStrategy]] to apply + * + * @param builder is the builder that helps us to build the + * best reference possible, based on our `initialValue` + */ + inline def withPadding[A, R <: Atomic[A]](initialValue: A, padding: PaddingStrategy)(implicit + builder: AtomicBuilder[A, R] + ): R = + builder.buildInstance(initialValue, padding, allowPlatformIntrinsics = true) + + /** Returns the builder that would be chosen to construct Atomic + * references for the given `initialValue`. + */ + def builderFor[A, R <: Atomic[A]](initialValue: A)(implicit builder: AtomicBuilder[A, R]): AtomicBuilder[A, R] = { + val _ = initialValue + builder + } + + extension [A](self: Atomic[A]) { + /** DEPRECATED - switch to [[Atomic.get]]. */ + @deprecated("Switch to .get()", "4.0.0") + def apply(): A = { + // $COVERAGE-OFF$ + self.get() + // $COVERAGE-ON$ + } + + /** DEPRECATED — switch to [[Atomic.set]]. */ + @deprecated("Switch to .set()", "4.0.0") + def update(value: A): Unit = { + // $COVERAGE-OFF$ + self.set(value) + // $COVERAGE-ON$ + } + + /** DEPRECATED — switch to [[Atomic.set]]. */ + @deprecated("Switch to .set()", "4.0.0") + def `:=`(value: A): Unit = { + // $COVERAGE-OFF$ + self.set(value) + // $COVERAGE-ON$ + } + } +} diff --git a/monix-execution/jvm/src/main/scala_3.0/monix/execution/atomic/AtomicNumber.scala b/monix-execution/atomic/jvm/src/main/scala-3/monix/execution/atomic/AtomicNumber.scala similarity index 97% rename from monix-execution/jvm/src/main/scala_3.0/monix/execution/atomic/AtomicNumber.scala rename to monix-execution/atomic/jvm/src/main/scala-3/monix/execution/atomic/AtomicNumber.scala index 60040a1c7..bc5d20fd4 100644 --- a/monix-execution/jvm/src/main/scala_3.0/monix/execution/atomic/AtomicNumber.scala +++ b/monix-execution/atomic/jvm/src/main/scala-3/monix/execution/atomic/AtomicNumber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicAny.scala b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicAny.scala similarity index 94% rename from monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicAny.scala rename to monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicAny.scala index 316a4c211..e25b041be 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicAny.scala +++ b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicAny.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,14 +18,14 @@ package monix.execution.atomic import monix.execution.atomic.PaddingStrategy.NoPadding -import monix.execution.internal.atomic.{BoxedObject, Factory} +import monix.execution.atomic.internal.{ BoxedObject, Factory } /** Atomic references wrapping `AnyRef` values. * * @tparam A is forced to be an `AnyRef` because the equality test is * by reference and not by value. */ -final class AtomicAny[A <: AnyRef] private (private[this] val ref: BoxedObject) extends Atomic[A] { +final class AtomicAny[A <: AnyRef] private (private val ref: BoxedObject) extends Atomic[A] { def get(): A = ref.volatileGet().asInstanceOf[A] def set(update: A): Unit = ref.volatileSet(update) @@ -86,7 +86,8 @@ object AtomicAny { boxStrategyToPaddingStrategy(padding), true, // allowUnsafe allowPlatformIntrinsics - )) + ) + ) } /** $createDesc @@ -111,5 +112,6 @@ object AtomicAny { boxStrategyToPaddingStrategy(padding), false, // allowUnsafe false // allowPlatformIntrinsics - )) + ) + ) } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicBoolean.scala b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicBoolean.scala similarity index 94% rename from monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicBoolean.scala rename to monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicBoolean.scala index a628b8d52..9646f569a 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicBoolean.scala +++ b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicBoolean.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,14 +18,14 @@ package monix.execution.atomic import monix.execution.atomic.PaddingStrategy.NoPadding -import monix.execution.internal.atomic.{BoxedInt, Factory} +import monix.execution.atomic.internal.{ BoxedInt, Factory } /** Atomic references wrapping `Boolean` values. * * Note that the equality test in `compareAndSet` is value based, * since `Boolean` is a primitive. */ -final class AtomicBoolean private (private[this] val ref: BoxedInt) extends Atomic[Boolean] { +final class AtomicBoolean private (private val ref: BoxedInt) extends Atomic[Boolean] { def get(): Boolean = ref.volatileGet() == 1 @@ -97,7 +97,9 @@ object AtomicBoolean { if (initialValue) 1 else 0, boxStrategyToPaddingStrategy(padding), true, // allowUnsafe - allowPlatformIntrinsics)) + allowPlatformIntrinsics + ) + ) } /** $createDesc @@ -122,6 +124,7 @@ object AtomicBoolean { boxStrategyToPaddingStrategy(padding), false, // allowUnsafe false // allowJava8Intrinsics - )) + ) + ) } } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicBuilder.scala b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicBuilder.scala similarity index 97% rename from monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicBuilder.scala rename to monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicBuilder.scala index 7a580eb58..aabaf7948 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicBuilder.scala +++ b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicBuilder.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -47,10 +47,10 @@ private[atomic] object Implicits { implicit def AtomicNumberBuilder[A <: AnyRef: Numeric]: AtomicBuilder[A, AtomicNumberAny[A]] = new AtomicBuilder[A, AtomicNumberAny[A]] { def buildInstance(initialValue: A, padding: PaddingStrategy, allowPlatformIntrinsics: Boolean) = - AtomicNumberAny.create(initialValue, padding, allowPlatformIntrinsics)(implicitly[Numeric[A]]) + AtomicNumberAny.create(initialValue, padding, allowPlatformIntrinsics) def buildSafeInstance(initialValue: A, padding: PaddingStrategy) = - AtomicNumberAny.safe(initialValue, padding)(implicitly[Numeric[A]]) + AtomicNumberAny.safe(initialValue, padding) } } } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicByte.scala b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicByte.scala similarity index 94% rename from monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicByte.scala rename to monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicByte.scala index 736282763..e1f003143 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicByte.scala +++ b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicByte.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,21 +18,21 @@ package monix.execution.atomic import monix.execution.atomic.PaddingStrategy.NoPadding -import monix.execution.internal.atomic.{BoxedInt, Factory} +import monix.execution.atomic.internal.{ BoxedInt, Factory } /** Atomic references wrapping `Byte` values. * * Note that the equality test in `compareAndSet` is value based, * since `Byte` is a primitive. */ -final class AtomicByte private (private[this] val ref: BoxedInt) extends AtomicNumber[Byte] { +final class AtomicByte private (private val ref: BoxedInt) extends AtomicNumber[Byte] { - private[this] val mask = 255 + private val mask = 255 - def get(): Byte = + def get(): Byte = (ref.volatileGet() & mask).asInstanceOf[Byte] - def set(update: Byte): Unit = + def set(update: Byte): Unit = ref.volatileSet(update.asInstanceOf[Int]) def lazySet(update: Byte): Unit = @@ -129,7 +129,8 @@ object AtomicByte { boxStrategyToPaddingStrategy(padding), true, // allowUnsafe allowPlatformIntrinsics - )) + ) + ) /** $createDesc * @@ -153,6 +154,7 @@ object AtomicByte { boxStrategyToPaddingStrategy(padding), false, // allowUnsafe false // allowJava8Intrinsics - )) + ) + ) } } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicChar.scala b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicChar.scala similarity index 94% rename from monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicChar.scala rename to monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicChar.scala index 9d10ecadc..39cf64c90 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicChar.scala +++ b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicChar.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,20 +18,20 @@ package monix.execution.atomic import monix.execution.atomic.PaddingStrategy.NoPadding -import monix.execution.internal.atomic.{BoxedInt, Factory} +import monix.execution.atomic.internal.{ BoxedInt, Factory } /** Atomic references wrapping `Char` values. * * Note that the equality test in `compareAndSet` is value based, * since `Char` is a primitive. */ -final class AtomicChar private (private[this] val ref: BoxedInt) extends AtomicNumber[Char] { - private[this] val mask = 255 + 255 * 256 +final class AtomicChar private (private val ref: BoxedInt) extends AtomicNumber[Char] { + private val mask = 255 + 255 * 256 - def get(): Char = + def get(): Char = (ref.volatileGet() & mask).asInstanceOf[Char] - def set(update: Char): Unit = + def set(update: Char): Unit = ref.volatileSet(update.asInstanceOf[Int]) def lazySet(update: Char): Unit = @@ -128,7 +128,8 @@ object AtomicChar { boxStrategyToPaddingStrategy(padding), true, // allowUnsafe allowPlatformIntrinsics - )) + ) + ) } /** $createDesc @@ -153,6 +154,7 @@ object AtomicChar { boxStrategyToPaddingStrategy(padding), false, // allowUnsafe false // allowJava8Intrinsics - )) + ) + ) } } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicDouble.scala b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicDouble.scala similarity index 93% rename from monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicDouble.scala rename to monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicDouble.scala index 8c1bc9df1..0cb74f7dc 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicDouble.scala +++ b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicDouble.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,17 +17,17 @@ package monix.execution.atomic +import monix.execution.atomic.internal.{ BoxedLong, Factory } import monix.execution.atomic.PaddingStrategy.NoPadding +import java.lang.Double.{ doubleToLongBits, longBitsToDouble } import scala.annotation.tailrec -import java.lang.Double.{doubleToLongBits, longBitsToDouble} -import monix.execution.internal.atomic.{BoxedLong, Factory} /** Atomic references wrapping `Double` values. * * Note that the equality test in `compareAndSet` is value based, * since `Double` is a primitive. */ -final class AtomicDouble private (val ref: BoxedLong) extends AtomicNumber[Double] { +final class AtomicDouble private (private val ref: BoxedLong) extends AtomicNumber[Double] { def get(): Double = longBitsToDouble(ref.volatileGet()) def set(update: Double): Unit = ref.volatileSet(doubleToLongBits(update)) @@ -131,9 +131,9 @@ final class AtomicDouble private (val ref: BoxedLong) extends AtomicNumber[Doubl def decrementAndGet(v: Int = 1): Double = incrementAndGet(-v) def getAndDecrement(v: Int = 1): Double = getAndIncrement(-v) - private[this] def plusOp(a: Double, b: Double): Double = a + b - private[this] def minusOp(a: Double, b: Double): Double = a - b - private[this] def incrementOp(a: Double, b: Int): Double = a + b + private def plusOp(a: Double, b: Double): Double = a + b + private def minusOp(a: Double, b: Double): Double = a - b + private def incrementOp(a: Double, b: Int): Double = a + b } /** @define createDesc Constructs an [[AtomicDouble]] reference, allowing @@ -183,7 +183,8 @@ object AtomicDouble { boxStrategyToPaddingStrategy(padding), true, // allowIntrinsics allowPlatformIntrinsics - )) + ) + ) } /** $createDesc @@ -208,6 +209,7 @@ object AtomicDouble { boxStrategyToPaddingStrategy(padding), false, // allowUnsafe false // allowJava8Intrinsics - )) + ) + ) } } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicFloat.scala b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicFloat.scala similarity index 92% rename from monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicFloat.scala rename to monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicFloat.scala index 83379e222..ddf9ac54d 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicFloat.scala +++ b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicFloat.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,17 +17,17 @@ package monix.execution.atomic +import monix.execution.atomic.internal.{ BoxedInt, Factory } import monix.execution.atomic.PaddingStrategy.NoPadding import scala.annotation.tailrec -import java.lang.Float.{floatToIntBits, intBitsToFloat} -import monix.execution.internal.atomic.{BoxedInt, Factory} +import java.lang.Float.{ floatToIntBits, intBitsToFloat } /** Atomic references wrapping `Float` values. * * Note that the equality test in `compareAndSet` is value based, * since `Float` is a primitive. */ -final class AtomicFloat private (private[this] val ref: BoxedInt) extends AtomicNumber[Float] { +final class AtomicFloat private (private val ref: BoxedInt) extends AtomicNumber[Float] { def get(): Float = intBitsToFloat(ref.volatileGet()) def set(update: Float): Unit = ref.volatileSet(floatToIntBits(update)) @@ -131,9 +131,9 @@ final class AtomicFloat private (private[this] val ref: BoxedInt) extends Atomic def decrementAndGet(v: Int = 1): Float = incrementAndGet(-v) def getAndDecrement(v: Int = 1): Float = getAndIncrement(-v) - private[this] def plusOp(a: Float, b: Float): Float = a + b - private[this] def minusOp(a: Float, b: Float): Float = a - b - private[this] def incrementOp(a: Float, b: Int): Float = a + b + private def plusOp(a: Float, b: Float): Float = a + b + private def minusOp(a: Float, b: Float): Float = a - b + private def incrementOp(a: Float, b: Int): Float = a + b } /** @define createDesc Constructs an [[AtomicFloat]] reference, allowing @@ -183,7 +183,8 @@ object AtomicFloat { boxStrategyToPaddingStrategy(padding), true, // allowUnsafe allowPlatformIntrinsics - )) + ) + ) } /** $createDesc @@ -208,6 +209,7 @@ object AtomicFloat { boxStrategyToPaddingStrategy(padding), false, // allowUnsafe false // allowJava8Intrinsics - )) + ) + ) } } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicInt.scala b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicInt.scala similarity index 95% rename from monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicInt.scala rename to monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicInt.scala index 1c648241f..8c865fbef 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicInt.scala +++ b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicInt.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,14 +18,14 @@ package monix.execution.atomic import monix.execution.atomic.PaddingStrategy.NoPadding -import monix.execution.internal.atomic.{BoxedInt, Factory} +import monix.execution.atomic.internal.{ BoxedInt, Factory } /** Atomic references wrapping `Int` values. * * Note that the equality test in `compareAndSet` is value based, * since `Int` is a primitive. */ -final class AtomicInt private (private[this] val ref: BoxedInt) extends AtomicNumber[Int] { +final class AtomicInt private (private val ref: BoxedInt) extends AtomicNumber[Int] { def get(): Int = ref.volatileGet() def set(update: Int): Unit = ref.volatileSet(update) @@ -124,7 +124,8 @@ object AtomicInt { boxStrategyToPaddingStrategy(padding), true, // allowUnsafe allowPlatformIntrinsics - )) + ) + ) } /** $createDesc @@ -149,6 +150,7 @@ object AtomicInt { boxStrategyToPaddingStrategy(padding), false, // allowUnsafe false // allowJava8Intrinsics - )) + ) + ) } } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicLong.scala b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicLong.scala similarity index 92% rename from monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicLong.scala rename to monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicLong.scala index e637dd6d9..79a737f10 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicLong.scala +++ b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicLong.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,14 +18,14 @@ package monix.execution.atomic import monix.execution.atomic.PaddingStrategy.NoPadding -import monix.execution.internal.atomic.{BoxedLong, Factory} +import monix.execution.atomic.internal.{ BoxedLong, Factory } /** Atomic references wrapping `Long` values. * * Note that the equality test in `compareAndSet` is value based, * since `Long` is a primitive. */ -final class AtomicLong private (private[this] val ref: BoxedLong) extends AtomicNumber[Long] { +final class AtomicLong private (private val ref: BoxedLong) extends AtomicNumber[Long] { def get(): Long = ref.volatileGet() def set(update: Long): Unit = ref.volatileSet(update) @@ -70,16 +70,16 @@ final class AtomicLong private (private[this] val ref: BoxedLong) extends Atomic def subtractAndGet(v: Long): Long = addAndGet(-v) - def decrement(v: Int = 1): Unit = + def decrement(v: Int = 1): Unit = increment(-v) - def decrementAndGet(v: Int = 1): Long = + def decrementAndGet(v: Int = 1): Long = incrementAndGet(-v) - def getAndDecrement(v: Int = 1): Long = + def getAndDecrement(v: Int = 1): Long = getAndIncrement(-v) - override def toString: String = + override def toString: String = s"AtomicLong(${ref.volatileGet()})" } @@ -130,7 +130,8 @@ object AtomicLong { boxStrategyToPaddingStrategy(padding), true, // allowUnsafe allowPlatformIntrinsics - )) + ) + ) } /** $createDesc @@ -155,6 +156,7 @@ object AtomicLong { boxStrategyToPaddingStrategy(padding), false, // allowUnsafe false // allowPlatformIntrinsics - )) + ) + ) } } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicNumberAny.scala b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicNumberAny.scala similarity index 95% rename from monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicNumberAny.scala rename to monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicNumberAny.scala index d95c5df22..7284e747e 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicNumberAny.scala +++ b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicNumberAny.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.execution.atomic import monix.execution.atomic.PaddingStrategy.NoPadding -import monix.execution.internal.atomic.{BoxedObject, Factory} +import monix.execution.atomic.internal.{ BoxedObject, Factory } import scala.annotation.tailrec /** Atomic references wrapping any values implementing @@ -29,9 +29,9 @@ import scala.annotation.tailrec * of the JVM that's the semantic of `compareAndSet`. This behavior * is kept consistent even on top of Scala.js / Javascript. */ -final class AtomicNumberAny[A <: AnyRef: Numeric] private (private[this] val ref: BoxedObject) extends AtomicNumber[A] { +final class AtomicNumberAny[A <: AnyRef: Numeric] private (private val ref: BoxedObject) extends AtomicNumber[A] { - private[this] val ev = implicitly[Numeric[A]] + private val ev = implicitly[Numeric[A]] def get(): A = ref.volatileGet().asInstanceOf[A] def set(update: A): Unit = ref.volatileSet(update) @@ -180,14 +180,16 @@ object AtomicNumberAny { def create[A <: AnyRef: Numeric]( initialValue: A, padding: PaddingStrategy, - allowPlatformIntrinsics: Boolean): AtomicNumberAny[A] = { + allowPlatformIntrinsics: Boolean + ): AtomicNumberAny[A] = { new AtomicNumberAny[A]( Factory.newBoxedObject( initialValue, boxStrategyToPaddingStrategy(padding), true, // allowUnsafe allowPlatformIntrinsics - )) + ) + ) } /** $createDesc @@ -212,5 +214,6 @@ object AtomicNumberAny { boxStrategyToPaddingStrategy(padding), false, // allowUnsafe false // allowPlatformIntrinsics - )) + ) + ) } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicShort.scala b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicShort.scala similarity index 94% rename from monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicShort.scala rename to monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicShort.scala index 86e0f46c5..f5b5a4a0c 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/atomic/AtomicShort.scala +++ b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/AtomicShort.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,20 +18,20 @@ package monix.execution.atomic import monix.execution.atomic.PaddingStrategy.NoPadding -import monix.execution.internal.atomic.{BoxedInt, Factory} +import monix.execution.atomic.internal.{ BoxedInt, Factory } /** Atomic references wrapping `Short` values. * * Note that the equality test in `compareAndSet` is value based, * since `Short` is a primitive. */ -final class AtomicShort private (private[this] val ref: BoxedInt) extends AtomicNumber[Short] { - private[this] val mask = 255 + 255 * 256 +final class AtomicShort private (private val ref: BoxedInt) extends AtomicNumber[Short] { + private val mask = 255 + 255 * 256 - def get(): Short = + def get(): Short = (ref.volatileGet() & mask).asInstanceOf[Short] - def set(update: Short): Unit = + def set(update: Short): Unit = ref.volatileSet(update.asInstanceOf[Int]) def lazySet(update: Short): Unit = @@ -128,7 +128,8 @@ object AtomicShort { boxStrategyToPaddingStrategy(padding), true, // allowUnsafe allowPlatformIntrinsics - )) + ) + ) } /** $createDesc @@ -153,6 +154,7 @@ object AtomicShort { boxStrategyToPaddingStrategy(padding), false, // allowUnsafe false // allowJava8Intrinsics - )) + ) + ) } } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/atomic/package.scala b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/package.scala similarity index 84% rename from monix-execution/jvm/src/main/scala/monix/execution/atomic/package.scala rename to monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/package.scala index 25bf901b8..52799f1dd 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/atomic/package.scala +++ b/monix-execution/atomic/jvm/src/main/scala/monix/execution/atomic/package.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.execution import monix.execution.atomic.PaddingStrategy._ -import monix.execution.internal.atomic.BoxPaddingStrategy +import monix.execution.atomic.internal.BoxPaddingStrategy /** A small toolkit of classes that support compare-and-swap semantics * for safe mutation of variables. @@ -28,10 +28,7 @@ import monix.execution.internal.atomic.BoxPaddingStrategy * for API compatibility purposes and because it's a useful way to * box a value. * - * The backbone of Atomic references is this method: - * {{{ - * def compareAndSet(expect: T, update: T): Boolean - * }}} + * The backbone of Atomic references is this method: [[Atomic.compareAndSet]]. * * This method atomically sets a variable to the `update` value if it * currently holds the `expect` value, reporting `true` on success or @@ -44,16 +41,17 @@ import monix.execution.internal.atomic.BoxPaddingStrategy * `AtomicNumber[A]`): * * {{{ + * import monix.execution.atomic._ + * * val atomicNumber = Atomic(12.2) - * * atomicNumber.incrementAndGet() * // => 13.2 * }}} * - * These also provide useful helpers for atomically mutating of - * values (i.e. `transform`, `transformAndGet`, `getAndTransform`, - * etc...) or of numbers of any kind (`incrementAndGet`, `getAndAdd`, - * etc...). + * These also provide useful helpers for atomically mutating of values + * (i.e. [[Atomic.transform]], [[Atomic.transformAndGet]], [[Atomic.transformAndExtract]], + * etc.) or of numbers of any kind ([[AtomicNumber.incrementAndGet]], + * [[AtomicNumber.getAndAdd]], etc.). */ package object atomic { /** Internal utility for converting between padding strategy representations. */ diff --git a/monix-execution/jvm/src/test/scala/monix/execution/atomic/ConcurrentAtomicNumberSuite.scala b/monix-execution/atomic/jvm/src/test/scala/monix/execution/atomic/ConcurrentAtomicNumberSuite.scala similarity index 60% rename from monix-execution/jvm/src/test/scala/monix/execution/atomic/ConcurrentAtomicNumberSuite.scala rename to monix-execution/atomic/jvm/src/test/scala/monix/execution/atomic/ConcurrentAtomicNumberSuite.scala index 0129a6822..4864f13ef 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/atomic/ConcurrentAtomicNumberSuite.scala +++ b/monix-execution/atomic/jvm/src/test/scala/monix/execution/atomic/ConcurrentAtomicNumberSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,81 +19,82 @@ package monix.execution.atomic import minitest.SimpleTestSuite import monix.execution.atomic.PaddingStrategy._ -import scala.concurrent.{Await, Future} +import scala.concurrent.{ Await, Future } import scala.concurrent.duration._ import scala.concurrent.ExecutionContext.Implicits.global abstract class ConcurrentAtomicNumberSuite[A, R <: AtomicNumber[A]]( builder: AtomicBuilder[A, R], strategy: PaddingStrategy, - value: A, - nan1: Option[A], - maxValue: A, - minValue: A, - allowPlatformIntrinsics: Boolean)(implicit ev: Numeric[A]) + allowPlatformIntrinsics: Boolean, +)(implicit ev: Numeric[A]) extends SimpleTestSuite { def Atomic(initial: A): R = builder.buildInstance(initial, strategy, allowPlatformIntrinsics) - val two = ev.plus(ev.one, ev.one) test("should perform concurrent compareAndSet") { val r = Atomic(ev.zero) - val futures = for (i <- 0 until 5) yield Future { - for (j <- 0 until 100) - r.increment() - } + val futures = + for (_ <- 0 until 5) yield Future { + for (_ <- 0 until 100) + r.increment() + } val f = Future.sequence(futures) - Await.result(f, 30.seconds) + val _ = Await.result(f, 30.seconds) assert(r.get() == ev.fromInt(500)) } test("should perform concurrent getAndSet") { val r = Atomic(ev.zero) - val futures = for (i <- 0 until 5) yield Future { - for (j <- 0 until 100) - r.getAndSet(ev.fromInt(j + 1)) - } + val futures = + for (_ <- 0 until 5) yield Future { + for (j <- 0 until 100) + r.getAndSet(ev.fromInt(j + 1)) + } val f = Future.sequence(futures) - Await.result(f, 30.seconds) + val _ = Await.result(f, 30.seconds) assert(r.get() == ev.fromInt(100)) } test("should perform concurrent increment") { val r = Atomic(ev.zero) - val futures = for (i <- 0 until 5) yield Future { - for (j <- 0 until 100) - r.increment() - } + val futures = + for (_ <- 0 until 5) yield Future { + for (_ <- 0 until 100) + r.increment() + } val f = Future.sequence(futures) - Await.result(f, 30.seconds) + val _ = Await.result(f, 30.seconds) assert(r.get() == ev.fromInt(500)) } test("should perform concurrent incrementAndGet") { val r = Atomic(ev.zero) - val futures = for (i <- 0 until 5) yield Future { - for (j <- 0 until 100) - r.incrementAndGet() - } + val futures = + for (_ <- 0 until 5) yield Future { + for (_ <- 0 until 100) + r.incrementAndGet() + } val f = Future.sequence(futures) - Await.result(f, 30.seconds) + val _ = Await.result(f, 30.seconds) assert(r.get() == ev.fromInt(500)) } test("should perform concurrent getAndIncrement") { val r = Atomic(ev.zero) - val futures = for (i <- 0 until 5) yield Future { - for (j <- 0 until 100) - r.getAndIncrement() - } + val futures = + for (_ <- 0 until 5) yield Future { + for (_ <- 0 until 100) + r.getAndIncrement() + } val f = Future.sequence(futures) - Await.result(f, 30.seconds) + val _ = Await.result(f, 30.seconds) assert(r.get() == ev.fromInt(500)) } } @@ -104,81 +105,57 @@ object ConcurrentAtomicNumberDoubleNoPaddingSuite extends ConcurrentAtomicNumberSuite[Double, AtomicDouble]( Atomic.builderFor(0.0), NoPadding, - 17.23, - Some(Double.NaN), - Double.MaxValue, - Double.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberFloatNoPaddingSuite extends ConcurrentAtomicNumberSuite[Float, AtomicFloat]( Atomic.builderFor(0.0f), NoPadding, - 17.23f, - Some(Float.NaN), - Float.MaxValue, - Float.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberLongNoPaddingSuite extends ConcurrentAtomicNumberSuite[Long, AtomicLong]( Atomic.builderFor(0L), NoPadding, - -782L, - None, - Long.MaxValue, - Long.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberIntNoPaddingSuite extends ConcurrentAtomicNumberSuite[Int, AtomicInt]( Atomic.builderFor(0), NoPadding, - 782, - None, - Int.MaxValue, - Int.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberShortNoPaddingSuite extends ConcurrentAtomicNumberSuite[Short, AtomicShort]( Atomic.builderFor(0.toShort), NoPadding, - 782.toShort, - None, - Short.MaxValue, - Short.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberByteNoPaddingSuite extends ConcurrentAtomicNumberSuite[Byte, AtomicByte]( Atomic.builderFor(0.toByte), NoPadding, - 782.toByte, - None, - Byte.MaxValue, - Byte.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberCharNoPaddingSuite extends ConcurrentAtomicNumberSuite[Char, AtomicChar]( Atomic.builderFor(0.toChar), NoPadding, - 782.toChar, - None, - Char.MaxValue, - Char.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberNumberAnyNoPaddingSuite extends ConcurrentAtomicNumberSuite[BigInt, AtomicNumberAny[BigInt]]( Atomic.builderFor(BigInt(0)), NoPadding, - BigInt(Int.MaxValue), - None, - BigInt(Long.MaxValue), - BigInt(Long.MinValue), - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) //--Left64 (Java 8) @@ -186,81 +163,57 @@ object ConcurrentAtomicNumberDoubleLeft64Suite extends ConcurrentAtomicNumberSuite[Double, AtomicDouble]( Atomic.builderFor(0.0), Left64, - 17.23, - Some(Double.NaN), - Double.MaxValue, - Double.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberFloatLeft64Suite extends ConcurrentAtomicNumberSuite[Float, AtomicFloat]( Atomic.builderFor(0.0f), Left64, - 17.23f, - Some(Float.NaN), - Float.MaxValue, - Float.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberLongLeft64Suite extends ConcurrentAtomicNumberSuite[Long, AtomicLong]( Atomic.builderFor(0L), Left64, - -782L, - None, - Long.MaxValue, - Long.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberIntLeft64Suite extends ConcurrentAtomicNumberSuite[Int, AtomicInt]( Atomic.builderFor(0), Left64, - 782, - None, - Int.MaxValue, - Int.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberShortLeft64Suite extends ConcurrentAtomicNumberSuite[Short, AtomicShort]( Atomic.builderFor(0.toShort), Left64, - 782.toShort, - None, - Short.MaxValue, - Short.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberByteLeft64Suite extends ConcurrentAtomicNumberSuite[Byte, AtomicByte]( Atomic.builderFor(0.toByte), Left64, - 782.toByte, - None, - Byte.MaxValue, - Byte.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberCharLeft64Suite extends ConcurrentAtomicNumberSuite[Char, AtomicChar]( Atomic.builderFor(0.toChar), Left64, - 782.toChar, - None, - Char.MaxValue, - Char.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberNumberAnyLeft64Suite extends ConcurrentAtomicNumberSuite[BigInt, AtomicNumberAny[BigInt]]( Atomic.builderFor(BigInt(0)), Left64, - BigInt(Int.MaxValue), - None, - BigInt(Long.MaxValue), - BigInt(Long.MinValue), - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) //-- Right64 (Java 8) @@ -268,81 +221,57 @@ object ConcurrentAtomicNumberDoubleRight64Suite extends ConcurrentAtomicNumberSuite[Double, AtomicDouble]( Atomic.builderFor(0.0), Right64, - 17.23, - Some(Double.NaN), - Double.MaxValue, - Double.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberFloatRight64Suite extends ConcurrentAtomicNumberSuite[Float, AtomicFloat]( Atomic.builderFor(0.0f), Right64, - 17.23f, - Some(Float.NaN), - Float.MaxValue, - Float.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberLongRight64Suite extends ConcurrentAtomicNumberSuite[Long, AtomicLong]( Atomic.builderFor(0L), Right64, - -782L, - None, - Long.MaxValue, - Long.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberIntRight64Suite extends ConcurrentAtomicNumberSuite[Int, AtomicInt]( Atomic.builderFor(0), Right64, - 782, - None, - Int.MaxValue, - Int.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberShortRight64Suite extends ConcurrentAtomicNumberSuite[Short, AtomicShort]( Atomic.builderFor(0.toShort), Right64, - 782.toShort, - None, - Short.MaxValue, - Short.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberByteRight64Suite extends ConcurrentAtomicNumberSuite[Byte, AtomicByte]( Atomic.builderFor(0.toByte), Right64, - 782.toByte, - None, - Byte.MaxValue, - Byte.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberCharRight64Suite extends ConcurrentAtomicNumberSuite[Char, AtomicChar]( Atomic.builderFor(0.toChar), Right64, - 782.toChar, - None, - Char.MaxValue, - Char.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberNumberAnyRight64Suite extends ConcurrentAtomicNumberSuite[BigInt, AtomicNumberAny[BigInt]]( Atomic.builderFor(BigInt(0)), Right64, - BigInt(Int.MaxValue), - None, - BigInt(Long.MaxValue), - BigInt(Long.MinValue), - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) //-- LeftRight128 (Java 8) @@ -350,81 +279,57 @@ object ConcurrentAtomicNumberDoubleLeftRight128Suite extends ConcurrentAtomicNumberSuite[Double, AtomicDouble]( Atomic.builderFor(0.0), LeftRight128, - 17.23, - Some(Double.NaN), - Double.MaxValue, - Double.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberFloatLeftRight128Suite extends ConcurrentAtomicNumberSuite[Float, AtomicFloat]( Atomic.builderFor(0.0f), LeftRight128, - 17.23f, - Some(Float.NaN), - Float.MaxValue, - Float.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberLongLeftRight128Suite extends ConcurrentAtomicNumberSuite[Long, AtomicLong]( Atomic.builderFor(0L), LeftRight128, - -782L, - None, - Long.MaxValue, - Long.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberIntLeftRight128Suite extends ConcurrentAtomicNumberSuite[Int, AtomicInt]( Atomic.builderFor(0), LeftRight128, - 782, - None, - Int.MaxValue, - Int.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberShortLeftRight128Suite extends ConcurrentAtomicNumberSuite[Short, AtomicShort]( Atomic.builderFor(0.toShort), LeftRight128, - 782.toShort, - None, - Short.MaxValue, - Short.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberByteLeftRight128Suite extends ConcurrentAtomicNumberSuite[Byte, AtomicByte]( Atomic.builderFor(0.toByte), LeftRight128, - 782.toByte, - None, - Byte.MaxValue, - Byte.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberCharLeftRight128Suite extends ConcurrentAtomicNumberSuite[Char, AtomicChar]( Atomic.builderFor(0.toChar), LeftRight128, - 782.toChar, - None, - Char.MaxValue, - Char.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberNumberAnyLeftRight128Suite extends ConcurrentAtomicNumberSuite[BigInt, AtomicNumberAny[BigInt]]( Atomic.builderFor(BigInt(0)), LeftRight128, - BigInt(Int.MaxValue), - None, - BigInt(Long.MaxValue), - BigInt(Long.MinValue), - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) //--Left128 (Java 8) @@ -432,81 +337,57 @@ object ConcurrentAtomicNumberDoubleLeft128Suite extends ConcurrentAtomicNumberSuite[Double, AtomicDouble]( Atomic.builderFor(0.0), Left128, - 17.23, - Some(Double.NaN), - Double.MaxValue, - Double.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberFloatLeft128Suite extends ConcurrentAtomicNumberSuite[Float, AtomicFloat]( Atomic.builderFor(0.0f), Left128, - 17.23f, - Some(Float.NaN), - Float.MaxValue, - Float.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberLongLeft128Suite extends ConcurrentAtomicNumberSuite[Long, AtomicLong]( Atomic.builderFor(0L), Left128, - -782L, - None, - Long.MaxValue, - Long.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberIntLeft128Suite extends ConcurrentAtomicNumberSuite[Int, AtomicInt]( Atomic.builderFor(0), Left128, - 782, - None, - Int.MaxValue, - Int.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberShortLeft128Suite extends ConcurrentAtomicNumberSuite[Short, AtomicShort]( Atomic.builderFor(0.toShort), Left128, - 782.toShort, - None, - Short.MaxValue, - Short.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberByteLeft128Suite extends ConcurrentAtomicNumberSuite[Byte, AtomicByte]( Atomic.builderFor(0.toByte), Left128, - 782.toByte, - None, - Byte.MaxValue, - Byte.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberCharLeft128Suite extends ConcurrentAtomicNumberSuite[Char, AtomicChar]( Atomic.builderFor(0.toChar), Left128, - 782.toChar, - None, - Char.MaxValue, - Char.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberNumberAnyLeft128Suite extends ConcurrentAtomicNumberSuite[BigInt, AtomicNumberAny[BigInt]]( Atomic.builderFor(BigInt(0)), Left128, - BigInt(Int.MaxValue), - None, - BigInt(Long.MaxValue), - BigInt(Long.MinValue), - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) //-- Right128 (Java 8) @@ -514,81 +395,57 @@ object ConcurrentAtomicNumberDoubleRight128Suite extends ConcurrentAtomicNumberSuite[Double, AtomicDouble]( Atomic.builderFor(0.0), Right128, - 17.23, - Some(Double.NaN), - Double.MaxValue, - Double.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberFloatRight128Suite extends ConcurrentAtomicNumberSuite[Float, AtomicFloat]( Atomic.builderFor(0.0f), Right128, - 17.23f, - Some(Float.NaN), - Float.MaxValue, - Float.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberLongRight128Suite extends ConcurrentAtomicNumberSuite[Long, AtomicLong]( Atomic.builderFor(0L), Right128, - -782L, - None, - Long.MaxValue, - Long.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberIntRight128Suite extends ConcurrentAtomicNumberSuite[Int, AtomicInt]( Atomic.builderFor(0), Right128, - 782, - None, - Int.MaxValue, - Int.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberShortRight128Suite extends ConcurrentAtomicNumberSuite[Short, AtomicShort]( Atomic.builderFor(0.toShort), Right128, - 782.toShort, - None, - Short.MaxValue, - Short.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberByteRight128Suite extends ConcurrentAtomicNumberSuite[Byte, AtomicByte]( Atomic.builderFor(0.toByte), Right128, - 782.toByte, - None, - Byte.MaxValue, - Byte.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberCharRight128Suite extends ConcurrentAtomicNumberSuite[Char, AtomicChar]( Atomic.builderFor(0.toChar), Right128, - 782.toChar, - None, - Char.MaxValue, - Char.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberNumberAnyRight128Suite extends ConcurrentAtomicNumberSuite[BigInt, AtomicNumberAny[BigInt]]( Atomic.builderFor(BigInt(0)), Right128, - BigInt(Int.MaxValue), - None, - BigInt(Long.MaxValue), - BigInt(Long.MinValue), - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) //-- LeftRight256 (Java 8) @@ -596,81 +453,57 @@ object ConcurrentAtomicNumberDoubleLeftRight256Suite extends ConcurrentAtomicNumberSuite[Double, AtomicDouble]( Atomic.builderFor(0.0), LeftRight256, - 17.23, - Some(Double.NaN), - Double.MaxValue, - Double.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberFloatLeftRight256Suite extends ConcurrentAtomicNumberSuite[Float, AtomicFloat]( Atomic.builderFor(0.0f), LeftRight256, - 17.23f, - Some(Float.NaN), - Float.MaxValue, - Float.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberLongLeftRight256Suite extends ConcurrentAtomicNumberSuite[Long, AtomicLong]( Atomic.builderFor(0L), LeftRight256, - -782L, - None, - Long.MaxValue, - Long.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberIntLeftRight256Suite extends ConcurrentAtomicNumberSuite[Int, AtomicInt]( Atomic.builderFor(0), LeftRight256, - 782, - None, - Int.MaxValue, - Int.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberShortLeftRight256Suite extends ConcurrentAtomicNumberSuite[Short, AtomicShort]( Atomic.builderFor(0.toShort), LeftRight256, - 782.toShort, - None, - Short.MaxValue, - Short.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberByteLeftRight256Suite extends ConcurrentAtomicNumberSuite[Byte, AtomicByte]( Atomic.builderFor(0.toByte), LeftRight256, - 782.toByte, - None, - Byte.MaxValue, - Byte.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberCharLeftRight256Suite extends ConcurrentAtomicNumberSuite[Char, AtomicChar]( Atomic.builderFor(0.toChar), LeftRight256, - 782.toChar, - None, - Char.MaxValue, - Char.MinValue, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicNumberNumberAnyLeftRight256Suite extends ConcurrentAtomicNumberSuite[BigInt, AtomicNumberAny[BigInt]]( Atomic.builderFor(BigInt(0)), LeftRight256, - BigInt(Int.MaxValue), - None, - BigInt(Long.MaxValue), - BigInt(Long.MinValue), - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) // ------------ Java 7 @@ -680,81 +513,57 @@ object ConcurrentAtomicNumberDoubleNoPaddingJava7Suite extends ConcurrentAtomicNumberSuite[Double, AtomicDouble]( Atomic.builderFor(0.0), NoPadding, - 17.23, - Some(Double.NaN), - Double.MaxValue, - Double.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberFloatNoPaddingJava7Suite extends ConcurrentAtomicNumberSuite[Float, AtomicFloat]( Atomic.builderFor(0.0f), NoPadding, - 17.23f, - Some(Float.NaN), - Float.MaxValue, - Float.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberLongNoPaddingJava7Suite extends ConcurrentAtomicNumberSuite[Long, AtomicLong]( Atomic.builderFor(0L), NoPadding, - -782L, - None, - Long.MaxValue, - Long.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberIntNoPaddingJava7Suite extends ConcurrentAtomicNumberSuite[Int, AtomicInt]( Atomic.builderFor(0), NoPadding, - 782, - None, - Int.MaxValue, - Int.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberShortNoPaddingJava7Suite extends ConcurrentAtomicNumberSuite[Short, AtomicShort]( Atomic.builderFor(0.toShort), NoPadding, - 782.toShort, - None, - Short.MaxValue, - Short.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberByteNoPaddingJava7Suite extends ConcurrentAtomicNumberSuite[Byte, AtomicByte]( Atomic.builderFor(0.toByte), NoPadding, - 782.toByte, - None, - Byte.MaxValue, - Byte.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberCharNoPaddingJava7Suite extends ConcurrentAtomicNumberSuite[Char, AtomicChar]( Atomic.builderFor(0.toChar), NoPadding, - 782.toChar, - None, - Char.MaxValue, - Char.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberNumberAnyNoPaddingJava7Suite extends ConcurrentAtomicNumberSuite[BigInt, AtomicNumberAny[BigInt]]( Atomic.builderFor(BigInt(0)), NoPadding, - BigInt(Int.MaxValue), - None, - BigInt(Long.MaxValue), - BigInt(Long.MinValue), - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) //--Left64 (Java 7) @@ -762,81 +571,57 @@ object ConcurrentAtomicNumberDoubleLeft64Java7Suite extends ConcurrentAtomicNumberSuite[Double, AtomicDouble]( Atomic.builderFor(0.0), Left64, - 17.23, - Some(Double.NaN), - Double.MaxValue, - Double.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberFloatLeft64Java7Suite extends ConcurrentAtomicNumberSuite[Float, AtomicFloat]( Atomic.builderFor(0.0f), Left64, - 17.23f, - Some(Float.NaN), - Float.MaxValue, - Float.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberLongLeft64Java7Suite extends ConcurrentAtomicNumberSuite[Long, AtomicLong]( Atomic.builderFor(0L), Left64, - -782L, - None, - Long.MaxValue, - Long.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberIntLeft64Java7Suite extends ConcurrentAtomicNumberSuite[Int, AtomicInt]( Atomic.builderFor(0), Left64, - 782, - None, - Int.MaxValue, - Int.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberShortLeft64Java7Suite extends ConcurrentAtomicNumberSuite[Short, AtomicShort]( Atomic.builderFor(0.toShort), Left64, - 782.toShort, - None, - Short.MaxValue, - Short.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberByteLeft64Java7Suite extends ConcurrentAtomicNumberSuite[Byte, AtomicByte]( Atomic.builderFor(0.toByte), Left64, - 782.toByte, - None, - Byte.MaxValue, - Byte.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberCharLeft64Java7Suite extends ConcurrentAtomicNumberSuite[Char, AtomicChar]( Atomic.builderFor(0.toChar), Left64, - 782.toChar, - None, - Char.MaxValue, - Char.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberNumberAnyLeft64Java7Suite extends ConcurrentAtomicNumberSuite[BigInt, AtomicNumberAny[BigInt]]( Atomic.builderFor(BigInt(0)), Left64, - BigInt(Int.MaxValue), - None, - BigInt(Long.MaxValue), - BigInt(Long.MinValue), - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) //-- Right64 (Java 7) @@ -844,81 +629,57 @@ object ConcurrentAtomicNumberDoubleRight64Java7Suite extends ConcurrentAtomicNumberSuite[Double, AtomicDouble]( Atomic.builderFor(0.0), Right64, - 17.23, - Some(Double.NaN), - Double.MaxValue, - Double.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberFloatRight64Java7Suite extends ConcurrentAtomicNumberSuite[Float, AtomicFloat]( Atomic.builderFor(0.0f), Right64, - 17.23f, - Some(Float.NaN), - Float.MaxValue, - Float.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberLongRight64Java7Suite extends ConcurrentAtomicNumberSuite[Long, AtomicLong]( Atomic.builderFor(0L), Right64, - -782L, - None, - Long.MaxValue, - Long.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberIntRight64Java7Suite extends ConcurrentAtomicNumberSuite[Int, AtomicInt]( Atomic.builderFor(0), Right64, - 782, - None, - Int.MaxValue, - Int.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberShortRight64Java7Suite extends ConcurrentAtomicNumberSuite[Short, AtomicShort]( Atomic.builderFor(0.toShort), Right64, - 782.toShort, - None, - Short.MaxValue, - Short.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberByteRight64Java7Suite extends ConcurrentAtomicNumberSuite[Byte, AtomicByte]( Atomic.builderFor(0.toByte), Right64, - 782.toByte, - None, - Byte.MaxValue, - Byte.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberCharRight64Java7Suite extends ConcurrentAtomicNumberSuite[Char, AtomicChar]( Atomic.builderFor(0.toChar), Right64, - 782.toChar, - None, - Char.MaxValue, - Char.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberNumberAnyRight64Java7Suite extends ConcurrentAtomicNumberSuite[BigInt, AtomicNumberAny[BigInt]]( Atomic.builderFor(BigInt(0)), Right64, - BigInt(Int.MaxValue), - None, - BigInt(Long.MaxValue), - BigInt(Long.MinValue), - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) //-- LeftRight128 (Java 7) @@ -926,81 +687,57 @@ object ConcurrentAtomicNumberDoubleLeftRight128Java7Suite extends ConcurrentAtomicNumberSuite[Double, AtomicDouble]( Atomic.builderFor(0.0), LeftRight128, - 17.23, - Some(Double.NaN), - Double.MaxValue, - Double.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberFloatLeftRight128Java7Suite extends ConcurrentAtomicNumberSuite[Float, AtomicFloat]( Atomic.builderFor(0.0f), LeftRight128, - 17.23f, - Some(Float.NaN), - Float.MaxValue, - Float.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberLongLeftRight128Java7Suite extends ConcurrentAtomicNumberSuite[Long, AtomicLong]( Atomic.builderFor(0L), LeftRight128, - -782L, - None, - Long.MaxValue, - Long.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberIntLeftRight128Java7Suite extends ConcurrentAtomicNumberSuite[Int, AtomicInt]( Atomic.builderFor(0), LeftRight128, - 782, - None, - Int.MaxValue, - Int.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberShortLeftRight128Java7Suite extends ConcurrentAtomicNumberSuite[Short, AtomicShort]( Atomic.builderFor(0.toShort), LeftRight128, - 782.toShort, - None, - Short.MaxValue, - Short.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberByteLeftRight128Java7Suite extends ConcurrentAtomicNumberSuite[Byte, AtomicByte]( Atomic.builderFor(0.toByte), LeftRight128, - 782.toByte, - None, - Byte.MaxValue, - Byte.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberCharLeftRight128Java7Suite extends ConcurrentAtomicNumberSuite[Char, AtomicChar]( Atomic.builderFor(0.toChar), LeftRight128, - 782.toChar, - None, - Char.MaxValue, - Char.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberNumberAnyLeftRight128Java7Suite extends ConcurrentAtomicNumberSuite[BigInt, AtomicNumberAny[BigInt]]( Atomic.builderFor(BigInt(0)), LeftRight128, - BigInt(Int.MaxValue), - None, - BigInt(Long.MaxValue), - BigInt(Long.MinValue), - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) //--Left128 (Java 7) @@ -1008,81 +745,57 @@ object ConcurrentAtomicNumberDoubleLeft128Java7Suite extends ConcurrentAtomicNumberSuite[Double, AtomicDouble]( Atomic.builderFor(0.0), Left128, - 17.23, - Some(Double.NaN), - Double.MaxValue, - Double.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberFloatLeft128Java7Suite extends ConcurrentAtomicNumberSuite[Float, AtomicFloat]( Atomic.builderFor(0.0f), Left128, - 17.23f, - Some(Float.NaN), - Float.MaxValue, - Float.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberLongLeft128Java7Suite extends ConcurrentAtomicNumberSuite[Long, AtomicLong]( Atomic.builderFor(0L), Left128, - -782L, - None, - Long.MaxValue, - Long.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberIntLeft128Java7Suite extends ConcurrentAtomicNumberSuite[Int, AtomicInt]( Atomic.builderFor(0), Left128, - 782, - None, - Int.MaxValue, - Int.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberShortLeft128Java7Suite extends ConcurrentAtomicNumberSuite[Short, AtomicShort]( Atomic.builderFor(0.toShort), Left128, - 782.toShort, - None, - Short.MaxValue, - Short.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberByteLeft128Java7Suite extends ConcurrentAtomicNumberSuite[Byte, AtomicByte]( Atomic.builderFor(0.toByte), Left128, - 782.toByte, - None, - Byte.MaxValue, - Byte.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberCharLeft128Java7Suite extends ConcurrentAtomicNumberSuite[Char, AtomicChar]( Atomic.builderFor(0.toChar), Left128, - 782.toChar, - None, - Char.MaxValue, - Char.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberNumberAnyLeft128Java7Suite extends ConcurrentAtomicNumberSuite[BigInt, AtomicNumberAny[BigInt]]( Atomic.builderFor(BigInt(0)), Left128, - BigInt(Int.MaxValue), - None, - BigInt(Long.MaxValue), - BigInt(Long.MinValue), - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) //-- Right128 (Java 7) @@ -1090,81 +803,57 @@ object ConcurrentAtomicNumberDoubleRight128Java7Suite extends ConcurrentAtomicNumberSuite[Double, AtomicDouble]( Atomic.builderFor(0.0), Right128, - 17.23, - Some(Double.NaN), - Double.MaxValue, - Double.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberFloatRight128Java7Suite extends ConcurrentAtomicNumberSuite[Float, AtomicFloat]( Atomic.builderFor(0.0f), Right128, - 17.23f, - Some(Float.NaN), - Float.MaxValue, - Float.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberLongRight128Java7Suite extends ConcurrentAtomicNumberSuite[Long, AtomicLong]( Atomic.builderFor(0L), Right128, - -782L, - None, - Long.MaxValue, - Long.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberIntRight128Java7Suite extends ConcurrentAtomicNumberSuite[Int, AtomicInt]( Atomic.builderFor(0), Right128, - 782, - None, - Int.MaxValue, - Int.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberShortRight128Java7Suite extends ConcurrentAtomicNumberSuite[Short, AtomicShort]( Atomic.builderFor(0.toShort), Right128, - 782.toShort, - None, - Short.MaxValue, - Short.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberByteRight128Java7Suite extends ConcurrentAtomicNumberSuite[Byte, AtomicByte]( Atomic.builderFor(0.toByte), Right128, - 782.toByte, - None, - Byte.MaxValue, - Byte.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberCharRight128Java7Suite extends ConcurrentAtomicNumberSuite[Char, AtomicChar]( Atomic.builderFor(0.toChar), Right128, - 782.toChar, - None, - Char.MaxValue, - Char.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberNumberAnyRight128Java7Suite extends ConcurrentAtomicNumberSuite[BigInt, AtomicNumberAny[BigInt]]( Atomic.builderFor(BigInt(0)), Right128, - BigInt(Int.MaxValue), - None, - BigInt(Long.MaxValue), - BigInt(Long.MinValue), - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) //-- LeftRight256 (Java 7) @@ -1172,78 +861,54 @@ object ConcurrentAtomicNumberDoubleLeftRight256Java7Suite extends ConcurrentAtomicNumberSuite[Double, AtomicDouble]( Atomic.builderFor(0.0), LeftRight256, - 17.23, - Some(Double.NaN), - Double.MaxValue, - Double.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberFloatLeftRight256Java7Suite extends ConcurrentAtomicNumberSuite[Float, AtomicFloat]( Atomic.builderFor(0.0f), LeftRight256, - 17.23f, - Some(Float.NaN), - Float.MaxValue, - Float.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberLongLeftRight256Java7Suite extends ConcurrentAtomicNumberSuite[Long, AtomicLong]( Atomic.builderFor(0L), LeftRight256, - -782L, - None, - Long.MaxValue, - Long.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberIntLeftRight256Java7Suite extends ConcurrentAtomicNumberSuite[Int, AtomicInt]( Atomic.builderFor(0), LeftRight256, - 782, - None, - Int.MaxValue, - Int.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberShortLeftRight256Java7Suite extends ConcurrentAtomicNumberSuite[Short, AtomicShort]( Atomic.builderFor(0.toShort), LeftRight256, - 782.toShort, - None, - Short.MaxValue, - Short.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberByteLeftRight256Java7Suite extends ConcurrentAtomicNumberSuite[Byte, AtomicByte]( Atomic.builderFor(0.toByte), LeftRight256, - 782.toByte, - None, - Byte.MaxValue, - Byte.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberCharLeftRight256Java7Suite extends ConcurrentAtomicNumberSuite[Char, AtomicChar]( Atomic.builderFor(0.toChar), LeftRight256, - 782.toChar, - None, - Char.MaxValue, - Char.MinValue, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicNumberNumberAnyLeftRight256Java7Suite extends ConcurrentAtomicNumberSuite[BigInt, AtomicNumberAny[BigInt]]( Atomic.builderFor(BigInt(0)), LeftRight256, - BigInt(Int.MaxValue), - None, - BigInt(Long.MaxValue), - BigInt(Long.MinValue), - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) diff --git a/monix-execution/jvm/src/test/scala/monix/execution/atomic/ConcurrentAtomicSuite.scala b/monix-execution/atomic/jvm/src/test/scala/monix/execution/atomic/ConcurrentAtomicSuite.scala similarity index 82% rename from monix-execution/jvm/src/test/scala/monix/execution/atomic/ConcurrentAtomicSuite.scala rename to monix-execution/atomic/jvm/src/test/scala/monix/execution/atomic/ConcurrentAtomicSuite.scala index 2df5b8ef7..5db41ee81 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/atomic/ConcurrentAtomicSuite.scala +++ b/monix-execution/atomic/jvm/src/test/scala/monix/execution/atomic/ConcurrentAtomicSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,15 +21,15 @@ import minitest.SimpleTestSuite import monix.execution.atomic.PaddingStrategy._ import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.duration._ -import scala.concurrent.{Await, Future} +import scala.concurrent.{ Await, Future } abstract class ConcurrentAtomicSuite[A, R <: Atomic[A]]( builder: AtomicBuilder[A, R], strategy: PaddingStrategy, valueFromInt: Int => A, valueToInt: A => Int, - allowPlatformIntrinsics: Boolean) - extends SimpleTestSuite { + allowPlatformIntrinsics: Boolean +) extends SimpleTestSuite { def Atomic(initial: A): R = builder.buildInstance(initial, strategy, allowPlatformIntrinsics) def zero = valueFromInt(0) @@ -38,25 +38,27 @@ abstract class ConcurrentAtomicSuite[A, R <: Atomic[A]]( test("should perform concurrent compareAndSet") { val r = Atomic(zero) - val futures = for (i <- 0 until 5) yield Future { - for (j <- 0 until 100) - r.transform(x => valueFromInt(valueToInt(x) + 1)) - } + val futures = + for (_ <- 0 until 5) yield Future { + for (_ <- 0 until 100) + r.transform(x => valueFromInt(valueToInt(x) + 1)) + } val f = Future.sequence(futures) - Await.result(f, 30.seconds) + val _ = Await.result(f, 30.seconds) assert(r.get() == valueFromInt(500)) } test("should perform concurrent getAndSet") { val r = Atomic(zero) - val futures = for (i <- 0 until 5) yield Future { - for (j <- 0 until 100) - r.getAndSet(valueFromInt(j)) - } + val futures = + for (_ <- 0 until 5) yield Future { + for (j <- 0 until 100) + r.getAndSet(valueFromInt(j)) + } val f = Future.sequence(futures) - Await.result(f, 30.seconds) + val _ = Await.result(f, 30.seconds) assert(r.get() == valueFromInt(99)) } } @@ -67,13 +69,15 @@ abstract class ConcurrentAtomicBooleanSuite(strategy: PaddingStrategy, allowPlat strategy, x => if (x == 1) true else false, x => if (x) 1 else 0, - allowPlatformIntrinsics) { + allowPlatformIntrinsics + ) { test("should flip to true when false") { val r = Atomic(false) - val futures = for (_ <- 0 until 5) yield Future { - r.flip(true) - } + val futures = + for (_ <- 0 until 5) yield Future { + r.flip(true) + } val result = Await.result(Future.sequence(futures), 30.seconds) assert(result.count(_ == true) == 1) assert(r.get()) @@ -81,9 +85,10 @@ abstract class ConcurrentAtomicBooleanSuite(strategy: PaddingStrategy, allowPlat test("should not flip to true when already true") { val r = Atomic(true) - val futures = for (_ <- 0 until 5) yield Future { - r.flip(true) - } + val futures = + for (_ <- 0 until 5) yield Future { + r.flip(true) + } val result = Await.result(Future.sequence(futures), 30.seconds) assert(result.forall(_ == false)) } @@ -97,7 +102,8 @@ object ConcurrentAtomicAnyNoPaddingSuite NoPadding, x => x.toString, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicBooleanNoPaddingSuite extends ConcurrentAtomicBooleanSuite(NoPadding) @@ -107,7 +113,8 @@ object ConcurrentAtomicNumberAnyNoPaddingSuite NoPadding, x => BigInt(x), x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicFloatNoPaddingSuite extends ConcurrentAtomicSuite[Float, AtomicFloat]( @@ -115,7 +122,8 @@ object ConcurrentAtomicFloatNoPaddingSuite NoPadding, x => x.toFloat, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicDoubleNoPaddingSuite extends ConcurrentAtomicSuite[Double, AtomicDouble]( @@ -123,7 +131,8 @@ object ConcurrentAtomicDoubleNoPaddingSuite NoPadding, x => x.toDouble, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicShortNoPaddingSuite extends ConcurrentAtomicSuite[Short, AtomicShort]( @@ -131,7 +140,8 @@ object ConcurrentAtomicShortNoPaddingSuite NoPadding, x => x.toShort, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicByteNoPaddingSuite extends ConcurrentAtomicSuite[Byte, AtomicByte]( @@ -139,7 +149,8 @@ object ConcurrentAtomicByteNoPaddingSuite NoPadding, x => x.toByte, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicCharNoPaddingSuite extends ConcurrentAtomicSuite[Char, AtomicChar]( @@ -147,7 +158,8 @@ object ConcurrentAtomicCharNoPaddingSuite NoPadding, x => x.toChar, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicIntNoPaddingSuite extends ConcurrentAtomicSuite[Int, AtomicInt]( @@ -155,7 +167,8 @@ object ConcurrentAtomicIntNoPaddingSuite NoPadding, x => x, x => x, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicLongNoPaddingSuite extends ConcurrentAtomicSuite[Long, AtomicLong]( @@ -163,7 +176,8 @@ object ConcurrentAtomicLongNoPaddingSuite NoPadding, x => x.toLong, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) // -- Left64 (Java 8) @@ -173,7 +187,8 @@ object ConcurrentAtomicAnyLeft64Suite Left64, x => x.toString, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicBooleanLeft64Suite extends ConcurrentAtomicBooleanSuite(Left64) @@ -183,7 +198,8 @@ object ConcurrentAtomicNumberAnyLeft64Suite Left64, x => BigInt(x), x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicFloatLeft64Suite extends ConcurrentAtomicSuite[Float, AtomicFloat]( @@ -191,7 +207,8 @@ object ConcurrentAtomicFloatLeft64Suite Left64, x => x.toFloat, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicDoubleLeft64Suite extends ConcurrentAtomicSuite[Double, AtomicDouble]( @@ -199,7 +216,8 @@ object ConcurrentAtomicDoubleLeft64Suite Left64, x => x.toDouble, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicShortLeft64Suite extends ConcurrentAtomicSuite[Short, AtomicShort]( @@ -207,7 +225,8 @@ object ConcurrentAtomicShortLeft64Suite Left64, x => x.toShort, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicByteLeft64Suite extends ConcurrentAtomicSuite[Byte, AtomicByte]( @@ -215,7 +234,8 @@ object ConcurrentAtomicByteLeft64Suite Left64, x => x.toByte, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicCharLeft64Suite extends ConcurrentAtomicSuite[Char, AtomicChar]( @@ -223,7 +243,8 @@ object ConcurrentAtomicCharLeft64Suite Left64, x => x.toChar, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicIntLeft64Suite extends ConcurrentAtomicSuite[Int, AtomicInt]( @@ -231,7 +252,8 @@ object ConcurrentAtomicIntLeft64Suite Left64, x => x, x => x, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicLongLeft64Suite extends ConcurrentAtomicSuite[Long, AtomicLong]( @@ -239,7 +261,8 @@ object ConcurrentAtomicLongLeft64Suite Left64, x => x.toLong, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) // -- Right64 (Java 8) @@ -249,7 +272,8 @@ object ConcurrentAtomicAnyRight64Suite Right64, x => x.toString, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicBooleanRight64Suite extends ConcurrentAtomicBooleanSuite(Right64) @@ -259,7 +283,8 @@ object ConcurrentAtomicNumberAnyRight64Suite Right64, x => BigInt(x), x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicFloatRight64Suite extends ConcurrentAtomicSuite[Float, AtomicFloat]( @@ -267,7 +292,8 @@ object ConcurrentAtomicFloatRight64Suite Right64, x => x.toFloat, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicDoubleRight64Suite extends ConcurrentAtomicSuite[Double, AtomicDouble]( @@ -275,7 +301,8 @@ object ConcurrentAtomicDoubleRight64Suite Right64, x => x.toDouble, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicShortRight64Suite extends ConcurrentAtomicSuite[Short, AtomicShort]( @@ -283,7 +310,8 @@ object ConcurrentAtomicShortRight64Suite Right64, x => x.toShort, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicByteRight64Suite extends ConcurrentAtomicSuite[Byte, AtomicByte]( @@ -291,7 +319,8 @@ object ConcurrentAtomicByteRight64Suite Right64, x => x.toByte, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicCharRight64Suite extends ConcurrentAtomicSuite[Char, AtomicChar]( @@ -299,7 +328,8 @@ object ConcurrentAtomicCharRight64Suite Right64, x => x.toChar, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicIntRight64Suite extends ConcurrentAtomicSuite[Int, AtomicInt]( @@ -307,7 +337,8 @@ object ConcurrentAtomicIntRight64Suite Right64, x => x, x => x, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicLongRight64Suite extends ConcurrentAtomicSuite[Long, AtomicLong]( @@ -315,7 +346,8 @@ object ConcurrentAtomicLongRight64Suite Right64, x => x.toLong, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) // -- LeftRight128 (Java 8) @@ -325,7 +357,8 @@ object ConcurrentAtomicAnyLeftRight128Suite LeftRight128, x => x.toString, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicBooleanLeftRight128Suite extends ConcurrentAtomicBooleanSuite(LeftRight128) @@ -335,7 +368,8 @@ object ConcurrentAtomicNumberAnyLeftRight128Suite LeftRight128, x => BigInt(x), x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicFloatLeftRight128Suite extends ConcurrentAtomicSuite[Float, AtomicFloat]( @@ -343,7 +377,8 @@ object ConcurrentAtomicFloatLeftRight128Suite LeftRight128, x => x.toFloat, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicDoubleLeftRight128Suite extends ConcurrentAtomicSuite[Double, AtomicDouble]( @@ -351,7 +386,8 @@ object ConcurrentAtomicDoubleLeftRight128Suite LeftRight128, x => x.toDouble, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicShortLeftRight128Suite extends ConcurrentAtomicSuite[Short, AtomicShort]( @@ -359,7 +395,8 @@ object ConcurrentAtomicShortLeftRight128Suite LeftRight128, x => x.toShort, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicByteLeftRight128Suite extends ConcurrentAtomicSuite[Byte, AtomicByte]( @@ -367,7 +404,8 @@ object ConcurrentAtomicByteLeftRight128Suite LeftRight128, x => x.toByte, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicCharLeftRight128Suite extends ConcurrentAtomicSuite[Char, AtomicChar]( @@ -375,7 +413,8 @@ object ConcurrentAtomicCharLeftRight128Suite LeftRight128, x => x.toChar, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicIntLeftRight128Suite extends ConcurrentAtomicSuite[Int, AtomicInt]( @@ -383,7 +422,8 @@ object ConcurrentAtomicIntLeftRight128Suite LeftRight128, x => x, x => x, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicLongLeftRight128Suite extends ConcurrentAtomicSuite[Long, AtomicLong]( @@ -391,7 +431,8 @@ object ConcurrentAtomicLongLeftRight128Suite LeftRight128, x => x.toLong, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) // -- Left128 (Java 8) @@ -401,7 +442,8 @@ object ConcurrentAtomicAnyLeft128Suite Left128, x => x.toString, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicBooleanLeft128Suite extends ConcurrentAtomicBooleanSuite(Left128) @@ -411,7 +453,8 @@ object ConcurrentAtomicNumberAnyLeft128Suite Left128, x => BigInt(x), x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicFloatLeft128Suite extends ConcurrentAtomicSuite[Float, AtomicFloat]( @@ -419,7 +462,8 @@ object ConcurrentAtomicFloatLeft128Suite Left128, x => x.toFloat, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicDoubleLeft128Suite extends ConcurrentAtomicSuite[Double, AtomicDouble]( @@ -427,7 +471,8 @@ object ConcurrentAtomicDoubleLeft128Suite Left128, x => x.toDouble, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicShortLeft128Suite extends ConcurrentAtomicSuite[Short, AtomicShort]( @@ -435,7 +480,8 @@ object ConcurrentAtomicShortLeft128Suite Left128, x => x.toShort, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicByteLeft128Suite extends ConcurrentAtomicSuite[Byte, AtomicByte]( @@ -443,7 +489,8 @@ object ConcurrentAtomicByteLeft128Suite Left128, x => x.toByte, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicCharLeft128Suite extends ConcurrentAtomicSuite[Char, AtomicChar]( @@ -451,7 +498,8 @@ object ConcurrentAtomicCharLeft128Suite Left128, x => x.toChar, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicIntLeft128Suite extends ConcurrentAtomicSuite[Int, AtomicInt]( @@ -459,7 +507,8 @@ object ConcurrentAtomicIntLeft128Suite Left128, x => x, x => x, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicLongLeft128Suite extends ConcurrentAtomicSuite[Long, AtomicLong]( @@ -467,7 +516,8 @@ object ConcurrentAtomicLongLeft128Suite Left128, x => x.toLong, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) // -- Right128 (Java 8) @@ -477,7 +527,8 @@ object ConcurrentAtomicAnyRight128Suite Right128, x => x.toString, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicBooleanRight128Suite extends ConcurrentAtomicBooleanSuite(Right128) @@ -487,7 +538,8 @@ object ConcurrentAtomicNumberAnyRight128Suite Right128, x => BigInt(x), x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicFloatRight128Suite extends ConcurrentAtomicSuite[Float, AtomicFloat]( @@ -495,7 +547,8 @@ object ConcurrentAtomicFloatRight128Suite Right128, x => x.toFloat, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicDoubleRight128Suite extends ConcurrentAtomicSuite[Double, AtomicDouble]( @@ -503,7 +556,8 @@ object ConcurrentAtomicDoubleRight128Suite Right128, x => x.toDouble, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicShortRight128Suite extends ConcurrentAtomicSuite[Short, AtomicShort]( @@ -511,7 +565,8 @@ object ConcurrentAtomicShortRight128Suite Right128, x => x.toShort, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicByteRight128Suite extends ConcurrentAtomicSuite[Byte, AtomicByte]( @@ -519,7 +574,8 @@ object ConcurrentAtomicByteRight128Suite Right128, x => x.toByte, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicCharRight128Suite extends ConcurrentAtomicSuite[Char, AtomicChar]( @@ -527,7 +583,8 @@ object ConcurrentAtomicCharRight128Suite Right128, x => x.toChar, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicIntRight128Suite extends ConcurrentAtomicSuite[Int, AtomicInt]( @@ -535,7 +592,8 @@ object ConcurrentAtomicIntRight128Suite Right128, x => x, x => x, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicLongRight128Suite extends ConcurrentAtomicSuite[Long, AtomicLong]( @@ -543,7 +601,8 @@ object ConcurrentAtomicLongRight128Suite Right128, x => x.toLong, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) // -- LeftRight256 (Java 8) @@ -553,7 +612,8 @@ object ConcurrentAtomicAnyLeftRight256Suite LeftRight256, x => x.toString, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicBooleanLeftRight256Suite extends ConcurrentAtomicBooleanSuite(LeftRight256) @@ -563,7 +623,8 @@ object ConcurrentAtomicNumberAnyLeftRight256Suite LeftRight256, x => BigInt(x), x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicFloatLeftRight256Suite extends ConcurrentAtomicSuite[Float, AtomicFloat]( @@ -571,7 +632,8 @@ object ConcurrentAtomicFloatLeftRight256Suite LeftRight256, x => x.toFloat, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicDoubleLeftRight256Suite extends ConcurrentAtomicSuite[Double, AtomicDouble]( @@ -579,7 +641,8 @@ object ConcurrentAtomicDoubleLeftRight256Suite LeftRight256, x => x.toDouble, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicShortLeftRight256Suite extends ConcurrentAtomicSuite[Short, AtomicShort]( @@ -587,7 +650,8 @@ object ConcurrentAtomicShortLeftRight256Suite LeftRight256, x => x.toShort, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicByteLeftRight256Suite extends ConcurrentAtomicSuite[Byte, AtomicByte]( @@ -595,7 +659,8 @@ object ConcurrentAtomicByteLeftRight256Suite LeftRight256, x => x.toByte, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicCharLeftRight256Suite extends ConcurrentAtomicSuite[Char, AtomicChar]( @@ -603,7 +668,8 @@ object ConcurrentAtomicCharLeftRight256Suite LeftRight256, x => x.toChar, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicIntLeftRight256Suite extends ConcurrentAtomicSuite[Int, AtomicInt]( @@ -611,7 +677,8 @@ object ConcurrentAtomicIntLeftRight256Suite LeftRight256, x => x, x => x, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) object ConcurrentAtomicLongLeftRight256Suite extends ConcurrentAtomicSuite[Long, AtomicLong]( @@ -619,7 +686,8 @@ object ConcurrentAtomicLongLeftRight256Suite LeftRight256, x => x.toLong, x => x.toInt, - allowPlatformIntrinsics = true) + allowPlatformIntrinsics = true + ) // -------------- Java 7 @@ -631,7 +699,8 @@ object ConcurrentAtomicAnyNoPaddingJava7Suite NoPadding, x => x.toString, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicBooleanNoPaddingJava7Suite extends ConcurrentAtomicBooleanSuite(NoPadding, allowPlatformIntrinsics = false) @@ -642,7 +711,8 @@ object ConcurrentAtomicNumberAnyNoPaddingJava7Suite NoPadding, x => BigInt(x), x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicFloatNoPaddingJava7Suite extends ConcurrentAtomicSuite[Float, AtomicFloat]( @@ -650,7 +720,8 @@ object ConcurrentAtomicFloatNoPaddingJava7Suite NoPadding, x => x.toFloat, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicDoubleNoPaddingJava7Suite extends ConcurrentAtomicSuite[Double, AtomicDouble]( @@ -658,7 +729,8 @@ object ConcurrentAtomicDoubleNoPaddingJava7Suite NoPadding, x => x.toDouble, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicShortNoPaddingJava7Suite extends ConcurrentAtomicSuite[Short, AtomicShort]( @@ -666,7 +738,8 @@ object ConcurrentAtomicShortNoPaddingJava7Suite NoPadding, x => x.toShort, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicByteNoPaddingJava7Suite extends ConcurrentAtomicSuite[Byte, AtomicByte]( @@ -674,7 +747,8 @@ object ConcurrentAtomicByteNoPaddingJava7Suite NoPadding, x => x.toByte, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicCharNoPaddingJava7Suite extends ConcurrentAtomicSuite[Char, AtomicChar]( @@ -682,7 +756,8 @@ object ConcurrentAtomicCharNoPaddingJava7Suite NoPadding, x => x.toChar, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicIntNoPaddingJava7Suite extends ConcurrentAtomicSuite[Int, AtomicInt]( @@ -690,7 +765,8 @@ object ConcurrentAtomicIntNoPaddingJava7Suite NoPadding, x => x, x => x, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicLongNoPaddingJava7Suite extends ConcurrentAtomicSuite[Long, AtomicLong]( @@ -698,7 +774,8 @@ object ConcurrentAtomicLongNoPaddingJava7Suite NoPadding, x => x.toLong, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) // -- Left64 (Java 7) @@ -708,7 +785,8 @@ object ConcurrentAtomicAnyLeft64Java7Suite Left64, x => x.toString, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicBooleanLeft64Java7Suite extends ConcurrentAtomicBooleanSuite(Left64, allowPlatformIntrinsics = false) @@ -719,7 +797,8 @@ object ConcurrentAtomicNumberAnyLeft64Java7Suite Left64, x => BigInt(x), x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicFloatLeft64Java7Suite extends ConcurrentAtomicSuite[Float, AtomicFloat]( @@ -727,7 +806,8 @@ object ConcurrentAtomicFloatLeft64Java7Suite Left64, x => x.toFloat, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicDoubleLeft64Java7Suite extends ConcurrentAtomicSuite[Double, AtomicDouble]( @@ -735,7 +815,8 @@ object ConcurrentAtomicDoubleLeft64Java7Suite Left64, x => x.toDouble, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicShortLeft64Java7Suite extends ConcurrentAtomicSuite[Short, AtomicShort]( @@ -743,7 +824,8 @@ object ConcurrentAtomicShortLeft64Java7Suite Left64, x => x.toShort, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicByteLeft64Java7Suite extends ConcurrentAtomicSuite[Byte, AtomicByte]( @@ -751,7 +833,8 @@ object ConcurrentAtomicByteLeft64Java7Suite Left64, x => x.toByte, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicCharLeft64Java7Suite extends ConcurrentAtomicSuite[Char, AtomicChar]( @@ -759,7 +842,8 @@ object ConcurrentAtomicCharLeft64Java7Suite Left64, x => x.toChar, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicIntLeft64Java7Suite extends ConcurrentAtomicSuite[Int, AtomicInt]( @@ -767,7 +851,8 @@ object ConcurrentAtomicIntLeft64Java7Suite Left64, x => x, x => x, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicLongLeft64Java7Suite extends ConcurrentAtomicSuite[Long, AtomicLong]( @@ -775,7 +860,8 @@ object ConcurrentAtomicLongLeft64Java7Suite Left64, x => x.toLong, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) // -- Right64 (Java 7) @@ -785,7 +871,8 @@ object ConcurrentAtomicAnyRight64Java7Suite Right64, x => x.toString, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicBooleanRight64Java7Suite extends ConcurrentAtomicBooleanSuite(Right64, allowPlatformIntrinsics = false) @@ -796,7 +883,8 @@ object ConcurrentAtomicNumberAnyRight64Java7Suite Right64, x => BigInt(x), x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicFloatRight64Java7Suite extends ConcurrentAtomicSuite[Float, AtomicFloat]( @@ -804,7 +892,8 @@ object ConcurrentAtomicFloatRight64Java7Suite Right64, x => x.toFloat, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicDoubleRight64Java7Suite extends ConcurrentAtomicSuite[Double, AtomicDouble]( @@ -812,7 +901,8 @@ object ConcurrentAtomicDoubleRight64Java7Suite Right64, x => x.toDouble, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicShortRight64Java7Suite extends ConcurrentAtomicSuite[Short, AtomicShort]( @@ -820,7 +910,8 @@ object ConcurrentAtomicShortRight64Java7Suite Right64, x => x.toShort, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicByteRight64Java7Suite extends ConcurrentAtomicSuite[Byte, AtomicByte]( @@ -828,7 +919,8 @@ object ConcurrentAtomicByteRight64Java7Suite Right64, x => x.toByte, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicCharRight64Java7Suite extends ConcurrentAtomicSuite[Char, AtomicChar]( @@ -836,7 +928,8 @@ object ConcurrentAtomicCharRight64Java7Suite Right64, x => x.toChar, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicIntRight64Java7Suite extends ConcurrentAtomicSuite[Int, AtomicInt]( @@ -844,7 +937,8 @@ object ConcurrentAtomicIntRight64Java7Suite Right64, x => x, x => x, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicLongRight64Java7Suite extends ConcurrentAtomicSuite[Long, AtomicLong]( @@ -852,7 +946,8 @@ object ConcurrentAtomicLongRight64Java7Suite Right64, x => x.toLong, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) // -- LeftRight128 (Java 7) @@ -862,7 +957,8 @@ object ConcurrentAtomicAnyLeftRight128Java7Suite LeftRight128, x => x.toString, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicBooleanLeftRight128Java7Suite extends ConcurrentAtomicBooleanSuite(LeftRight128, allowPlatformIntrinsics = false) @@ -873,7 +969,8 @@ object ConcurrentAtomicNumberAnyLeftRight128Java7Suite LeftRight128, x => BigInt(x), x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicFloatLeftRight128Java7Suite extends ConcurrentAtomicSuite[Float, AtomicFloat]( @@ -881,7 +978,8 @@ object ConcurrentAtomicFloatLeftRight128Java7Suite LeftRight128, x => x.toFloat, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicDoubleLeftRight128Java7Suite extends ConcurrentAtomicSuite[Double, AtomicDouble]( @@ -889,7 +987,8 @@ object ConcurrentAtomicDoubleLeftRight128Java7Suite LeftRight128, x => x.toDouble, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicShortLeftRight128Java7Suite extends ConcurrentAtomicSuite[Short, AtomicShort]( @@ -897,7 +996,8 @@ object ConcurrentAtomicShortLeftRight128Java7Suite LeftRight128, x => x.toShort, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicByteLeftRight128Java7Suite extends ConcurrentAtomicSuite[Byte, AtomicByte]( @@ -905,7 +1005,8 @@ object ConcurrentAtomicByteLeftRight128Java7Suite LeftRight128, x => x.toByte, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicCharLeftRight128Java7Suite extends ConcurrentAtomicSuite[Char, AtomicChar]( @@ -913,7 +1014,8 @@ object ConcurrentAtomicCharLeftRight128Java7Suite LeftRight128, x => x.toChar, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicIntLeftRight128Java7Suite extends ConcurrentAtomicSuite[Int, AtomicInt]( @@ -921,7 +1023,8 @@ object ConcurrentAtomicIntLeftRight128Java7Suite LeftRight128, x => x, x => x, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicLongLeftRight128Java7Suite extends ConcurrentAtomicSuite[Long, AtomicLong]( @@ -929,7 +1032,8 @@ object ConcurrentAtomicLongLeftRight128Java7Suite LeftRight128, x => x.toLong, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) // -- Left128 (Java 7) @@ -939,7 +1043,8 @@ object ConcurrentAtomicAnyLeft128Java7Suite Left128, x => x.toString, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicBooleanLeft128Java7Suite extends ConcurrentAtomicBooleanSuite(Left128, allowPlatformIntrinsics = false) @@ -950,7 +1055,8 @@ object ConcurrentAtomicNumberAnyLeft128Java7Suite Left128, x => BigInt(x), x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicFloatLeft128Java7Suite extends ConcurrentAtomicSuite[Float, AtomicFloat]( @@ -958,7 +1064,8 @@ object ConcurrentAtomicFloatLeft128Java7Suite Left128, x => x.toFloat, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicDoubleLeft128Java7Suite extends ConcurrentAtomicSuite[Double, AtomicDouble]( @@ -966,7 +1073,8 @@ object ConcurrentAtomicDoubleLeft128Java7Suite Left128, x => x.toDouble, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicShortLeft128Java7Suite extends ConcurrentAtomicSuite[Short, AtomicShort]( @@ -974,7 +1082,8 @@ object ConcurrentAtomicShortLeft128Java7Suite Left128, x => x.toShort, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicByteLeft128Java7Suite extends ConcurrentAtomicSuite[Byte, AtomicByte]( @@ -982,7 +1091,8 @@ object ConcurrentAtomicByteLeft128Java7Suite Left128, x => x.toByte, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicCharLeft128Java7Suite extends ConcurrentAtomicSuite[Char, AtomicChar]( @@ -990,7 +1100,8 @@ object ConcurrentAtomicCharLeft128Java7Suite Left128, x => x.toChar, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicIntLeft128Java7Suite extends ConcurrentAtomicSuite[Int, AtomicInt]( @@ -998,7 +1109,8 @@ object ConcurrentAtomicIntLeft128Java7Suite Left128, x => x, x => x, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicLongLeft128Java7Suite extends ConcurrentAtomicSuite[Long, AtomicLong]( @@ -1006,7 +1118,8 @@ object ConcurrentAtomicLongLeft128Java7Suite Left128, x => x.toLong, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) // -- Right128 (Java 7) @@ -1016,7 +1129,8 @@ object ConcurrentAtomicAnyRight128Java7Suite Right128, x => x.toString, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicBooleanRight128Java7Suite extends ConcurrentAtomicBooleanSuite(Right128, allowPlatformIntrinsics = false) @@ -1027,7 +1141,8 @@ object ConcurrentAtomicNumberAnyRight128Java7Suite Right128, x => BigInt(x), x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicFloatRight128Java7Suite extends ConcurrentAtomicSuite[Float, AtomicFloat]( @@ -1035,7 +1150,8 @@ object ConcurrentAtomicFloatRight128Java7Suite Right128, x => x.toFloat, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicDoubleRight128Java7Suite extends ConcurrentAtomicSuite[Double, AtomicDouble]( @@ -1043,7 +1159,8 @@ object ConcurrentAtomicDoubleRight128Java7Suite Right128, x => x.toDouble, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicShortRight128Java7Suite extends ConcurrentAtomicSuite[Short, AtomicShort]( @@ -1051,7 +1168,8 @@ object ConcurrentAtomicShortRight128Java7Suite Right128, x => x.toShort, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicByteRight128Java7Suite extends ConcurrentAtomicSuite[Byte, AtomicByte]( @@ -1059,7 +1177,8 @@ object ConcurrentAtomicByteRight128Java7Suite Right128, x => x.toByte, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicCharRight128Java7Suite extends ConcurrentAtomicSuite[Char, AtomicChar]( @@ -1067,7 +1186,8 @@ object ConcurrentAtomicCharRight128Java7Suite Right128, x => x.toChar, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicIntRight128Java7Suite extends ConcurrentAtomicSuite[Int, AtomicInt]( @@ -1075,7 +1195,8 @@ object ConcurrentAtomicIntRight128Java7Suite Right128, x => x, x => x, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicLongRight128Java7Suite extends ConcurrentAtomicSuite[Long, AtomicLong]( @@ -1083,7 +1204,8 @@ object ConcurrentAtomicLongRight128Java7Suite Right128, x => x.toLong, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) // -- LeftRight256 (Java 7) @@ -1093,7 +1215,8 @@ object ConcurrentAtomicAnyLeftRight256Java7Suite LeftRight256, x => x.toString, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicBooleanLeftRight256Java7Suite extends ConcurrentAtomicBooleanSuite(LeftRight256, allowPlatformIntrinsics = false) @@ -1104,7 +1227,8 @@ object ConcurrentAtomicNumberAnyLeftRight256Java7Suite LeftRight256, x => BigInt(x), x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicFloatLeftRight256Java7Suite extends ConcurrentAtomicSuite[Float, AtomicFloat]( @@ -1112,7 +1236,8 @@ object ConcurrentAtomicFloatLeftRight256Java7Suite LeftRight256, x => x.toFloat, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicDoubleLeftRight256Java7Suite extends ConcurrentAtomicSuite[Double, AtomicDouble]( @@ -1120,7 +1245,8 @@ object ConcurrentAtomicDoubleLeftRight256Java7Suite LeftRight256, x => x.toDouble, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicShortLeftRight256Java7Suite extends ConcurrentAtomicSuite[Short, AtomicShort]( @@ -1128,7 +1254,8 @@ object ConcurrentAtomicShortLeftRight256Java7Suite LeftRight256, x => x.toShort, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicByteLeftRight256Java7Suite extends ConcurrentAtomicSuite[Byte, AtomicByte]( @@ -1136,7 +1263,8 @@ object ConcurrentAtomicByteLeftRight256Java7Suite LeftRight256, x => x.toByte, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicCharLeftRight256Java7Suite extends ConcurrentAtomicSuite[Char, AtomicChar]( @@ -1144,7 +1272,8 @@ object ConcurrentAtomicCharLeftRight256Java7Suite LeftRight256, x => x.toChar, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicIntLeftRight256Java7Suite extends ConcurrentAtomicSuite[Int, AtomicInt]( @@ -1152,7 +1281,8 @@ object ConcurrentAtomicIntLeftRight256Java7Suite LeftRight256, x => x, x => x, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) object ConcurrentAtomicLongLeftRight256Java7Suite extends ConcurrentAtomicSuite[Long, AtomicLong]( @@ -1160,4 +1290,5 @@ object ConcurrentAtomicLongLeftRight256Java7Suite LeftRight256, x => x.toLong, x => x.toInt, - allowPlatformIntrinsics = false) + allowPlatformIntrinsics = false + ) diff --git a/monix-execution/shared/src/main/scala_3.0-/monix/execution/misc/HygieneUtilMacros.scala b/monix-execution/atomic/shared/src/main/scala-2/monix/execution/internal/HygieneUtilMacros.scala similarity index 88% rename from monix-execution/shared/src/main/scala_3.0-/monix/execution/misc/HygieneUtilMacros.scala rename to monix-execution/atomic/shared/src/main/scala-2/monix/execution/internal/HygieneUtilMacros.scala index a152f8b22..1e444a13d 100644 --- a/monix-execution/shared/src/main/scala_3.0-/monix/execution/misc/HygieneUtilMacros.scala +++ b/monix-execution/atomic/shared/src/main/scala-2/monix/execution/internal/HygieneUtilMacros.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,12 +15,12 @@ * limitations under the License. */ -package monix.execution.misc +package monix.execution.atomic.internal import scala.reflect.macros.whitebox /** Utilities for macro-hygiene. */ -trait HygieneUtilMacros { +private[atomic] trait HygieneUtilMacros { val c: whitebox.Context import c.universe._ @@ -35,7 +35,7 @@ trait HygieneUtilMacros { /** Returns true if the given expressions are either * stable symbols or clean functions, false otherwise. */ - def isClean(es: c.Expr[_]*): Boolean = + def isClean(es: c.Expr[?]*): Boolean = es.forall { _.tree match { case t @ Ident(_: TermName) if t.symbol.asTerm.isStable => true diff --git a/monix-execution/shared/src/main/scala_3.0-/monix/execution/misc/InlineMacros.scala b/monix-execution/atomic/shared/src/main/scala-2/monix/execution/internal/InlineMacros.scala similarity index 84% rename from monix-execution/shared/src/main/scala_3.0-/monix/execution/misc/InlineMacros.scala rename to monix-execution/atomic/shared/src/main/scala-2/monix/execution/internal/InlineMacros.scala index c246fd6d1..d608d1d87 100644 --- a/monix-execution/shared/src/main/scala_3.0-/monix/execution/misc/InlineMacros.scala +++ b/monix-execution/atomic/shared/src/main/scala-2/monix/execution/internal/InlineMacros.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,11 +15,11 @@ * limitations under the License. */ -package monix.execution.misc +package monix.execution.atomic.internal import scala.reflect.macros.whitebox -trait InlineMacros { +private[atomic] trait InlineMacros { val c: whitebox.Context import c.universe._ @@ -47,7 +47,7 @@ trait InlineMacros { case i @ Ident(_) if i.name == symbol => value case tt: TypeTree if tt.original != null => - //super.transform(TypeTree().setOriginal(transform(tt.original))) + // super.transform(TypeTree().setOriginal(transform(tt.original))) super.transform(c.universe.internal.setOriginal(TypeTree(), transform(tt.original))) case _ => super.transform(tree) @@ -60,13 +60,15 @@ trait InlineMacros { override def transform(tree: Tree): Tree = tree match { case Apply(Select(Function(params, body), ApplyName), args) => - params.zip(args).foldLeft(body) { case (b, (param, arg)) => - inlineSymbol(param.name, b, arg) + params.zip(args).foldLeft(body) { + case (b, (param, arg)) => + inlineSymbol(param.name, b, arg) } case Apply(Function(params, body), args) => - params.zip(args).foldLeft(body) { case (b, (param, arg)) => - inlineSymbol(param.name, b, arg) + params.zip(args).foldLeft(body) { + case (b, (param, arg)) => + inlineSymbol(param.name, b, arg) } case _ => @@ -93,11 +95,13 @@ trait InlineMacros { tree match { case UnApply( Apply(Select(qualifier, nme.unapply | nme.unapplySeq), List(Ident(nme.SELECTOR_DUMMY))), - args) => + args + ) => Apply(transform(qualifier), transformTrees(args)) case UnApply( Apply(TypeApply(Select(qualifier, nme.unapply | nme.unapplySeq), _), List(Ident(nme.SELECTOR_DUMMY))), - args) => + args + ) => Apply(transform(qualifier), transformTrees(args)) case t => t } diff --git a/monix-execution/shared/src/main/scala_3.0-/monix/execution/misc/test/TestBox.scala b/monix-execution/atomic/shared/src/main/scala-2/monix/execution/internal/TestBox.scala similarity index 80% rename from monix-execution/shared/src/main/scala_3.0-/monix/execution/misc/test/TestBox.scala rename to monix-execution/atomic/shared/src/main/scala-2/monix/execution/internal/TestBox.scala index 71134cbb7..21f96a9ab 100644 --- a/monix-execution/shared/src/main/scala_3.0-/monix/execution/misc/test/TestBox.scala +++ b/monix-execution/atomic/shared/src/main/scala-2/monix/execution/internal/TestBox.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,15 +15,14 @@ * limitations under the License. */ -package monix.execution.misc.test +package monix.execution.atomic.internal -import monix.execution.misc.{HygieneUtilMacros, InlineMacros} import scala.reflect.macros.whitebox /** Represents a boxed value, to be used in the testing * of [[InlineMacros]]. */ -private[execution] final case class TestBox[A](value: A) { +private[atomic] final case class TestBox[A](value: A) { def map[B](f: A => B): TestBox[B] = macro TestBox.Macros.mapMacroImpl[A, B] def collect[B](f: PartialFunction[A, B]): TestBox[B] = macro TestBox.Macros.mapMacroImpl[A, B] } @@ -31,15 +30,13 @@ private[execution] final case class TestBox[A](value: A) { /** Represents a boxed value, to be used in the testing * of [[InlineMacros]]. */ -private[execution] object TestBox { +private[atomic] object TestBox { class Macros(override val c: whitebox.Context) extends InlineMacros with HygieneUtilMacros { import c.universe._ - def mapMacroImpl[A: c.WeakTypeTag, B: c.WeakTypeTag](f: c.Expr[A => B]): c.Expr[TestBox[B]] = { - + def mapMacroImpl[A, B](f: c.Expr[A => B]): c.Expr[TestBox[B]] = { val selfExpr = c.Expr[TestBox[A]](c.prefix.tree) - val tree = if (util.isClean(f)) { q""" @@ -52,7 +49,6 @@ private[execution] object TestBox { TestBox($fn($selfExpr.value)) """ } - inlineAndReset[TestBox[B]](tree) } } diff --git a/monix-execution/shared/src/main/scala_3.0-/monix/execution/misc/test/TestInlineMacros.scala b/monix-execution/atomic/shared/src/main/scala-2/monix/execution/internal/TestInlineMacros.scala similarity index 97% rename from monix-execution/shared/src/main/scala_3.0-/monix/execution/misc/test/TestInlineMacros.scala rename to monix-execution/atomic/shared/src/main/scala-2/monix/execution/internal/TestInlineMacros.scala index 60222586d..f5bf0f34b 100644 --- a/monix-execution/shared/src/main/scala_3.0-/monix/execution/misc/test/TestInlineMacros.scala +++ b/monix-execution/atomic/shared/src/main/scala-2/monix/execution/internal/TestInlineMacros.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,12 +15,11 @@ * limitations under the License. */ -package monix.execution.misc.test +package monix.execution.atomic.internal -import monix.execution.misc._ import scala.reflect.macros.whitebox -private[execution] object TestInlineMacros { +private[atomic] object TestInlineMacros { def testInlineSingleArg(): Either[String, Unit] = macro Macros.testInlineSingleArg diff --git a/monix-execution/shared/src/main/scala/monix/execution/atomic/PaddingStrategy.scala b/monix-execution/atomic/shared/src/main/scala/monix/execution/atomic/PaddingStrategy.scala similarity index 96% rename from monix-execution/shared/src/main/scala/monix/execution/atomic/PaddingStrategy.scala rename to monix-execution/atomic/shared/src/main/scala/monix/execution/atomic/PaddingStrategy.scala index 022af8cb6..9c9c30783 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/atomic/PaddingStrategy.scala +++ b/monix-execution/atomic/shared/src/main/scala/monix/execution/atomic/PaddingStrategy.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,8 +32,9 @@ package monix.execution.atomic * import monix.execution.atomic.Atomic * import monix.execution.atomic.PaddingStrategy.Right64 * - * val paddedAtomic = Atomic.withPadding(10, Right64) - * }}} + * val paddedAtomic = Atomic.withPadding(10, Right64) + * val _ = paddedAtomic.get() + * }}} * * @see [[PaddingStrategy.NoPadding]] * @see [[PaddingStrategy.Left64]] diff --git a/monix-execution/atomic/shared/src/main/scala/monix/execution/atomic/internal/AtomicDocs.scala b/monix-execution/atomic/shared/src/main/scala/monix/execution/atomic/internal/AtomicDocs.scala new file mode 100644 index 000000000..eb18e0eaa --- /dev/null +++ b/monix-execution/atomic/shared/src/main/scala/monix/execution/atomic/internal/AtomicDocs.scala @@ -0,0 +1,272 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.execution.atomic +package internal + +/** + * + * @define atomicGetDesc Get the current value persisted by this atomic + * reference. + * + * This is a "volatile read", with all visibility guarantees that come + * from that. + * + * @define atomicSetDesc Stores the given value in the atomic reference. + * + * This is a "volatile write", with all visibility guarantees that come + * with it. For garbage-collecting purposes, but without the strong + * visibility guarantees, you might want to use [[lazySet]]. + * + * @define atomicGetAndSetDesc Sets the given value and returns + * the value visible just prior to the update. + * + * This is an atomic operation that's equivalent to: + * {{{ + * import monix.execution.atomic._ + * + * def getAndSet[A](ref: Atomic[A], update: A): A = { + * val current = ref.get() + * if (!ref.compareAndSet(current, update)) + * getAndSet(ref, update) // update failed, repeat! + * else + * current + * } + * + * val ref = Atomic(0) + * val _ = getAndSet(ref, 1) + * }}} + * + * NOTE — on top of the JVM this operation is a platform intrinsic, + * meaning that it's more efficient than a `compareAndSet`-driven loop. + * Therefore it isn't just a shortcut. If you can describe your logic + * in terms of `getAndSet`, instead of `compareAndSet`, then you should, + * but you'll also find this to be more challenging 😉 + * + * @define atomicGetAndSetParam the value that's going to be stored in + * the atomic reference once the transaction succeeds. + * + * @define atomicGetAndSetReturn the old value that was visible in the + * atomic reference, prior to the succeeding update. + * + * @define atomicLazySetDesc Eventually sets to the given value. + * + * Equivalent with [[set]], but on top of the JVM this operation isn't a + * volatile write, and thus has more relaxed visibility guarantees. For + * nullifying values, in order to allow garbage collection, this method is + * more efficient and should be prefered. But only if you know what you're + * doing, otherwise just use normal [[set]]. + * + * @define compareAndSetDesc Does a compare-and-set operation on the + * current value. For more info, checkout the related + * [[https://en.wikipedia.org/wiki/Compare-and-swap Compare-and-swap Wikipedia page]]. + * + * It's an atomic, worry-free, but low-level operation. Use only if + * you know what you're doing. + * + * Sample: {{{ + * import monix.execution.atomic._ + * import scala.collection.immutable.Queue + * + * class ConcurrentQueue0[A](ref: Atomic[Queue[A]]) { + * def enqueue(value: A): Unit = { + * val current = ref.get() + * val update = current.enqueue(value) + * if (!ref.compareAndSet(current, update)) + * enqueue(value) // transaction failed, retry! + * } + * + * def dequeue(): Option[A] = { + * val current = ref.get() + * if (current.isEmpty) + * None + * else { + * val (elem, update) = current.dequeue + * if (!ref.compareAndSet(current, update)) + * dequeue() // transaction failed, retry! + * else + * Some(elem) + * } + * } + * } + * + * val q0 = new ConcurrentQueue0[Int](Atomic(Queue.empty[Int])) + * q0.enqueue(1) + * val _ = q0.dequeue() + * }}} + * + * @define atomicBestPractices BEST PRACTICES: + * + * (1) state stored in this atomic reference MUST BE immutable, or + * treated as such. Storing mutable data in an atomic reference + * doesn't work — unless you understand Java's memory model, and if + * you have to wonder, then you don't. + * + * (2) in `compareAndSet`-driven loops, transformation/update functions + * get repeated, so those update functions MUST BE pure. If you have + * to trigger side-effects, then trigger them only AFTER the update + * has succeeded, not before or during the update. Failure to do so + * risks repeating those side-effects more than once. Working with + * an atomic reference is very unlike working with plain locks / + * / mutexes / `synchronize` blocks. + * + * (3) the operation is not based on Java's `Object#equals` or Scala's `==`. + * For primitives, value equality is going to be used, but reference + * equality is used for anything else, so ensure that the `expect` reference + * is the same as the one received via `get()`. + * + * @define atomicCASExpectParam is the value you expect to be persisted when + * the operation happens. + * + * @define atomicCASUpdateParam will be the new value, should the + * (reference) equality check for `expect` succeeds. + * + * @define atomicCASReturn either `true` in case the operation succeeded or + * `false` otherwise. If this returns `false`, it means that another + * concurrent transaction won the race and updated the atomic reference + * first, so you probably need to repeat the transaction. + * + * @define atomicTransformExtractDesc Updates this atomic reference in a + * transaction, modeled with a `compareAndSet`-driven loop. + * This "transformation" specifies a custom extractor. + * + * Sample: {{{ + * import monix.execution.atomic._ + * import scala.collection.immutable.Queue + * + * final class ConcurrentQueue1[A](state: Atomic[Queue[A]]) { + * def enqueue(value: A): Unit = + * state.transform(_.enqueue(value)) + * + * def dequeue(): Option[A] = + * state.transformAndExtract { queue => + * if (queue.isEmpty) + * (None, queue) + * else { + * val (a, update) = queue.dequeue + * (Some(a), update) + * } + * } + * } + * + * val q1 = new ConcurrentQueue1[Int](Atomic(Queue.empty[Int])) + * q1.enqueue(1) + * val _ = q1.dequeue() + * }}} + * + * @see [[getAndTransform]] and [[transformAndGet]]. + * + * @define atomicTransformBestPractices Best practices ... + * + * (1) This method will loop until the transaction succeeds in replacing + * the current value. If the atomic reference is contended by multiple + * actors trying to update the underlying value, then the transaction + * gets repeated until it succeeds. Therefore the given function + * MUST BE pure (i.e. MUST NOT do any I/O). + * + * (2) State stored in this atomic reference must be an immutable + * data-structure, or at least an effectively mutable one. If you + * mutate the state stored in this atomic reference, working with it + * is useless, as it cannot provide any transactional or visibility + * guarantees. The only updates that you should allow are the updates + * managed via this atomic reference. + * + * @define atomicTransformExtractParamF is a function that receives the + * current value as input and + * returns a tuple, representing (1) what the transaction yields + * after it succeeds and (2) what the update is. Note that this + * function mirrors `S => (A, S)`, which is the signature of the + * "state monad" 😉 + * + * @define atomicTransformExtractReturn whatever was extracted by your + * function, once the operation succeeds. + * + * @define atomicTransformAndGetDesc Updates this atomic reference in a + * transaction, modeled with a `compareAndSet`-driven loop. + * Returns the updated value. + * + * Sample: + * {{{ + * import monix.execution.atomic._ + * + * final class CountDown0(state: AtomicLong) { + * def next(): Boolean = { + * val n = state.transformAndGet(n => math.max(n - 1, 0)) + * n > 0 + * } + * } + * + * val c0 = new CountDown0(Atomic(10L)) + * val _ = c0.next() + * }}} + * + * @see [[getAndTransform]] and [[transformAndExtract]]. + * + * @define atomicTransformParam is a function that receives the current + * value as input and returns the `update` which is the new value that + * should be persisted. WARN — function could be called multiple times + * and should be pure! + * + * @define atomicTransformAndGetReturn returns the updated value, once + * the transaction succeeds. + * + * @define atomicGetAndTransformDesc Updates this atomic reference in a + * transaction, modeled with a `compareAndSet`-driven loop. + * Returns the value visible prior to the update. + * + * Sample: + * {{{ + * import monix.execution.atomic._ + * + * final class CountDown1(state: AtomicLong, n: Int) { + * def next(): Boolean = { + * val i = state.getAndTransform(i => math.min(n, i + 1)) + * i < n + * } + * } + * + * val c1 = new CountDown1(Atomic(0L), 10) + * val _ = c1.next() + * }}} + * + * @see [[transformAndGet]] and [[transformAndExtract]]. + * + * @define atomicGetAndTransformReturn the old value, that was visible + * just prior to when the update happened. + * + * @define atomicTransformDesc Updates this atomic reference in a + * transaction, modeled with a `compareAndSet`-driven loop. + * + * Similar with [[getAndTransform]], [[transformAndGet]], or + * [[transformAndExtract]], except this version doesn't return anything. + * To use whenever we only care about the side-effect. + * + * Sample: + * {{{ + * import monix.execution.atomic._ + * + * final class Counter(state: AtomicLong) { + * def mark(i: Int = 1): Unit = state.transform(_ + i) + * def get(): Long = state.get() + * } + * + * val counter = new Counter(Atomic(0L)) + * counter.mark(1) + * val _ = counter.get() + * }}} + */ +private[atomic] trait AtomicDocs { this: Atomic[?] => } diff --git a/monix-execution/shared/src/test/scala_3.0-/monix/execution/misc/InlineMacrosTest.scala b/monix-execution/atomic/shared/src/test/scala-2/monix/execution/atomic/internal/InlineMacrosTest.scala similarity index 91% rename from monix-execution/shared/src/test/scala_3.0-/monix/execution/misc/InlineMacrosTest.scala rename to monix-execution/atomic/shared/src/test/scala-2/monix/execution/atomic/internal/InlineMacrosTest.scala index 8a492bec7..47cb9f0d1 100644 --- a/monix-execution/shared/src/test/scala_3.0-/monix/execution/misc/InlineMacrosTest.scala +++ b/monix-execution/atomic/shared/src/test/scala-2/monix/execution/atomic/internal/InlineMacrosTest.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,14 +15,15 @@ * limitations under the License. */ -package monix.execution.misc +package monix.execution.atomic.internal import minitest.SimpleTestSuite -import monix.execution.exceptions.DummyException -import monix.execution.misc.test.{TestBox, TestInlineMacros} import scala.util.control.NonFatal +import scala.annotation.unused object InlineMacrosTest extends SimpleTestSuite { + class DummyException(msg: String) extends RuntimeException(msg) + test("inline a function code gen") { val result = TestInlineMacros.testInlineSingleArg() result match { @@ -91,7 +92,7 @@ object InlineMacrosTest extends SimpleTestSuite { val box = TestBox(1) val mapped = box.map { def incr = 1 - x: Int => x + incr + (x: Int) => x + incr } assertEquals(mapped, TestBox(2)) @@ -114,8 +115,8 @@ object InlineMacrosTest extends SimpleTestSuite { test("Inline NonFatal clause") { val box = TestBox(1) - val dummy = DummyException("dummy") - def increment(x: Int): Int = throw dummy + val dummy = new DummyException("dummy") + def increment(@unused x: Int): Int = throw dummy val mapped = box.map { x => try increment(x) diff --git a/monix-execution/shared/src/test/scala/monix/execution/atomic/AtomicBuilderSuite.scala b/monix-execution/atomic/shared/src/test/scala/monix/execution/atomic/AtomicBuilderSuite.scala similarity index 96% rename from monix-execution/shared/src/test/scala/monix/execution/atomic/AtomicBuilderSuite.scala rename to monix-execution/atomic/shared/src/test/scala/monix/execution/atomic/AtomicBuilderSuite.scala index 020be9b31..684772160 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/atomic/AtomicBuilderSuite.scala +++ b/monix-execution/atomic/shared/src/test/scala/monix/execution/atomic/AtomicBuilderSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/test/scala/monix/execution/atomic/AtomicNumberSuite.scala b/monix-execution/atomic/shared/src/test/scala/monix/execution/atomic/AtomicNumberSuite.scala similarity index 92% rename from monix-execution/shared/src/test/scala/monix/execution/atomic/AtomicNumberSuite.scala rename to monix-execution/atomic/shared/src/test/scala/monix/execution/atomic/AtomicNumberSuite.scala index 0b64b22f8..7ab59fe9e 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/atomic/AtomicNumberSuite.scala +++ b/monix-execution/atomic/shared/src/test/scala/monix/execution/atomic/AtomicNumberSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,7 +28,8 @@ abstract class AtomicNumberSuite[A, R <: AtomicNumber[A]]( minValue: A, hasOverflow: Boolean = true, allowPlatformIntrinsics: Boolean, - allowUnsafe: Boolean)(implicit ev: Numeric[A]) + allowUnsafe: Boolean +)(implicit ev: Numeric[A]) extends SimpleTestSuite { def Atomic(initial: A): R = { @@ -348,7 +349,8 @@ abstract class AtomicDoubleSuite(strategy: PaddingStrategy, allowPlatformIntrins Double.MinValue, hasOverflow = false, allowPlatformIntrinsics, - allowUnsafe) { + allowUnsafe + ) { test("should store MinPositiveValue, NaN, NegativeInfinity, PositiveInfinity") { assert(Atomic(Double.MinPositiveValue).get() == Double.MinPositiveValue) @@ -367,7 +369,8 @@ abstract class AtomicFloatSuite(strategy: PaddingStrategy, allowPlatformIntrinsi Float.MinValue, hasOverflow = false, allowPlatformIntrinsics, - allowUnsafe) { + allowUnsafe + ) { test("should store MinPositiveValue, NaN, NegativeInfinity, PositiveInfinity") { assert(Atomic(Float.MinPositiveValue).get() == Float.MinPositiveValue) @@ -391,7 +394,8 @@ object AtomicLongNoPaddingSuite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicIntNoPaddingSuite extends AtomicNumberSuite[Int, AtomicInt]( @@ -401,7 +405,8 @@ object AtomicIntNoPaddingSuite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicShortNoPaddingSuite extends AtomicNumberSuite[Short, AtomicShort]( @@ -411,7 +416,8 @@ object AtomicShortNoPaddingSuite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicByteNoPaddingSuite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -421,7 +427,8 @@ object AtomicByteNoPaddingSuite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicCharNoPaddingSuite extends AtomicNumberSuite[Char, AtomicChar]( @@ -431,7 +438,8 @@ object AtomicCharNoPaddingSuite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicNumberAnyNoPaddingSuite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -441,7 +449,8 @@ object AtomicNumberAnyNoPaddingSuite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) // -- Left64 (Java 8) @@ -456,7 +465,8 @@ object AtomicLongLeft64Suite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicIntLeft64Suite extends AtomicNumberSuite[Int, AtomicInt]( @@ -466,7 +476,8 @@ object AtomicIntLeft64Suite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicShortLeft64Suite extends AtomicNumberSuite[Short, AtomicShort]( @@ -476,7 +487,8 @@ object AtomicShortLeft64Suite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicByteLeft64Suite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -486,7 +498,8 @@ object AtomicByteLeft64Suite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicCharLeft64Suite extends AtomicNumberSuite[Char, AtomicChar]( @@ -496,7 +509,8 @@ object AtomicCharLeft64Suite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicNumberAnyLeft64Suite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -506,7 +520,8 @@ object AtomicNumberAnyLeft64Suite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) // -- Right64 (Java 8) @@ -521,7 +536,8 @@ object AtomicLongRight64Suite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicIntRight64Suite extends AtomicNumberSuite[Int, AtomicInt]( @@ -531,7 +547,8 @@ object AtomicIntRight64Suite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicShortRight64Suite extends AtomicNumberSuite[Short, AtomicShort]( @@ -541,7 +558,8 @@ object AtomicShortRight64Suite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicByteRight64Suite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -551,7 +569,8 @@ object AtomicByteRight64Suite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicCharRight64Suite extends AtomicNumberSuite[Char, AtomicChar]( @@ -561,7 +580,8 @@ object AtomicCharRight64Suite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicNumberAnyRight64Suite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -571,7 +591,8 @@ object AtomicNumberAnyRight64Suite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) // -- LeftRight128 (Java 8) @@ -588,7 +609,8 @@ object AtomicLongLeftRight128Suite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicIntLeftRight128Suite extends AtomicNumberSuite[Int, AtomicInt]( @@ -598,7 +620,8 @@ object AtomicIntLeftRight128Suite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicShortLeftRight128Suite extends AtomicNumberSuite[Short, AtomicShort]( @@ -608,7 +631,8 @@ object AtomicShortLeftRight128Suite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicByteLeftRight128Suite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -618,7 +642,8 @@ object AtomicByteLeftRight128Suite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicCharLeftRight128Suite extends AtomicNumberSuite[Char, AtomicChar]( @@ -628,7 +653,8 @@ object AtomicCharLeftRight128Suite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicNumberAnyLeftRight128Suite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -638,7 +664,8 @@ object AtomicNumberAnyLeftRight128Suite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) // -- Left128 (Java 8) @@ -653,7 +680,8 @@ object AtomicLongLeft128Suite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicIntLeft128Suite extends AtomicNumberSuite[Int, AtomicInt]( @@ -663,7 +691,8 @@ object AtomicIntLeft128Suite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicShortLeft128Suite extends AtomicNumberSuite[Short, AtomicShort]( @@ -673,7 +702,8 @@ object AtomicShortLeft128Suite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicByteLeft128Suite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -683,7 +713,8 @@ object AtomicByteLeft128Suite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicCharLeft128Suite extends AtomicNumberSuite[Char, AtomicChar]( @@ -693,7 +724,8 @@ object AtomicCharLeft128Suite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicNumberAnyLeft128Suite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -703,7 +735,8 @@ object AtomicNumberAnyLeft128Suite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) // -- Right128 (Java 8) @@ -718,7 +751,8 @@ object AtomicLongRight128Suite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicIntRight128Suite extends AtomicNumberSuite[Int, AtomicInt]( @@ -728,7 +762,8 @@ object AtomicIntRight128Suite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicShortRight128Suite extends AtomicNumberSuite[Short, AtomicShort]( @@ -738,7 +773,8 @@ object AtomicShortRight128Suite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicByteRight128Suite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -748,7 +784,8 @@ object AtomicByteRight128Suite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicCharRight128Suite extends AtomicNumberSuite[Char, AtomicChar]( @@ -758,7 +795,8 @@ object AtomicCharRight128Suite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicNumberAnyRight128Suite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -768,7 +806,8 @@ object AtomicNumberAnyRight128Suite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) // -- LeftRight256 (Java 8) @@ -785,7 +824,8 @@ object AtomicLongLeftRight256Suite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicIntLeftRight256Suite extends AtomicNumberSuite[Int, AtomicInt]( @@ -795,7 +835,8 @@ object AtomicIntLeftRight256Suite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicShortLeftRight256Suite extends AtomicNumberSuite[Short, AtomicShort]( @@ -805,7 +846,8 @@ object AtomicShortLeftRight256Suite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicByteLeftRight256Suite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -815,7 +857,8 @@ object AtomicByteLeftRight256Suite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicCharLeftRight256Suite extends AtomicNumberSuite[Char, AtomicChar]( @@ -825,7 +868,8 @@ object AtomicCharLeftRight256Suite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicNumberAnyLeftRight256Suite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -835,7 +879,8 @@ object AtomicNumberAnyLeftRight256Suite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) // ------------------ Java 7 @@ -854,7 +899,8 @@ object AtomicLongNoPaddingJava7Suite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicIntNoPaddingJava7Suite extends AtomicNumberSuite[Int, AtomicInt]( @@ -864,7 +910,8 @@ object AtomicIntNoPaddingJava7Suite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicShortNoPaddingJava7Suite extends AtomicNumberSuite[Short, AtomicShort]( @@ -874,7 +921,8 @@ object AtomicShortNoPaddingJava7Suite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicByteNoPaddingJava7Suite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -884,7 +932,8 @@ object AtomicByteNoPaddingJava7Suite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicCharNoPaddingJava7Suite extends AtomicNumberSuite[Char, AtomicChar]( @@ -894,7 +943,8 @@ object AtomicCharNoPaddingJava7Suite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicNumberAnyNoPaddingJava7Suite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -904,7 +954,8 @@ object AtomicNumberAnyNoPaddingJava7Suite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) // -- Left64 (Java 7) @@ -920,7 +971,8 @@ object AtomicLongLeft64Java7Suite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicIntLeft64Java7Suite extends AtomicNumberSuite[Int, AtomicInt]( @@ -930,7 +982,8 @@ object AtomicIntLeft64Java7Suite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicShortLeft64Java7Suite extends AtomicNumberSuite[Short, AtomicShort]( @@ -940,7 +993,8 @@ object AtomicShortLeft64Java7Suite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicByteLeft64Java7Suite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -950,7 +1004,8 @@ object AtomicByteLeft64Java7Suite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicCharLeft64Java7Suite extends AtomicNumberSuite[Char, AtomicChar]( @@ -960,7 +1015,8 @@ object AtomicCharLeft64Java7Suite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicNumberAnyLeft64Java7Suite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -970,7 +1026,8 @@ object AtomicNumberAnyLeft64Java7Suite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) // -- Right64 (Java 7) @@ -987,7 +1044,8 @@ object AtomicLongRight64Java7Suite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicIntRight64Java7Suite extends AtomicNumberSuite[Int, AtomicInt]( @@ -997,7 +1055,8 @@ object AtomicIntRight64Java7Suite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicShortRight64Java7Suite extends AtomicNumberSuite[Short, AtomicShort]( @@ -1007,7 +1066,8 @@ object AtomicShortRight64Java7Suite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicByteRight64Java7Suite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -1017,7 +1077,8 @@ object AtomicByteRight64Java7Suite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicCharRight64Java7Suite extends AtomicNumberSuite[Char, AtomicChar]( @@ -1027,7 +1088,8 @@ object AtomicCharRight64Java7Suite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicNumberAnyRight64Java7Suite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1037,7 +1099,8 @@ object AtomicNumberAnyRight64Java7Suite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) // -- LeftRight128 (Java 7) @@ -1054,7 +1117,8 @@ object AtomicLongLeftRight128Java7Suite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicIntLeftRight128Java7Suite extends AtomicNumberSuite[Int, AtomicInt]( @@ -1064,7 +1128,8 @@ object AtomicIntLeftRight128Java7Suite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicShortLeftRight128Java7Suite extends AtomicNumberSuite[Short, AtomicShort]( @@ -1074,7 +1139,8 @@ object AtomicShortLeftRight128Java7Suite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicByteLeftRight128Java7Suite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -1084,7 +1150,8 @@ object AtomicByteLeftRight128Java7Suite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicCharLeftRight128Java7Suite extends AtomicNumberSuite[Char, AtomicChar]( @@ -1094,7 +1161,8 @@ object AtomicCharLeftRight128Java7Suite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicNumberAnyLeftRight128Java7Suite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1104,7 +1172,8 @@ object AtomicNumberAnyLeftRight128Java7Suite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) // -- Left128 (Java 7) @@ -1121,7 +1190,8 @@ object AtomicLongLeft128Java7Suite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicIntLeft128Java7Suite extends AtomicNumberSuite[Int, AtomicInt]( @@ -1131,7 +1201,8 @@ object AtomicIntLeft128Java7Suite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicShortLeft128Java7Suite extends AtomicNumberSuite[Short, AtomicShort]( @@ -1141,7 +1212,8 @@ object AtomicShortLeft128Java7Suite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicByteLeft128Java7Suite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -1151,7 +1223,8 @@ object AtomicByteLeft128Java7Suite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicCharLeft128Java7Suite extends AtomicNumberSuite[Char, AtomicChar]( @@ -1161,7 +1234,8 @@ object AtomicCharLeft128Java7Suite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicNumberAnyLeft128Java7Suite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1171,7 +1245,8 @@ object AtomicNumberAnyLeft128Java7Suite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) // -- Right128 (Java 7) @@ -1188,7 +1263,8 @@ object AtomicLongRight128Java7Suite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicIntRight128Java7Suite extends AtomicNumberSuite[Int, AtomicInt]( @@ -1198,7 +1274,8 @@ object AtomicIntRight128Java7Suite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicShortRight128Java7Suite extends AtomicNumberSuite[Short, AtomicShort]( @@ -1208,7 +1285,8 @@ object AtomicShortRight128Java7Suite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicByteRight128Java7Suite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -1218,7 +1296,8 @@ object AtomicByteRight128Java7Suite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicCharRight128Java7Suite extends AtomicNumberSuite[Char, AtomicChar]( @@ -1228,7 +1307,8 @@ object AtomicCharRight128Java7Suite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicNumberAnyRight128Java7Suite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1238,7 +1318,8 @@ object AtomicNumberAnyRight128Java7Suite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) // -- LeftRight256 (Java 7) @@ -1255,7 +1336,8 @@ object AtomicLongLeftRight256Java7Suite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicIntLeftRight256Java7Suite extends AtomicNumberSuite[Int, AtomicInt]( @@ -1265,7 +1347,8 @@ object AtomicIntLeftRight256Java7Suite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicShortLeftRight256Java7Suite extends AtomicNumberSuite[Short, AtomicShort]( @@ -1275,7 +1358,8 @@ object AtomicShortLeftRight256Java7Suite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicByteLeftRight256Java7Suite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -1285,7 +1369,8 @@ object AtomicByteLeftRight256Java7Suite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicCharLeftRight256Java7Suite extends AtomicNumberSuite[Char, AtomicChar]( @@ -1295,7 +1380,8 @@ object AtomicCharLeftRight256Java7Suite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object AtomicNumberAnyLeftRight256Java7Suite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1305,7 +1391,8 @@ object AtomicNumberAnyLeftRight256Java7Suite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) // ------------------ Java X @@ -1324,7 +1411,8 @@ object AtomicLongNoPaddingJavaXSuite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicIntNoPaddingJavaXSuite extends AtomicNumberSuite[Int, AtomicInt]( @@ -1334,7 +1422,8 @@ object AtomicIntNoPaddingJavaXSuite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicShortNoPaddingJavaXSuite extends AtomicNumberSuite[Short, AtomicShort]( @@ -1344,7 +1433,8 @@ object AtomicShortNoPaddingJavaXSuite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicByteNoPaddingJavaXSuite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -1354,7 +1444,8 @@ object AtomicByteNoPaddingJavaXSuite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicCharNoPaddingJavaXSuite extends AtomicNumberSuite[Char, AtomicChar]( @@ -1364,7 +1455,8 @@ object AtomicCharNoPaddingJavaXSuite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicNumberAnyNoPaddingJavaXSuite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1374,7 +1466,8 @@ object AtomicNumberAnyNoPaddingJavaXSuite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) // -- Left64 (Java X) @@ -1391,7 +1484,8 @@ object AtomicLongLeft64JavaXSuite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicIntLeft64JavaXSuite extends AtomicNumberSuite[Int, AtomicInt]( @@ -1401,7 +1495,8 @@ object AtomicIntLeft64JavaXSuite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicShortLeft64JavaXSuite extends AtomicNumberSuite[Short, AtomicShort]( @@ -1411,7 +1506,8 @@ object AtomicShortLeft64JavaXSuite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicByteLeft64JavaXSuite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -1421,7 +1517,8 @@ object AtomicByteLeft64JavaXSuite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicCharLeft64JavaXSuite extends AtomicNumberSuite[Char, AtomicChar]( @@ -1431,7 +1528,8 @@ object AtomicCharLeft64JavaXSuite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicNumberAnyLeft64JavaXSuite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1441,7 +1539,8 @@ object AtomicNumberAnyLeft64JavaXSuite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) // -- Right64 (Java X) @@ -1458,7 +1557,8 @@ object AtomicLongRight64JavaXSuite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicIntRight64JavaXSuite extends AtomicNumberSuite[Int, AtomicInt]( @@ -1468,7 +1568,8 @@ object AtomicIntRight64JavaXSuite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicShortRight64JavaXSuite extends AtomicNumberSuite[Short, AtomicShort]( @@ -1478,7 +1579,8 @@ object AtomicShortRight64JavaXSuite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicByteRight64JavaXSuite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -1488,7 +1590,8 @@ object AtomicByteRight64JavaXSuite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicCharRight64JavaXSuite extends AtomicNumberSuite[Char, AtomicChar]( @@ -1498,7 +1601,8 @@ object AtomicCharRight64JavaXSuite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicNumberAnyRight64JavaXSuite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1508,7 +1612,8 @@ object AtomicNumberAnyRight64JavaXSuite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) // -- LeftRight128 (Java X) @@ -1525,7 +1630,8 @@ object AtomicLongLeftRight128JavaXSuite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicIntLeftRight128JavaXSuite extends AtomicNumberSuite[Int, AtomicInt]( @@ -1535,7 +1641,8 @@ object AtomicIntLeftRight128JavaXSuite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicShortLeftRight128JavaXSuite extends AtomicNumberSuite[Short, AtomicShort]( @@ -1545,7 +1652,8 @@ object AtomicShortLeftRight128JavaXSuite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicByteLeftRight128JavaXSuite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -1555,7 +1663,8 @@ object AtomicByteLeftRight128JavaXSuite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicCharLeftRight128JavaXSuite extends AtomicNumberSuite[Char, AtomicChar]( @@ -1565,7 +1674,8 @@ object AtomicCharLeftRight128JavaXSuite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicNumberAnyLeftRight128JavaXSuite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1575,7 +1685,8 @@ object AtomicNumberAnyLeftRight128JavaXSuite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) // -- Left128 (Java X) @@ -1592,7 +1703,8 @@ object AtomicLongLeft128JavaXSuite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicIntLeft128JavaXSuite extends AtomicNumberSuite[Int, AtomicInt]( @@ -1602,7 +1714,8 @@ object AtomicIntLeft128JavaXSuite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicShortLeft128JavaXSuite extends AtomicNumberSuite[Short, AtomicShort]( @@ -1612,7 +1725,8 @@ object AtomicShortLeft128JavaXSuite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicByteLeft128JavaXSuite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -1622,7 +1736,8 @@ object AtomicByteLeft128JavaXSuite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicCharLeft128JavaXSuite extends AtomicNumberSuite[Char, AtomicChar]( @@ -1632,7 +1747,8 @@ object AtomicCharLeft128JavaXSuite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicNumberAnyLeft128JavaXSuite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1642,7 +1758,8 @@ object AtomicNumberAnyLeft128JavaXSuite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) // -- Right128 (Java X) @@ -1659,7 +1776,8 @@ object AtomicLongRight128JavaXSuite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicIntRight128JavaXSuite extends AtomicNumberSuite[Int, AtomicInt]( @@ -1669,7 +1787,8 @@ object AtomicIntRight128JavaXSuite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicShortRight128JavaXSuite extends AtomicNumberSuite[Short, AtomicShort]( @@ -1679,7 +1798,8 @@ object AtomicShortRight128JavaXSuite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicByteRight128JavaXSuite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -1689,7 +1809,8 @@ object AtomicByteRight128JavaXSuite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicCharRight128JavaXSuite extends AtomicNumberSuite[Char, AtomicChar]( @@ -1699,7 +1820,8 @@ object AtomicCharRight128JavaXSuite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicNumberAnyRight128JavaXSuite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1709,7 +1831,8 @@ object AtomicNumberAnyRight128JavaXSuite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) // -- LeftRight256 (Java X) @@ -1726,7 +1849,8 @@ object AtomicLongLeftRight256JavaXSuite Long.MaxValue, Long.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicIntLeftRight256JavaXSuite extends AtomicNumberSuite[Int, AtomicInt]( @@ -1736,7 +1860,8 @@ object AtomicIntLeftRight256JavaXSuite Int.MaxValue, Int.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicShortLeftRight256JavaXSuite extends AtomicNumberSuite[Short, AtomicShort]( @@ -1746,7 +1871,8 @@ object AtomicShortLeftRight256JavaXSuite Short.MaxValue, Short.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicByteLeftRight256JavaXSuite extends AtomicNumberSuite[Byte, AtomicByte]( @@ -1756,7 +1882,8 @@ object AtomicByteLeftRight256JavaXSuite Byte.MaxValue, Byte.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicCharLeftRight256JavaXSuite extends AtomicNumberSuite[Char, AtomicChar]( @@ -1766,7 +1893,8 @@ object AtomicCharLeftRight256JavaXSuite Char.MaxValue, Char.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object AtomicNumberAnyLeftRight256JavaXSuite extends AtomicNumberSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1776,4 +1904,5 @@ object AtomicNumberAnyLeftRight256JavaXSuite BoxedLong.MaxValue, BoxedLong.MinValue, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) diff --git a/monix-execution/shared/src/test/scala/monix/execution/atomic/BoxedLong.scala b/monix-execution/atomic/shared/src/test/scala/monix/execution/atomic/BoxedLong.scala similarity index 94% rename from monix-execution/shared/src/test/scala/monix/execution/atomic/BoxedLong.scala rename to monix-execution/atomic/shared/src/test/scala/monix/execution/atomic/BoxedLong.scala index e48a9908c..2f615b151 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/atomic/BoxedLong.scala +++ b/monix-execution/atomic/shared/src/test/scala/monix/execution/atomic/BoxedLong.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,6 +17,8 @@ package monix.execution.atomic +import scala.annotation.nowarn + case class BoxedLong(value: Long) object BoxedLong { @@ -44,6 +46,8 @@ object BoxedLong { BoxedLong(x.value - y.value) def compare(x: BoxedLong, y: BoxedLong): Int = x.value.compareTo(y.value) + + @nowarn def parseString(str: String): Option[BoxedLong] = try Some(BoxedLong(str.toLong)) catch { case _: NumberFormatException => None } diff --git a/monix-execution/shared/src/test/scala/monix/execution/atomic/GenericAtomicSuite.scala b/monix-execution/atomic/shared/src/test/scala/monix/execution/atomic/GenericAtomicSuite.scala similarity index 90% rename from monix-execution/shared/src/test/scala/monix/execution/atomic/GenericAtomicSuite.scala rename to monix-execution/atomic/shared/src/test/scala/monix/execution/atomic/GenericAtomicSuite.scala index 2c23d76b1..7ac63712a 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/atomic/GenericAtomicSuite.scala +++ b/monix-execution/atomic/shared/src/test/scala/monix/execution/atomic/GenericAtomicSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,8 +28,8 @@ abstract class GenericAtomicSuite[A, R <: Atomic[A]]( valueFromInt: Int => A, valueToInt: A => Int, allowPlatformIntrinsics: Boolean, - allowUnsafe: Boolean) - extends SimpleTestSuite { + allowUnsafe: Boolean +) extends SimpleTestSuite { def Atomic(initial: A): R = { if (allowUnsafe) @@ -292,7 +292,8 @@ object GenericAtomicAnyNoPadding x => x.toString, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicBooleanNoPadding extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -301,7 +302,8 @@ object GenericAtomicBooleanNoPadding x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicNumberAnyNoPadding extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -310,7 +312,8 @@ object GenericAtomicNumberAnyNoPadding x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicFloatNoPadding extends GenericAtomicSuite[Float, AtomicFloat]( @@ -319,7 +322,8 @@ object GenericAtomicFloatNoPadding x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicDoubleNoPadding extends GenericAtomicSuite[Double, AtomicDouble]( @@ -328,7 +332,8 @@ object GenericAtomicDoubleNoPadding x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicShortNoPadding extends GenericAtomicSuite[Short, AtomicShort]( @@ -337,7 +342,8 @@ object GenericAtomicShortNoPadding x => x.toShort, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicByteNoPadding extends GenericAtomicSuite[Byte, AtomicByte]( @@ -346,7 +352,8 @@ object GenericAtomicByteNoPadding x => x.toByte, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicCharNoPadding extends GenericAtomicSuite[Char, AtomicChar]( @@ -355,7 +362,8 @@ object GenericAtomicCharNoPadding x => x.toChar, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicIntNoPadding extends GenericAtomicSuite[Int, AtomicInt]( @@ -364,7 +372,8 @@ object GenericAtomicIntNoPadding x => x, x => x, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicLongNoPadding extends GenericAtomicSuite[Long, AtomicLong]( @@ -373,7 +382,8 @@ object GenericAtomicLongNoPadding x => x.toLong, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) // -- Left64 (Java 8) @@ -384,7 +394,8 @@ object GenericAtomicAnyLeft64 x => x.toString, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicBooleanLeft64 extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -393,7 +404,8 @@ object GenericAtomicBooleanLeft64 x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicNumberAnyLeft64 extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -402,7 +414,8 @@ object GenericAtomicNumberAnyLeft64 x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicFloatLeft64 extends GenericAtomicSuite[Float, AtomicFloat]( @@ -411,7 +424,8 @@ object GenericAtomicFloatLeft64 x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicDoubleLeft64 extends GenericAtomicSuite[Double, AtomicDouble]( @@ -420,7 +434,8 @@ object GenericAtomicDoubleLeft64 x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicShortLeft64 extends GenericAtomicSuite[Short, AtomicShort]( @@ -429,7 +444,8 @@ object GenericAtomicShortLeft64 x => x.toShort, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicByteLeft64 extends GenericAtomicSuite[Byte, AtomicByte]( @@ -438,7 +454,8 @@ object GenericAtomicByteLeft64 x => x.toByte, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicCharLeft64 extends GenericAtomicSuite[Char, AtomicChar]( @@ -447,7 +464,8 @@ object GenericAtomicCharLeft64 x => x.toChar, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicIntLeft64 extends GenericAtomicSuite[Int, AtomicInt]( @@ -456,7 +474,8 @@ object GenericAtomicIntLeft64 x => x, x => x, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicLongLeft64 extends GenericAtomicSuite[Long, AtomicLong]( @@ -465,7 +484,8 @@ object GenericAtomicLongLeft64 x => x.toLong, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) // -- Right64 (Java 8) @@ -476,7 +496,8 @@ object GenericAtomicAnyRight64 x => x.toString, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicBooleanRight64 extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -485,7 +506,8 @@ object GenericAtomicBooleanRight64 x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicNumberAnyRight64 extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -494,7 +516,8 @@ object GenericAtomicNumberAnyRight64 x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicFloatRight64 extends GenericAtomicSuite[Float, AtomicFloat]( @@ -503,7 +526,8 @@ object GenericAtomicFloatRight64 x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicDoubleRight64 extends GenericAtomicSuite[Double, AtomicDouble]( @@ -512,7 +536,8 @@ object GenericAtomicDoubleRight64 x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicShortRight64 extends GenericAtomicSuite[Short, AtomicShort]( @@ -521,7 +546,8 @@ object GenericAtomicShortRight64 x => x.toShort, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicByteRight64 extends GenericAtomicSuite[Byte, AtomicByte]( @@ -530,7 +556,8 @@ object GenericAtomicByteRight64 x => x.toByte, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicCharRight64 extends GenericAtomicSuite[Char, AtomicChar]( @@ -539,7 +566,8 @@ object GenericAtomicCharRight64 x => x.toChar, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicIntRight64 extends GenericAtomicSuite[Int, AtomicInt]( @@ -548,7 +576,8 @@ object GenericAtomicIntRight64 x => x, x => x, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicLongRight64 extends GenericAtomicSuite[Long, AtomicLong]( @@ -557,7 +586,8 @@ object GenericAtomicLongRight64 x => x.toLong, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) // -- LeftRight128 (Java 8) @@ -568,7 +598,8 @@ object GenericAtomicAnyLeftRight128 x => x.toString, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicBooleanLeftRight128 extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -577,7 +608,8 @@ object GenericAtomicBooleanLeftRight128 x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicNumberAnyLeftRight128 extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -586,7 +618,8 @@ object GenericAtomicNumberAnyLeftRight128 x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicFloatLeftRight128 extends GenericAtomicSuite[Float, AtomicFloat]( @@ -595,7 +628,8 @@ object GenericAtomicFloatLeftRight128 x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicDoubleLeftRight128 extends GenericAtomicSuite[Double, AtomicDouble]( @@ -604,7 +638,8 @@ object GenericAtomicDoubleLeftRight128 x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicShortLeftRight128 extends GenericAtomicSuite[Short, AtomicShort]( @@ -613,7 +648,8 @@ object GenericAtomicShortLeftRight128 x => x.toShort, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicByteLeftRight128 extends GenericAtomicSuite[Byte, AtomicByte]( @@ -622,7 +658,8 @@ object GenericAtomicByteLeftRight128 x => x.toByte, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicCharLeftRight128 extends GenericAtomicSuite[Char, AtomicChar]( @@ -631,7 +668,8 @@ object GenericAtomicCharLeftRight128 x => x.toChar, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicIntLeftRight128 extends GenericAtomicSuite[Int, AtomicInt]( @@ -640,7 +678,8 @@ object GenericAtomicIntLeftRight128 x => x, x => x, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicLongLeftRight128 extends GenericAtomicSuite[Long, AtomicLong]( @@ -649,7 +688,8 @@ object GenericAtomicLongLeftRight128 x => x.toLong, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) // -- Left128 (Java 8) @@ -660,7 +700,8 @@ object GenericAtomicAnyLeft128 x => x.toString, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicBooleanLeft128 extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -669,7 +710,8 @@ object GenericAtomicBooleanLeft128 x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicNumberAnyLeft128 extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -678,7 +720,8 @@ object GenericAtomicNumberAnyLeft128 x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicFloatLeft128 extends GenericAtomicSuite[Float, AtomicFloat]( @@ -687,7 +730,8 @@ object GenericAtomicFloatLeft128 x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicDoubleLeft128 extends GenericAtomicSuite[Double, AtomicDouble]( @@ -696,7 +740,8 @@ object GenericAtomicDoubleLeft128 x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicShortLeft128 extends GenericAtomicSuite[Short, AtomicShort]( @@ -705,7 +750,8 @@ object GenericAtomicShortLeft128 x => x.toShort, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicByteLeft128 extends GenericAtomicSuite[Byte, AtomicByte]( @@ -714,7 +760,8 @@ object GenericAtomicByteLeft128 x => x.toByte, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicCharLeft128 extends GenericAtomicSuite[Char, AtomicChar]( @@ -723,7 +770,8 @@ object GenericAtomicCharLeft128 x => x.toChar, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicIntLeft128 extends GenericAtomicSuite[Int, AtomicInt]( @@ -732,7 +780,8 @@ object GenericAtomicIntLeft128 x => x, x => x, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicLongLeft128 extends GenericAtomicSuite[Long, AtomicLong]( @@ -741,7 +790,8 @@ object GenericAtomicLongLeft128 x => x.toLong, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) // -- Right128 (Java 8) @@ -752,7 +802,8 @@ object GenericAtomicAnyRight128 x => x.toString, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicBooleanRight128 extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -761,7 +812,8 @@ object GenericAtomicBooleanRight128 x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicNumberAnyRight128 extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -770,7 +822,8 @@ object GenericAtomicNumberAnyRight128 x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicFloatRight128 extends GenericAtomicSuite[Float, AtomicFloat]( @@ -779,7 +832,8 @@ object GenericAtomicFloatRight128 x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicDoubleRight128 extends GenericAtomicSuite[Double, AtomicDouble]( @@ -788,7 +842,8 @@ object GenericAtomicDoubleRight128 x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicShortRight128 extends GenericAtomicSuite[Short, AtomicShort]( @@ -797,7 +852,8 @@ object GenericAtomicShortRight128 x => x.toShort, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicByteRight128 extends GenericAtomicSuite[Byte, AtomicByte]( @@ -806,7 +862,8 @@ object GenericAtomicByteRight128 x => x.toByte, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicCharRight128 extends GenericAtomicSuite[Char, AtomicChar]( @@ -815,7 +872,8 @@ object GenericAtomicCharRight128 x => x.toChar, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicIntRight128 extends GenericAtomicSuite[Int, AtomicInt]( @@ -824,7 +882,8 @@ object GenericAtomicIntRight128 x => x, x => x, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicLongRight128 extends GenericAtomicSuite[Long, AtomicLong]( @@ -833,7 +892,8 @@ object GenericAtomicLongRight128 x => x.toLong, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) // -- LeftRight256 (Java 8) @@ -844,7 +904,8 @@ object GenericAtomicAnyLeftRight256 x => x.toString, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicBooleanLeftRight256 extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -853,7 +914,8 @@ object GenericAtomicBooleanLeftRight256 x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicNumberAnyLeftRight256 extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -862,7 +924,8 @@ object GenericAtomicNumberAnyLeftRight256 x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicFloatLeftRight256 extends GenericAtomicSuite[Float, AtomicFloat]( @@ -871,7 +934,8 @@ object GenericAtomicFloatLeftRight256 x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicDoubleLeftRight256 extends GenericAtomicSuite[Double, AtomicDouble]( @@ -880,7 +944,8 @@ object GenericAtomicDoubleLeftRight256 x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicShortLeftRight256 extends GenericAtomicSuite[Short, AtomicShort]( @@ -889,7 +954,8 @@ object GenericAtomicShortLeftRight256 x => x.toShort, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicByteLeftRight256 extends GenericAtomicSuite[Byte, AtomicByte]( @@ -898,7 +964,8 @@ object GenericAtomicByteLeftRight256 x => x.toByte, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicCharLeftRight256 extends GenericAtomicSuite[Char, AtomicChar]( @@ -907,7 +974,8 @@ object GenericAtomicCharLeftRight256 x => x.toChar, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicIntLeftRight256 extends GenericAtomicSuite[Int, AtomicInt]( @@ -916,7 +984,8 @@ object GenericAtomicIntLeftRight256 x => x, x => x, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicLongLeftRight256 extends GenericAtomicSuite[Long, AtomicLong]( @@ -925,7 +994,8 @@ object GenericAtomicLongLeftRight256 x => x.toLong, x => x.toInt, allowPlatformIntrinsics = true, - allowUnsafe = true) + allowUnsafe = true + ) // ----------------- Java 7 @@ -938,7 +1008,8 @@ object GenericAtomicAnyNoPaddingJava7Suite x => x.toString, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicBooleanNoPaddingJava7Suite extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -947,7 +1018,8 @@ object GenericAtomicBooleanNoPaddingJava7Suite x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicNumberAnyNoPaddingJava7Suite extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -956,7 +1028,8 @@ object GenericAtomicNumberAnyNoPaddingJava7Suite x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicFloatNoPaddingJava7Suite extends GenericAtomicSuite[Float, AtomicFloat]( @@ -965,7 +1038,8 @@ object GenericAtomicFloatNoPaddingJava7Suite x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicDoubleNoPaddingJava7Suite extends GenericAtomicSuite[Double, AtomicDouble]( @@ -974,7 +1048,8 @@ object GenericAtomicDoubleNoPaddingJava7Suite x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicShortNoPaddingJava7Suite extends GenericAtomicSuite[Short, AtomicShort]( @@ -983,7 +1058,8 @@ object GenericAtomicShortNoPaddingJava7Suite x => x.toShort, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicByteNoPaddingJava7Suite extends GenericAtomicSuite[Byte, AtomicByte]( @@ -992,7 +1068,8 @@ object GenericAtomicByteNoPaddingJava7Suite x => x.toByte, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicCharNoPaddingJava7Suite extends GenericAtomicSuite[Char, AtomicChar]( @@ -1001,7 +1078,8 @@ object GenericAtomicCharNoPaddingJava7Suite x => x.toChar, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicIntNoPaddingJava7Suite extends GenericAtomicSuite[Int, AtomicInt]( @@ -1010,7 +1088,8 @@ object GenericAtomicIntNoPaddingJava7Suite x => x, x => x, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicLongNoPaddingJava7Suite extends GenericAtomicSuite[Long, AtomicLong]( @@ -1019,7 +1098,8 @@ object GenericAtomicLongNoPaddingJava7Suite x => x.toLong, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) // -- Left64 (Java 7) @@ -1030,7 +1110,8 @@ object GenericAtomicAnyLeft64Java7Suite x => x.toString, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicBooleanLeft64Java7Suite extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -1039,7 +1120,8 @@ object GenericAtomicBooleanLeft64Java7Suite x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicNumberAnyLeft64Java7Suite extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1048,7 +1130,8 @@ object GenericAtomicNumberAnyLeft64Java7Suite x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicFloatLeft64Java7Suite extends GenericAtomicSuite[Float, AtomicFloat]( @@ -1057,7 +1140,8 @@ object GenericAtomicFloatLeft64Java7Suite x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicDoubleLeft64Java7Suite extends GenericAtomicSuite[Double, AtomicDouble]( @@ -1066,7 +1150,8 @@ object GenericAtomicDoubleLeft64Java7Suite x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicShortLeft64Java7Suite extends GenericAtomicSuite[Short, AtomicShort]( @@ -1075,7 +1160,8 @@ object GenericAtomicShortLeft64Java7Suite x => x.toShort, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicByteLeft64Java7Suite extends GenericAtomicSuite[Byte, AtomicByte]( @@ -1084,7 +1170,8 @@ object GenericAtomicByteLeft64Java7Suite x => x.toByte, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicCharLeft64Java7Suite extends GenericAtomicSuite[Char, AtomicChar]( @@ -1093,7 +1180,8 @@ object GenericAtomicCharLeft64Java7Suite x => x.toChar, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicIntLeft64Java7Suite extends GenericAtomicSuite[Int, AtomicInt]( @@ -1102,7 +1190,8 @@ object GenericAtomicIntLeft64Java7Suite x => x, x => x, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicLongLeft64Java7Suite extends GenericAtomicSuite[Long, AtomicLong]( @@ -1111,7 +1200,8 @@ object GenericAtomicLongLeft64Java7Suite x => x.toLong, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) // -- Right64 (Java 7) @@ -1122,7 +1212,8 @@ object GenericAtomicAnyRight64Java7Suite x => x.toString, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicBooleanRight64Java7Suite extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -1131,7 +1222,8 @@ object GenericAtomicBooleanRight64Java7Suite x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicNumberAnyRight64Java7Suite extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1140,7 +1232,8 @@ object GenericAtomicNumberAnyRight64Java7Suite x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicFloatRight64Java7Suite extends GenericAtomicSuite[Float, AtomicFloat]( @@ -1149,7 +1242,8 @@ object GenericAtomicFloatRight64Java7Suite x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicDoubleRight64Java7Suite extends GenericAtomicSuite[Double, AtomicDouble]( @@ -1158,7 +1252,8 @@ object GenericAtomicDoubleRight64Java7Suite x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicShortRight64Java7Suite extends GenericAtomicSuite[Short, AtomicShort]( @@ -1167,7 +1262,8 @@ object GenericAtomicShortRight64Java7Suite x => x.toShort, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicByteRight64Java7Suite extends GenericAtomicSuite[Byte, AtomicByte]( @@ -1176,7 +1272,8 @@ object GenericAtomicByteRight64Java7Suite x => x.toByte, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicCharRight64Java7Suite extends GenericAtomicSuite[Char, AtomicChar]( @@ -1185,7 +1282,8 @@ object GenericAtomicCharRight64Java7Suite x => x.toChar, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicIntRight64Java7Suite extends GenericAtomicSuite[Int, AtomicInt]( @@ -1194,7 +1292,8 @@ object GenericAtomicIntRight64Java7Suite x => x, x => x, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicLongRight64Java7Suite extends GenericAtomicSuite[Long, AtomicLong]( @@ -1203,7 +1302,8 @@ object GenericAtomicLongRight64Java7Suite x => x.toLong, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) // -- LeftRight128 (Java 7) @@ -1214,7 +1314,8 @@ object GenericAtomicAnyLeftRight128Java7Suite x => x.toString, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicBooleanLeftRight128Java7Suite extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -1223,7 +1324,8 @@ object GenericAtomicBooleanLeftRight128Java7Suite x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicNumberAnyLeftRight128Java7Suite extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1232,7 +1334,8 @@ object GenericAtomicNumberAnyLeftRight128Java7Suite x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicFloatLeftRight128Java7Suite extends GenericAtomicSuite[Float, AtomicFloat]( @@ -1241,7 +1344,8 @@ object GenericAtomicFloatLeftRight128Java7Suite x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicDoubleLeftRight128Java7Suite extends GenericAtomicSuite[Double, AtomicDouble]( @@ -1250,7 +1354,8 @@ object GenericAtomicDoubleLeftRight128Java7Suite x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicShortLeftRight128Java7Suite extends GenericAtomicSuite[Short, AtomicShort]( @@ -1259,7 +1364,8 @@ object GenericAtomicShortLeftRight128Java7Suite x => x.toShort, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicByteLeftRight128Java7Suite extends GenericAtomicSuite[Byte, AtomicByte]( @@ -1268,7 +1374,8 @@ object GenericAtomicByteLeftRight128Java7Suite x => x.toByte, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicCharLeftRight128Java7Suite extends GenericAtomicSuite[Char, AtomicChar]( @@ -1277,7 +1384,8 @@ object GenericAtomicCharLeftRight128Java7Suite x => x.toChar, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicIntLeftRight128Java7Suite extends GenericAtomicSuite[Int, AtomicInt]( @@ -1286,7 +1394,8 @@ object GenericAtomicIntLeftRight128Java7Suite x => x, x => x, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicLongLeftRight128Java7Suite extends GenericAtomicSuite[Long, AtomicLong]( @@ -1295,7 +1404,8 @@ object GenericAtomicLongLeftRight128Java7Suite x => x.toLong, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) // -- Left128 (Java 7) @@ -1306,7 +1416,8 @@ object GenericAtomicAnyLeft128Java7Suite x => x.toString, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicBooleanLeft128Java7Suite extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -1315,7 +1426,8 @@ object GenericAtomicBooleanLeft128Java7Suite x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicNumberAnyLeft128Java7Suite extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1324,7 +1436,8 @@ object GenericAtomicNumberAnyLeft128Java7Suite x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicFloatLeft128Java7Suite extends GenericAtomicSuite[Float, AtomicFloat]( @@ -1333,7 +1446,8 @@ object GenericAtomicFloatLeft128Java7Suite x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicDoubleLeft128Java7Suite extends GenericAtomicSuite[Double, AtomicDouble]( @@ -1342,7 +1456,8 @@ object GenericAtomicDoubleLeft128Java7Suite x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicShortLeft128Java7Suite extends GenericAtomicSuite[Short, AtomicShort]( @@ -1351,7 +1466,8 @@ object GenericAtomicShortLeft128Java7Suite x => x.toShort, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicByteLeft128Java7Suite extends GenericAtomicSuite[Byte, AtomicByte]( @@ -1360,7 +1476,8 @@ object GenericAtomicByteLeft128Java7Suite x => x.toByte, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicCharLeft128Java7Suite extends GenericAtomicSuite[Char, AtomicChar]( @@ -1369,7 +1486,8 @@ object GenericAtomicCharLeft128Java7Suite x => x.toChar, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicIntLeft128Java7Suite extends GenericAtomicSuite[Int, AtomicInt]( @@ -1378,7 +1496,8 @@ object GenericAtomicIntLeft128Java7Suite x => x, x => x, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicLongLeft128Java7Suite extends GenericAtomicSuite[Long, AtomicLong]( @@ -1387,7 +1506,8 @@ object GenericAtomicLongLeft128Java7Suite x => x.toLong, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) // -- Right128 (Java 7) @@ -1398,7 +1518,8 @@ object GenericAtomicAnyRight128Java7Suite x => x.toString, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicBooleanRight128Java7Suite extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -1407,7 +1528,8 @@ object GenericAtomicBooleanRight128Java7Suite x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicNumberAnyRight128Java7Suite extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1416,7 +1538,8 @@ object GenericAtomicNumberAnyRight128Java7Suite x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicFloatRight128Java7Suite extends GenericAtomicSuite[Float, AtomicFloat]( @@ -1425,7 +1548,8 @@ object GenericAtomicFloatRight128Java7Suite x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicDoubleRight128Java7Suite extends GenericAtomicSuite[Double, AtomicDouble]( @@ -1434,7 +1558,8 @@ object GenericAtomicDoubleRight128Java7Suite x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicShortRight128Java7Suite extends GenericAtomicSuite[Short, AtomicShort]( @@ -1443,7 +1568,8 @@ object GenericAtomicShortRight128Java7Suite x => x.toShort, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicByteRight128Java7Suite extends GenericAtomicSuite[Byte, AtomicByte]( @@ -1452,7 +1578,8 @@ object GenericAtomicByteRight128Java7Suite x => x.toByte, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicCharRight128Java7Suite extends GenericAtomicSuite[Char, AtomicChar]( @@ -1461,7 +1588,8 @@ object GenericAtomicCharRight128Java7Suite x => x.toChar, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicIntRight128Java7Suite extends GenericAtomicSuite[Int, AtomicInt]( @@ -1470,7 +1598,8 @@ object GenericAtomicIntRight128Java7Suite x => x, x => x, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicLongRight128Java7Suite extends GenericAtomicSuite[Long, AtomicLong]( @@ -1479,7 +1608,8 @@ object GenericAtomicLongRight128Java7Suite x => x.toLong, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) // -- LeftRight256 (Java 7) @@ -1490,7 +1620,8 @@ object GenericAtomicAnyLeftRight256Java7Suite x => x.toString, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicBooleanLeftRight256Java7Suite extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -1499,7 +1630,8 @@ object GenericAtomicBooleanLeftRight256Java7Suite x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicNumberAnyLeftRight256Java7Suite extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1508,7 +1640,8 @@ object GenericAtomicNumberAnyLeftRight256Java7Suite x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicFloatLeftRight256Java7Suite extends GenericAtomicSuite[Float, AtomicFloat]( @@ -1517,7 +1650,8 @@ object GenericAtomicFloatLeftRight256Java7Suite x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicDoubleLeftRight256Java7Suite extends GenericAtomicSuite[Double, AtomicDouble]( @@ -1526,7 +1660,8 @@ object GenericAtomicDoubleLeftRight256Java7Suite x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicShortLeftRight256Java7Suite extends GenericAtomicSuite[Short, AtomicShort]( @@ -1535,7 +1670,8 @@ object GenericAtomicShortLeftRight256Java7Suite x => x.toShort, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicByteLeftRight256Java7Suite extends GenericAtomicSuite[Byte, AtomicByte]( @@ -1544,7 +1680,8 @@ object GenericAtomicByteLeftRight256Java7Suite x => x.toByte, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicCharLeftRight256Java7Suite extends GenericAtomicSuite[Char, AtomicChar]( @@ -1553,7 +1690,8 @@ object GenericAtomicCharLeftRight256Java7Suite x => x.toChar, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicIntLeftRight256Java7Suite extends GenericAtomicSuite[Int, AtomicInt]( @@ -1562,7 +1700,8 @@ object GenericAtomicIntLeftRight256Java7Suite x => x, x => x, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) object GenericAtomicLongLeftRight256Java7Suite extends GenericAtomicSuite[Long, AtomicLong]( @@ -1571,7 +1710,8 @@ object GenericAtomicLongLeftRight256Java7Suite x => x.toLong, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = true) + allowUnsafe = true + ) // ----------------- Java X @@ -1584,7 +1724,8 @@ object GenericAtomicAnyNoPaddingJavaXSuite x => x.toString, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicBooleanNoPaddingJavaXSuite extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -1593,7 +1734,8 @@ object GenericAtomicBooleanNoPaddingJavaXSuite x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicNumberAnyNoPaddingJavaXSuite extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1602,7 +1744,8 @@ object GenericAtomicNumberAnyNoPaddingJavaXSuite x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicFloatNoPaddingJavaXSuite extends GenericAtomicSuite[Float, AtomicFloat]( @@ -1611,7 +1754,8 @@ object GenericAtomicFloatNoPaddingJavaXSuite x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicDoubleNoPaddingJavaXSuite extends GenericAtomicSuite[Double, AtomicDouble]( @@ -1620,7 +1764,8 @@ object GenericAtomicDoubleNoPaddingJavaXSuite x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicShortNoPaddingJavaXSuite extends GenericAtomicSuite[Short, AtomicShort]( @@ -1629,7 +1774,8 @@ object GenericAtomicShortNoPaddingJavaXSuite x => x.toShort, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicByteNoPaddingJavaXSuite extends GenericAtomicSuite[Byte, AtomicByte]( @@ -1638,7 +1784,8 @@ object GenericAtomicByteNoPaddingJavaXSuite x => x.toByte, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicCharNoPaddingJavaXSuite extends GenericAtomicSuite[Char, AtomicChar]( @@ -1647,7 +1794,8 @@ object GenericAtomicCharNoPaddingJavaXSuite x => x.toChar, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicIntNoPaddingJavaXSuite extends GenericAtomicSuite[Int, AtomicInt]( @@ -1656,7 +1804,8 @@ object GenericAtomicIntNoPaddingJavaXSuite x => x, x => x, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicLongNoPaddingJavaXSuite extends GenericAtomicSuite[Long, AtomicLong]( @@ -1665,7 +1814,8 @@ object GenericAtomicLongNoPaddingJavaXSuite x => x.toLong, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) // -- Left64 (Java X) @@ -1676,7 +1826,8 @@ object GenericAtomicAnyLeft64JavaXSuite x => x.toString, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicBooleanLeft64JavaXSuite extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -1685,7 +1836,8 @@ object GenericAtomicBooleanLeft64JavaXSuite x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicNumberAnyLeft64JavaXSuite extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1694,7 +1846,8 @@ object GenericAtomicNumberAnyLeft64JavaXSuite x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicFloatLeft64JavaXSuite extends GenericAtomicSuite[Float, AtomicFloat]( @@ -1703,7 +1856,8 @@ object GenericAtomicFloatLeft64JavaXSuite x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicDoubleLeft64JavaXSuite extends GenericAtomicSuite[Double, AtomicDouble]( @@ -1712,7 +1866,8 @@ object GenericAtomicDoubleLeft64JavaXSuite x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicShortLeft64JavaXSuite extends GenericAtomicSuite[Short, AtomicShort]( @@ -1721,7 +1876,8 @@ object GenericAtomicShortLeft64JavaXSuite x => x.toShort, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicByteLeft64JavaXSuite extends GenericAtomicSuite[Byte, AtomicByte]( @@ -1730,7 +1886,8 @@ object GenericAtomicByteLeft64JavaXSuite x => x.toByte, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicCharLeft64JavaXSuite extends GenericAtomicSuite[Char, AtomicChar]( @@ -1739,7 +1896,8 @@ object GenericAtomicCharLeft64JavaXSuite x => x.toChar, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicIntLeft64JavaXSuite extends GenericAtomicSuite[Int, AtomicInt]( @@ -1748,7 +1906,8 @@ object GenericAtomicIntLeft64JavaXSuite x => x, x => x, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicLongLeft64JavaXSuite extends GenericAtomicSuite[Long, AtomicLong]( @@ -1757,7 +1916,8 @@ object GenericAtomicLongLeft64JavaXSuite x => x.toLong, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) // -- Right64 (Java X) @@ -1768,7 +1928,8 @@ object GenericAtomicAnyRight64JavaXSuite x => x.toString, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicBooleanRight64JavaXSuite extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -1777,7 +1938,8 @@ object GenericAtomicBooleanRight64JavaXSuite x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicNumberAnyRight64JavaXSuite extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1786,7 +1948,8 @@ object GenericAtomicNumberAnyRight64JavaXSuite x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicFloatRight64JavaXSuite extends GenericAtomicSuite[Float, AtomicFloat]( @@ -1795,7 +1958,8 @@ object GenericAtomicFloatRight64JavaXSuite x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicDoubleRight64JavaXSuite extends GenericAtomicSuite[Double, AtomicDouble]( @@ -1804,7 +1968,8 @@ object GenericAtomicDoubleRight64JavaXSuite x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicShortRight64JavaXSuite extends GenericAtomicSuite[Short, AtomicShort]( @@ -1813,7 +1978,8 @@ object GenericAtomicShortRight64JavaXSuite x => x.toShort, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicByteRight64JavaXSuite extends GenericAtomicSuite[Byte, AtomicByte]( @@ -1822,7 +1988,8 @@ object GenericAtomicByteRight64JavaXSuite x => x.toByte, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicCharRight64JavaXSuite extends GenericAtomicSuite[Char, AtomicChar]( @@ -1831,7 +1998,8 @@ object GenericAtomicCharRight64JavaXSuite x => x.toChar, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicIntRight64JavaXSuite extends GenericAtomicSuite[Int, AtomicInt]( @@ -1840,7 +2008,8 @@ object GenericAtomicIntRight64JavaXSuite x => x, x => x, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicLongRight64JavaXSuite extends GenericAtomicSuite[Long, AtomicLong]( @@ -1849,7 +2018,8 @@ object GenericAtomicLongRight64JavaXSuite x => x.toLong, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) // -- LeftRight128 (Java X) @@ -1860,7 +2030,8 @@ object GenericAtomicAnyLeftRight128JavaXSuite x => x.toString, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicBooleanLeftRight128JavaXSuite extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -1869,7 +2040,8 @@ object GenericAtomicBooleanLeftRight128JavaXSuite x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicNumberAnyLeftRight128JavaXSuite extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1878,7 +2050,8 @@ object GenericAtomicNumberAnyLeftRight128JavaXSuite x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicFloatLeftRight128JavaXSuite extends GenericAtomicSuite[Float, AtomicFloat]( @@ -1887,7 +2060,8 @@ object GenericAtomicFloatLeftRight128JavaXSuite x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicDoubleLeftRight128JavaXSuite extends GenericAtomicSuite[Double, AtomicDouble]( @@ -1896,7 +2070,8 @@ object GenericAtomicDoubleLeftRight128JavaXSuite x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicShortLeftRight128JavaXSuite extends GenericAtomicSuite[Short, AtomicShort]( @@ -1905,7 +2080,8 @@ object GenericAtomicShortLeftRight128JavaXSuite x => x.toShort, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicByteLeftRight128JavaXSuite extends GenericAtomicSuite[Byte, AtomicByte]( @@ -1914,7 +2090,8 @@ object GenericAtomicByteLeftRight128JavaXSuite x => x.toByte, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicCharLeftRight128JavaXSuite extends GenericAtomicSuite[Char, AtomicChar]( @@ -1923,7 +2100,8 @@ object GenericAtomicCharLeftRight128JavaXSuite x => x.toChar, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicIntLeftRight128JavaXSuite extends GenericAtomicSuite[Int, AtomicInt]( @@ -1932,7 +2110,8 @@ object GenericAtomicIntLeftRight128JavaXSuite x => x, x => x, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicLongLeftRight128JavaXSuite extends GenericAtomicSuite[Long, AtomicLong]( @@ -1941,7 +2120,8 @@ object GenericAtomicLongLeftRight128JavaXSuite x => x.toLong, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) // -- Left128 (Java X) @@ -1952,7 +2132,8 @@ object GenericAtomicAnyLeft128JavaXSuite x => x.toString, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicBooleanLeft128JavaXSuite extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -1961,7 +2142,8 @@ object GenericAtomicBooleanLeft128JavaXSuite x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicNumberAnyLeft128JavaXSuite extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -1970,7 +2152,8 @@ object GenericAtomicNumberAnyLeft128JavaXSuite x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicFloatLeft128JavaXSuite extends GenericAtomicSuite[Float, AtomicFloat]( @@ -1979,7 +2162,8 @@ object GenericAtomicFloatLeft128JavaXSuite x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicDoubleLeft128JavaXSuite extends GenericAtomicSuite[Double, AtomicDouble]( @@ -1988,7 +2172,8 @@ object GenericAtomicDoubleLeft128JavaXSuite x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicShortLeft128JavaXSuite extends GenericAtomicSuite[Short, AtomicShort]( @@ -1997,7 +2182,8 @@ object GenericAtomicShortLeft128JavaXSuite x => x.toShort, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicByteLeft128JavaXSuite extends GenericAtomicSuite[Byte, AtomicByte]( @@ -2006,7 +2192,8 @@ object GenericAtomicByteLeft128JavaXSuite x => x.toByte, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicCharLeft128JavaXSuite extends GenericAtomicSuite[Char, AtomicChar]( @@ -2015,7 +2202,8 @@ object GenericAtomicCharLeft128JavaXSuite x => x.toChar, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicIntLeft128JavaXSuite extends GenericAtomicSuite[Int, AtomicInt]( @@ -2024,7 +2212,8 @@ object GenericAtomicIntLeft128JavaXSuite x => x, x => x, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicLongLeft128JavaXSuite extends GenericAtomicSuite[Long, AtomicLong]( @@ -2033,7 +2222,8 @@ object GenericAtomicLongLeft128JavaXSuite x => x.toLong, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) // -- Right128 (Java X) @@ -2044,7 +2234,8 @@ object GenericAtomicAnyRight128JavaXSuite x => x.toString, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicBooleanRight128JavaXSuite extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -2053,7 +2244,8 @@ object GenericAtomicBooleanRight128JavaXSuite x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicNumberAnyRight128JavaXSuite extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -2062,7 +2254,8 @@ object GenericAtomicNumberAnyRight128JavaXSuite x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicFloatRight128JavaXSuite extends GenericAtomicSuite[Float, AtomicFloat]( @@ -2071,7 +2264,8 @@ object GenericAtomicFloatRight128JavaXSuite x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicDoubleRight128JavaXSuite extends GenericAtomicSuite[Double, AtomicDouble]( @@ -2080,7 +2274,8 @@ object GenericAtomicDoubleRight128JavaXSuite x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicShortRight128JavaXSuite extends GenericAtomicSuite[Short, AtomicShort]( @@ -2089,7 +2284,8 @@ object GenericAtomicShortRight128JavaXSuite x => x.toShort, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicByteRight128JavaXSuite extends GenericAtomicSuite[Byte, AtomicByte]( @@ -2098,7 +2294,8 @@ object GenericAtomicByteRight128JavaXSuite x => x.toByte, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicCharRight128JavaXSuite extends GenericAtomicSuite[Char, AtomicChar]( @@ -2107,7 +2304,8 @@ object GenericAtomicCharRight128JavaXSuite x => x.toChar, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicIntRight128JavaXSuite extends GenericAtomicSuite[Int, AtomicInt]( @@ -2116,7 +2314,8 @@ object GenericAtomicIntRight128JavaXSuite x => x, x => x, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicLongRight128JavaXSuite extends GenericAtomicSuite[Long, AtomicLong]( @@ -2125,7 +2324,8 @@ object GenericAtomicLongRight128JavaXSuite x => x.toLong, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) // -- LeftRight256 (Java X) @@ -2136,7 +2336,8 @@ object GenericAtomicAnyLeftRight256JavaXSuite x => x.toString, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicBooleanLeftRight256JavaXSuite extends GenericAtomicSuite[Boolean, AtomicBoolean]( @@ -2145,7 +2346,8 @@ object GenericAtomicBooleanLeftRight256JavaXSuite x => if (x == 1) true else false, x => if (x) 1 else 0, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicNumberAnyLeftRight256JavaXSuite extends GenericAtomicSuite[BoxedLong, AtomicNumberAny[BoxedLong]]( @@ -2154,7 +2356,8 @@ object GenericAtomicNumberAnyLeftRight256JavaXSuite x => BoxedLong(x.toLong), x => x.value.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicFloatLeftRight256JavaXSuite extends GenericAtomicSuite[Float, AtomicFloat]( @@ -2163,7 +2366,8 @@ object GenericAtomicFloatLeftRight256JavaXSuite x => x.toFloat, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicDoubleLeftRight256JavaXSuite extends GenericAtomicSuite[Double, AtomicDouble]( @@ -2172,7 +2376,8 @@ object GenericAtomicDoubleLeftRight256JavaXSuite x => x.toDouble, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicShortLeftRight256JavaXSuite extends GenericAtomicSuite[Short, AtomicShort]( @@ -2181,7 +2386,8 @@ object GenericAtomicShortLeftRight256JavaXSuite x => x.toShort, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicByteLeftRight256JavaXSuite extends GenericAtomicSuite[Byte, AtomicByte]( @@ -2190,7 +2396,8 @@ object GenericAtomicByteLeftRight256JavaXSuite x => x.toByte, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicCharLeftRight256JavaXSuite extends GenericAtomicSuite[Char, AtomicChar]( @@ -2199,7 +2406,8 @@ object GenericAtomicCharLeftRight256JavaXSuite x => x.toChar, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicIntLeftRight256JavaXSuite extends GenericAtomicSuite[Int, AtomicInt]( @@ -2208,7 +2416,8 @@ object GenericAtomicIntLeftRight256JavaXSuite x => x, x => x, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) object GenericAtomicLongLeftRight256JavaXSuite extends GenericAtomicSuite[Long, AtomicLong]( @@ -2217,4 +2426,5 @@ object GenericAtomicLongLeftRight256JavaXSuite x => x.toLong, x => x.toInt, allowPlatformIntrinsics = false, - allowUnsafe = false) + allowUnsafe = false + ) diff --git a/monix-execution/js/src/main/scala/monix/execution/cancelables/ChainedCancelable.scala b/monix-execution/js/src/main/scala/monix/execution/cancelables/ChainedCancelable.scala index c480e5377..d5acb3d61 100644 --- a/monix-execution/js/src/main/scala/monix/execution/cancelables/ChainedCancelable.scala +++ b/monix-execution/js/src/main/scala/monix/execution/cancelables/ChainedCancelable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -83,9 +83,7 @@ import monix.execution.internal.exceptions.matchError * [[SingleAssignCancelable]] for most purposes. */ final class ChainedCancelable private (private var stateRef: AnyRef) extends AssignableCancelable { - - import ChainedCancelable.{Canceled, WeakRef} - private type CC = ChainedCancelable + import ChainedCancelable.{ Canceled, WeakRef } // States of `state`: // @@ -105,7 +103,7 @@ final class ChainedCancelable private (private var stateRef: AnyRef) extends Ass case other => // $COVERAGE-OFF$ matchError(other) - // $COVERAGE-ON$ + // $COVERAGE-ON$ } } @@ -186,7 +184,7 @@ final class ChainedCancelable private (private var stateRef: AnyRef) extends Ass case other => // $COVERAGE-OFF$ matchError(other) - // $COVERAGE-ON$ + // $COVERAGE-ON$ } } } diff --git a/monix-execution/js/src/main/scala/monix/execution/internal/CancelableFutureForPlatform.scala b/monix-execution/js/src/main/scala/monix/execution/internal/CancelableFutureForPlatform.scala index 0e575728a..58fe4c7d4 100644 --- a/monix-execution/js/src/main/scala/monix/execution/internal/CancelableFutureForPlatform.scala +++ b/monix-execution/js/src/main/scala/monix/execution/internal/CancelableFutureForPlatform.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/js/src/main/scala/monix/execution/internal/DefaultUncaughtExceptionReporter.scala b/monix-execution/js/src/main/scala/monix/execution/internal/DefaultUncaughtExceptionReporter.scala index d5667d2a2..56fb7ee49 100644 --- a/monix-execution/js/src/main/scala/monix/execution/internal/DefaultUncaughtExceptionReporter.scala +++ b/monix-execution/js/src/main/scala/monix/execution/internal/DefaultUncaughtExceptionReporter.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,6 +28,5 @@ private[execution] object DefaultUncaughtExceptionReporter extends UncaughtExcep def reportFailure(e: Throwable): Unit = logger(e) - private[this] lazy val logger = - ExecutionContext.defaultReporter + private val logger = ExecutionContext.defaultReporter } diff --git a/monix-execution/js/src/main/scala/monix/execution/internal/FutureUtilsForPlatform.scala b/monix-execution/js/src/main/scala/monix/execution/internal/FutureUtilsForPlatform.scala index fcb7739bc..e0918fbc4 100644 --- a/monix-execution/js/src/main/scala/monix/execution/internal/FutureUtilsForPlatform.scala +++ b/monix-execution/js/src/main/scala/monix/execution/internal/FutureUtilsForPlatform.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/js/src/main/scala/monix/execution/internal/Platform.scala b/monix-execution/js/src/main/scala/monix/execution/internal/Platform.scala index bc2dd45a3..8aa4f09f5 100644 --- a/monix-execution/js/src/main/scala/monix/execution/internal/Platform.scala +++ b/monix-execution/js/src/main/scala/monix/execution/internal/Platform.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,6 +24,7 @@ import scala.concurrent.Awaitable import scala.concurrent.duration.Duration import scala.scalajs.js import scala.util.control.NonFatal +import scala.annotation.unused private[monix] object Platform { /** @@ -99,7 +100,7 @@ private[monix] object Platform { * This operation is only supported on top of the JVM, whereas for * JavaScript a dummy is provided. */ - def await[A](fa: Awaitable[A], timeout: Duration)(implicit permit: CanBlock): A = + def await[A](@unused fa: Awaitable[A], @unused timeout: Duration)(implicit @unused permit: CanBlock): A = throw new UnsupportedOperationException( "Blocking operations are not supported on top of JavaScript" ) @@ -128,7 +129,7 @@ private[monix] object Platform { * Useful utility that combines an `Either` result, which is what * `MonadError#attempt` returns. */ - def composeErrors(first: Throwable, second: Either[Throwable, _]): Throwable = + def composeErrors(first: Throwable, second: Either[Throwable, Any]): Throwable = second match { case Left(e2) => composeErrors(first, e2) case _ => first diff --git a/monix-execution/js/src/main/scala/monix/execution/internal/collection/JSArrayQueue.scala b/monix-execution/js/src/main/scala/monix/execution/internal/collection/JSArrayQueue.scala index 372c52b9b..f802e6dd7 100644 --- a/monix-execution/js/src/main/scala/monix/execution/internal/collection/JSArrayQueue.scala +++ b/monix-execution/js/src/main/scala/monix/execution/internal/collection/JSArrayQueue.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,10 +28,9 @@ import scala.scalajs.js private[monix] final class JSArrayQueue[A] private (_size: Int, triggerEx: Int => Throwable = null) extends EvictingQueue[A] with LowLevelConcurrentQueue[A] { - private[this] var queue = new js.Array[A]() - private[this] var offset = 0 - private[this] val bufferSize = - if (_size <= 0) 0 else nextPowerOf2(_size) + private var queue = new js.Array[A]() + private var offset = 0 + private val bufferSize = if (_size <= 0) 0 else nextPowerOf2(_size) override def capacity: Int = if (bufferSize == 0) Int.MaxValue else bufferSize @@ -53,7 +52,7 @@ private[monix] final class JSArrayQueue[A] private (_size: Int, triggerEx: Int = if (triggerEx != null) throw triggerEx(capacity) 1 // rejecting new element as we are at capacity } else { - queue.push(elem) + val _ = queue.push(elem) 0 } } diff --git a/monix-execution/js/src/main/scala/monix/execution/internal/collection/queues/LowLevelConcurrentQueueBuilders.scala b/monix-execution/js/src/main/scala/monix/execution/internal/collection/queues/LowLevelConcurrentQueueBuilders.scala index 5e95a3b01..eb90aa30a 100644 --- a/monix-execution/js/src/main/scala/monix/execution/internal/collection/queues/LowLevelConcurrentQueueBuilders.scala +++ b/monix-execution/js/src/main/scala/monix/execution/internal/collection/queues/LowLevelConcurrentQueueBuilders.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,14 +17,19 @@ package monix.execution.internal.collection.queues -import monix.execution.{BufferCapacity, ChannelType} -import monix.execution.internal.collection.{JSArrayQueue, LowLevelConcurrentQueue} +import monix.execution.{ BufferCapacity, ChannelType } +import monix.execution.internal.collection.{ JSArrayQueue, LowLevelConcurrentQueue } +import scala.annotation.unused private[internal] trait LowLevelConcurrentQueueBuilders { /** * Builds a `ConcurrentQueue` reference. */ - def apply[A](capacity: BufferCapacity, channelType: ChannelType, fenced: Boolean): LowLevelConcurrentQueue[A] = + def apply[A]( + capacity: BufferCapacity, + @unused channelType: ChannelType, + @unused fenced: Boolean + ): LowLevelConcurrentQueue[A] = capacity match { case BufferCapacity.Bounded(c) => JSArrayQueue.bounded[A](c) case BufferCapacity.Unbounded(_) => JSArrayQueue.unbounded[A] diff --git a/monix-execution/js/src/main/scala/monix/execution/misc/ThreadLocal.scala b/monix-execution/js/src/main/scala/monix/execution/misc/ThreadLocal.scala index 790f994ec..0f71c9f79 100644 --- a/monix-execution/js/src/main/scala/monix/execution/misc/ThreadLocal.scala +++ b/monix-execution/js/src/main/scala/monix/execution/misc/ThreadLocal.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,7 +31,7 @@ package monix.execution.misc * any values yet. */ final class ThreadLocal[A] private (val initial: A) { - private[this] var tl = initial + private var tl = initial /** Returns the value in the current thread's copy of this * thread-local variable. If the variable has no value for the diff --git a/monix-execution/js/src/main/scala/monix/execution/schedulers/AsyncScheduler.scala b/monix-execution/js/src/main/scala/monix/execution/schedulers/AsyncScheduler.scala index 32c4c8de7..87a50b52b 100644 --- a/monix-execution/js/src/main/scala/monix/execution/schedulers/AsyncScheduler.scala +++ b/monix-execution/js/src/main/scala/monix/execution/schedulers/AsyncScheduler.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,8 +20,8 @@ package schedulers import java.util.concurrent.TimeUnit -import monix.execution.schedulers.JSTimer.{clearTimeout, setTimeout} -import monix.execution.{ExecutionModel => ExecModel} +import monix.execution.schedulers.JSTimer.{ clearTimeout, setTimeout } +import monix.execution.{ ExecutionModel => ExecModel } import scala.concurrent.ExecutionContext import monix.execution.internal.InterceptRunnable diff --git a/monix-execution/js/src/main/scala/monix/execution/schedulers/CanBlock.scala b/monix-execution/js/src/main/scala/monix/execution/schedulers/CanBlock.scala index d244b5025..7f10f7961 100644 --- a/monix-execution/js/src/main/scala/monix/execution/schedulers/CanBlock.scala +++ b/monix-execution/js/src/main/scala/monix/execution/schedulers/CanBlock.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,6 +18,7 @@ package monix.execution.schedulers import scala.annotation.implicitNotFound +import scala.annotation.nowarn /** Marker for blocking operations that need to be disallowed on top of * JavaScript engines, or other platforms that don't support the blocking @@ -74,5 +75,7 @@ import scala.annotation.implicitNotFound @implicitNotFound( "Blocking operations aren't supported \n" + "on top of JavaScript, because it cannot block threads! \n" + - "Please use asynchronous API calls.") + "Please use asynchronous API calls." +) +@nowarn final class CanBlock private () diff --git a/monix-execution/js/src/main/scala/monix/execution/schedulers/JSTimer.scala b/monix-execution/js/src/main/scala/monix/execution/schedulers/JSTimer.scala index d0a0bd3fa..94fa83449 100644 --- a/monix-execution/js/src/main/scala/monix/execution/schedulers/JSTimer.scala +++ b/monix-execution/js/src/main/scala/monix/execution/schedulers/JSTimer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,7 +34,7 @@ private[schedulers] object JSTimer { } def clearTimeout(task: js.Dynamic): Unit = { - js.Dynamic.global.clearTimeout(task) + val _ = js.Dynamic.global.clearTimeout(task) () } } diff --git a/monix-execution/js/src/main/scala/monix/execution/schedulers/SchedulerCompanionImpl.scala b/monix-execution/js/src/main/scala/monix/execution/schedulers/SchedulerCompanionImpl.scala index 4612406c9..931448b0f 100644 --- a/monix-execution/js/src/main/scala/monix/execution/schedulers/SchedulerCompanionImpl.scala +++ b/monix-execution/js/src/main/scala/monix/execution/schedulers/SchedulerCompanionImpl.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.execution.schedulers -import monix.execution.{Scheduler, SchedulerCompanion, UncaughtExceptionReporter, ExecutionModel => ExecModel} +import monix.execution.{ ExecutionModel => ExecModel, Scheduler, SchedulerCompanion, UncaughtExceptionReporter } import org.scalajs.macrotaskexecutor.MacrotaskExecutor import scala.concurrent.ExecutionContext diff --git a/monix-execution/js/src/main/scala/monix/execution/schedulers/TrampolineExecutionContext.scala b/monix-execution/js/src/main/scala/monix/execution/schedulers/TrampolineExecutionContext.scala index b3bdfacbd..33df07bb8 100644 --- a/monix-execution/js/src/main/scala/monix/execution/schedulers/TrampolineExecutionContext.scala +++ b/monix-execution/js/src/main/scala/monix/execution/schedulers/TrampolineExecutionContext.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.execution.schedulers import monix.execution.internal.Trampoline import monix.execution.internal.Trampoline.{ForkingTrampolineEC, ImmediateTrampolineEC, TrampolineEC} -import scala.concurrent.{ExecutionContext, ExecutionContextExecutor} +import scala.concurrent.{ ExecutionContext, ExecutionContextExecutor } /** A `scala.concurrentExecutionContext` implementation * that executes runnables immediately, on the current thread, @@ -54,7 +54,7 @@ import scala.concurrent.{ExecutionContext, ExecutionContextExecutor} */ final class TrampolineExecutionContext private (underlying: TrampolineEC) extends ExecutionContextExecutor { - private[this] val trampoline = new Trampoline + private val trampoline = new Trampoline override def execute(runnable: Runnable): Unit = trampoline.execute(runnable, underlying) diff --git a/monix-execution/js/src/main/scala/org/reactivestreams/Processor.scala b/monix-execution/js/src/main/scala/org/reactivestreams/Processor.scala index bb85cf9aa..6597ceadd 100644 --- a/monix-execution/js/src/main/scala/org/reactivestreams/Processor.scala +++ b/monix-execution/js/src/main/scala/org/reactivestreams/Processor.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/js/src/main/scala/org/reactivestreams/Publisher.scala b/monix-execution/js/src/main/scala/org/reactivestreams/Publisher.scala index f8ebed184..e34704734 100644 --- a/monix-execution/js/src/main/scala/org/reactivestreams/Publisher.scala +++ b/monix-execution/js/src/main/scala/org/reactivestreams/Publisher.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -43,5 +43,5 @@ trait Publisher[T] extends Any { * @param subscriber the [[Subscriber]] that will consume signals * from this [[Publisher]] */ - def subscribe(subscriber: Subscriber[_ >: T]): Unit + def subscribe(subscriber: Subscriber[? >: T]): Unit } diff --git a/monix-execution/js/src/main/scala/org/reactivestreams/Subscriber.scala b/monix-execution/js/src/main/scala/org/reactivestreams/Subscriber.scala index a301b34f3..774f6e20d 100644 --- a/monix-execution/js/src/main/scala/org/reactivestreams/Subscriber.scala +++ b/monix-execution/js/src/main/scala/org/reactivestreams/Subscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/js/src/main/scala/org/reactivestreams/Subscription.scala b/monix-execution/js/src/main/scala/org/reactivestreams/Subscription.scala index 4704d2e62..042de50f4 100644 --- a/monix-execution/js/src/main/scala/org/reactivestreams/Subscription.scala +++ b/monix-execution/js/src/main/scala/org/reactivestreams/Subscription.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/js/src/main/scala_3.0/monix/execution/atomic/Atomic.scala b/monix-execution/js/src/main/scala_3.0/monix/execution/atomic/Atomic.scala deleted file mode 100644 index cb52952f8..000000000 --- a/monix-execution/js/src/main/scala_3.0/monix/execution/atomic/Atomic.scala +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.atomic - -/** - * Base trait of all atomic references, no matter the type. - */ -abstract class Atomic[A] extends Serializable { - /** Get the current value persisted by this Atomic. */ - def get(): A - - /** Get the current value persisted by this Atomic, an alias for `get()`. */ - inline final def apply(): A = get() - - /** Updates the current value. - * - * @param update will be the new value returned by `get()` - */ - def set(update: A): Unit - - /** Alias for [[set]]. Updates the current value. - * - * @param value will be the new value returned by `get()` - */ - inline final def update(value: A): Unit = set(value) - - /** Alias for [[set]]. Updates the current value. - * - * @param value will be the new value returned by `get()` - */ - inline final def `:=`(value: A): Unit = set(value) - - /** Does a compare-and-set operation on the current value. For more info, checkout the related - * [[https://en.wikipedia.org/wiki/Compare-and-swap Compare-and-swap Wikipedia page]]. - * - * It's an atomic, worry free operation. - * - * @param expect is the value you expect to be persisted when the operation happens - * @param update will be the new value, should the check for `expect` succeeds - * @return either true in case the operation succeeded or false otherwise - */ - def compareAndSet(expect: A, update: A): Boolean - - /** Sets the persisted value to `update` and returns the old value that was in place. - * It's an atomic, worry free operation. - */ - def getAndSet(update: A): A - - /** Eventually sets to the given value. - * Has weaker visibility guarantees than the normal `set()`. - */ - def lazySet(update: A): Unit = set(update) - - /** Abstracts over `compareAndSet`. You specify a transformation by specifying a callback to be - * executed, a callback that transforms the current value. This method will loop until it will - * succeed in replacing the current value with the one produced by your callback. - * - * Note that the callback will be executed on each iteration of the loop, so it can be called - * multiple times - don't do destructive I/O or operations that mutate global state in it. - * - * @param cb is a callback that receives the current value as input and returns a tuple that specifies - * the update + what should this method return when the operation succeeds. - * @return whatever was specified by your callback, once the operation succeeds - */ - inline final def transformAndExtract[U](inline cb: (A) => (U, A)): U = { - val current = get() - val (result, update) = cb(current) - set(update) - result - } - - /** Abstracts over `compareAndSet`. You specify a transformation by specifying a callback to be - * executed, a callback that transforms the current value. This method will loop until it will - * succeed in replacing the current value with the one produced by the given callback. - * - * Note that the callback will be executed on each iteration of the loop, so it can be called - * multiple times - don't do destructive I/O or operations that mutate global state in it. - * - * @param cb is a callback that receives the current value as input and returns the `update` which is the - * new value that should be persisted - * @return whatever the update is, after the operation succeeds - */ - inline final def transformAndGet(inline cb: (A) => A): A = { - val current = get() - val update = cb(current) - - set(update) - update - } - - /** Abstracts over `compareAndSet`. You specify a transformation by specifying a callback to be - * executed, a callback that transforms the current value. This method will loop until it will - * succeed in replacing the current value with the one produced by the given callback. - * - * Note that the callback will be executed on each iteration of the loop, so it can be called - * multiple times - don't do destructive I/O or operations that mutate global state in it. - * - * @param cb is a callback that receives the current value as input and returns the `update` which is the - * new value that should be persisted - * @return the old value, just prior to when the successful update happened - */ - inline final def getAndTransform(inline cb: (A) => A): A = { - val current = get() - val update = cb(current) - - set(update) - current - } - - /** Abstracts over `compareAndSet`. You specify a transformation by specifying a callback to be - * executed, a callback that transforms the current value. This method will loop until it will - * succeed in replacing the current value with the one produced by the given callback. - * - * Note that the callback will be executed on each iteration of the loop, so it can be called - * multiple times - don't do destructive I/O or operations that mutate global state in it. - * - * @param cb is a callback that receives the current value as input and returns the `update` which is the - * new value that should be persisted - */ - inline final def transform(inline cb: (A) => A): Unit = - set(cb(get())) -} - -object Atomic { - /** Constructs an `Atomic[A]` reference. - * - * Based on the `initialValue`, it will return the best, most - * specific type. E.g. you give it a number, it will return - * something inheriting from `AtomicNumber[A]`. That's why it takes - * an `AtomicBuilder[T, R]` as an implicit parameter - but worry - * not about such details as it just works. - * - * @param initialValue is the initial value with which to - * initialize the Atomic reference - * - * @param builder is the builder that helps us to build the - * best reference possible, based on our `initialValue` - */ - inline def apply[A, R <: Atomic[A]](initialValue: A)(implicit builder: AtomicBuilder[A, R]): R = - builder.buildInstance(initialValue, PaddingStrategy.NoPadding, allowPlatformIntrinsics = true) - - /** Constructs an `Atomic[A]` reference, applying the provided - * [[PaddingStrategy]] in order to counter the "false sharing" - * problem. - * - * Based on the `initialValue`, it will return the best, most - * specific type. E.g. you give it a number, it will return - * something inheriting from `AtomicNumber[A]`. That's why it takes - * an `AtomicBuilder[A, R]` as an implicit parameter - but worry - * not about such details as it just works. - * - * Note that for ''Scala.js'' we aren't applying any padding, as it - * doesn't make much sense, since Javascript execution is single - * threaded, but this builder is provided for syntax compatibility - * anyway across the JVM and Javascript and we never know how - * Javascript engines will evolve. - * - * @param initialValue is the initial value with which to - * initialize the Atomic reference - * - * @param padding is the [[PaddingStrategy]] to apply - * - * @param builder is the builder that helps us to build the - * best reference possible, based on our `initialValue` - */ - inline def withPadding[A, R <: Atomic[A]](initialValue: A, padding: PaddingStrategy)( - implicit builder: AtomicBuilder[A, R]): R = - builder.buildInstance(initialValue, padding, allowPlatformIntrinsics = true) - - /** Returns the builder that would be chosen to construct Atomic - * references for the given `initialValue`. - */ - def builderFor[A, R <: Atomic[A]](initialValue: A)(implicit builder: AtomicBuilder[A, R]): AtomicBuilder[A, R] = - builder -} diff --git a/monix-execution/js/src/test/scala/monix/execution/internal/AsyncSchedulerJSSuite.scala b/monix-execution/js/src/test/scala/monix/execution/internal/AsyncSchedulerJSSuite.scala index cc9bb93d4..062625496 100644 --- a/monix-execution/js/src/test/scala/monix/execution/internal/AsyncSchedulerJSSuite.scala +++ b/monix-execution/js/src/test/scala/monix/execution/internal/AsyncSchedulerJSSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,9 +20,8 @@ package monix.execution.internal import minitest.TestSuite import monix.execution.cancelables.SingleAssignCancelable import monix.execution.schedulers.AsyncScheduler -import monix.execution.{ExecutionModel, Scheduler, TestUtils} +import monix.execution.{ ExecutionModel, Scheduler, TestUtils } import org.scalajs.macrotaskexecutor.MacrotaskExecutor - import scala.concurrent.Promise import scala.concurrent.duration._ @@ -75,7 +74,7 @@ object AsyncSchedulerJSSuite extends TestSuite[Scheduler] with TestUtils { import concurrent.duration._ val p = Promise[Unit]() val startAt = s.clockMonotonic(MILLISECONDS) - s.scheduleOnce(100.millis) { p.success(()); () } + val _ = s.scheduleOnce(100.millis) { p.success(()); () } for (_ <- p.future) yield { val duration = s.clockMonotonic(MILLISECONDS) - startAt diff --git a/monix-execution/js/src/test/scala/monix/execution/internal/PlatformSuite.scala b/monix-execution/js/src/test/scala/monix/execution/internal/PlatformSuite.scala index e8680ae89..33fa63b62 100644 --- a/monix-execution/js/src/test/scala/monix/execution/internal/PlatformSuite.scala +++ b/monix-execution/js/src/test/scala/monix/execution/internal/PlatformSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/js/src/test/scala/monix/execution/internal/collection/JSArrayQueueSuite.scala b/monix-execution/js/src/test/scala/monix/execution/internal/collection/JSArrayQueueSuite.scala index e6f578cec..ad411f438 100644 --- a/monix-execution/js/src/test/scala/monix/execution/internal/collection/JSArrayQueueSuite.scala +++ b/monix-execution/js/src/test/scala/monix/execution/internal/collection/JSArrayQueueSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/InternalApi.java b/monix-execution/jvm/src/main/java/monix/execution/internal/InternalApi.java deleted file mode 100644 index 63b92df66..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/InternalApi.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.CLASS; - -/** - * Marks APIs that are considered internal to Monix and may change at - * any point in time without any warning. - * - * For example, this annotation should be used when the Scala - * `private[monix]` access restriction is used, as Java has no way of - * representing this package restricted access and such methods and - * classes are represented as public in byte-code. - * - * If a method/class annotated with this method has a javadoc/scaladoc - * comment, the first line MUST include INTERNAL API in order to be - * easily identifiable from generated documentation. Additional - * information may be put on the same line as the INTERNAL API comment - * in order to clarify further. - * - * Copied from the [[https://akka.io/ Akka project]]. - */ -@Documented -@Retention(value=CLASS) -@Target(value={METHOD,CONSTRUCTOR,FIELD,TYPE,PACKAGE}) -public @interface InternalApi {} diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Factory.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Factory.java deleted file mode 100644 index 26b3335f0..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Factory.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import scala.MatchError; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi public final class Factory { - public static BoxedObject newBoxedObject(Object initial, BoxPaddingStrategy padding, boolean allowUnsafe, boolean allowJava8Intrinsics) { - boolean useJava7Unsafe = allowUnsafe && UnsafeAccess.IS_AVAILABLE; - boolean useJava8Unsafe = useJava7Unsafe && allowJava8Intrinsics && UnsafeAccess.HAS_JAVA8_INTRINSICS; - - switch (padding) { - case NO_PADDING: - if (useJava8Unsafe) - return new NormalJava8BoxedObject(initial); - else if (useJava7Unsafe) - return new NormalJava7BoxedObject(initial); - else - return new NormalJavaXBoxedObject(initial); - - case LEFT_64: - if (useJava8Unsafe) - return new Left64Java8BoxedObject(initial); - else if (useJava7Unsafe) - return new Left64Java7BoxedObject(initial); - else - return new Left64JavaXBoxedObject(initial); - - case RIGHT_64: - if (useJava8Unsafe) - return new Right64Java8BoxedObject(initial); - else if (useJava7Unsafe) - return new Right64Java7BoxedObject(initial); - else - return new Right64JavaXBoxedObject(initial); - - case LEFT_RIGHT_128: - if (useJava8Unsafe) - return new LeftRight128Java8BoxedObject(initial); - else if (useJava7Unsafe) - return new LeftRight128Java7BoxedObject(initial); - else - return new LeftRight128JavaXBoxedObject(initial); - - case LEFT_128: - if (useJava8Unsafe) - return new Left128Java8BoxedObject(initial); - else if (useJava7Unsafe) - return new Left128Java7BoxedObject(initial); - else - return new Left128JavaXBoxedObject(initial); - - case RIGHT_128: - if (useJava8Unsafe) - return new Right128Java8BoxedObject(initial); - else if (useJava7Unsafe) - return new Right128Java7BoxedObject(initial); - else - return new Right128JavaXBoxedObject(initial); - - case LEFT_RIGHT_256: - if (useJava8Unsafe) - return new LeftRight256Java8BoxedObject(initial); - else if (useJava7Unsafe) - return new LeftRight256Java7BoxedObject(initial); - else - return new LeftRight256JavaXBoxedObject(initial); - - default: - throw new MatchError(padding); - } - } - - public static BoxedInt newBoxedInt(int initial, BoxPaddingStrategy padding, boolean allowUnsafe, boolean allowJava8Intrinsics) { - boolean useJava7Unsafe = allowUnsafe && UnsafeAccess.IS_AVAILABLE; - boolean useJava8Unsafe = useJava7Unsafe && allowJava8Intrinsics && UnsafeAccess.HAS_JAVA8_INTRINSICS; - - switch (padding) { - case NO_PADDING: - if (useJava8Unsafe) - return new NormalJava8BoxedInt(initial); - else if (useJava7Unsafe) - return new NormalJava7BoxedInt(initial); - else - return new NormalJavaXBoxedInt(initial); - - case LEFT_64: - if (useJava8Unsafe) - return new Left64Java8BoxedInt(initial); - else if (useJava7Unsafe) - return new Left64Java7BoxedInt(initial); - else - return new Left64JavaXBoxedInt(initial); - - case RIGHT_64: - if (useJava8Unsafe) - return new Right64Java8BoxedInt(initial); - else if (useJava7Unsafe) - return new Right64Java7BoxedInt(initial); - else - return new Right64JavaXBoxedInt(initial); - - case LEFT_RIGHT_128: - if (useJava8Unsafe) - return new LeftRight128Java8BoxedInt(initial); - else if (useJava7Unsafe) - return new LeftRight128Java7BoxedInt(initial); - else - return new LeftRight128JavaXBoxedInt(initial); - - case LEFT_128: - if (useJava8Unsafe) - return new Left128Java8BoxedInt(initial); - else if (useJava7Unsafe) - return new Left128Java7BoxedInt(initial); - else - return new Left128JavaXBoxedInt(initial); - - case RIGHT_128: - if (useJava8Unsafe) - return new Right128Java8BoxedInt(initial); - else if (useJava7Unsafe) - return new Right128Java7BoxedInt(initial); - else - return new Right128JavaXBoxedInt(initial); - - case LEFT_RIGHT_256: - if (useJava8Unsafe) - return new LeftRight256Java8BoxedInt(initial); - else if (useJava7Unsafe) - return new LeftRight256Java7BoxedInt(initial); - else - return new LeftRight256JavaXBoxedInt(initial); - - default: - throw new MatchError(padding); - } - } - - public static BoxedLong newBoxedLong(long initial, BoxPaddingStrategy padding, boolean allowUnsafe, boolean allowJava8Intrinsics) { - boolean useJava7Unsafe = allowUnsafe && UnsafeAccess.IS_AVAILABLE; - boolean useJava8Unsafe = useJava7Unsafe && allowJava8Intrinsics && UnsafeAccess.HAS_JAVA8_INTRINSICS; - - switch (padding) { - case NO_PADDING: - if (useJava8Unsafe) - return new NormalJava8BoxedLong(initial); - else if (useJava7Unsafe) - return new NormalJava7BoxedLong(initial); - else - return new NormalJavaXBoxedLong(initial); - - case LEFT_64: - if (useJava8Unsafe) - return new Left64Java8BoxedLong(initial); - else if (useJava7Unsafe) - return new Left64Java7BoxedLong(initial); - else - return new Left64JavaXBoxedLong(initial); - - case RIGHT_64: - if (useJava8Unsafe) - return new Right64Java8BoxedLong(initial); - else if (useJava7Unsafe) - return new Right64Java7BoxedLong(initial); - else - return new Right64JavaXBoxedLong(initial); - - case LEFT_RIGHT_128: - if (useJava8Unsafe) - return new LeftRight128Java8BoxedLong(initial); - else if (useJava7Unsafe) - return new LeftRight128Java7BoxedLong(initial); - else - return new LeftRight128JavaXBoxedLong(initial); - - case LEFT_128: - if (useJava8Unsafe) - return new Left128Java8BoxedLong(initial); - else if (useJava7Unsafe) - return new Left128Java7BoxedLong(initial); - else - return new Left128JavaXBoxedLong(initial); - - case RIGHT_128: - if (useJava8Unsafe) - return new Right128Java8BoxedLong(initial); - else if (useJava7Unsafe) - return new Right128Java7BoxedLong(initial); - else - return new Right128JavaXBoxedLong(initial); - - case LEFT_RIGHT_256: - if (useJava8Unsafe) - return new LeftRight256Java8BoxedLong(initial); - else if (useJava7Unsafe) - return new LeftRight256Java7BoxedLong(initial); - else - return new LeftRight256JavaXBoxedLong(initial); - - default: - throw new MatchError(padding); - } - } -} diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128Java7BoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128Java7BoxedInt.java deleted file mode 100644 index 9ad14fd8a..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128Java7BoxedInt.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Left128Java7BoxedInt extends LeftPadding120 implements BoxedInt { - public volatile int value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Left128Java7BoxedInt.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Left128Java7BoxedInt(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UNSAFE.putOrderedInt(this, OFFSET, update); - } - - public boolean compareAndSet(int current, int update) { - return UNSAFE.compareAndSwapInt(this, OFFSET, current, update); - } - - public int getAndSet(int update) { - int current = value; - while (!UNSAFE.compareAndSwapInt(this, OFFSET, current, update)) - current = value; - return current; - } - - public int getAndAdd(int delta) { - int current; - do { - current = UNSAFE.getIntVolatile(this, OFFSET); - } while (!UNSAFE.compareAndSwapInt(this, OFFSET, current, current+delta)); - return current; - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128Java7BoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128Java7BoxedLong.java deleted file mode 100644 index d4c8f2534..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128Java7BoxedLong.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Left128Java7BoxedLong extends LeftPadding120 implements BoxedLong { - public volatile long value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Left128Java7BoxedLong.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Left128Java7BoxedLong(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UNSAFE.putOrderedLong(this, OFFSET, update); - } - - public boolean compareAndSet(long current, long update) { - return UNSAFE.compareAndSwapLong(this, OFFSET, current, update); - } - - public long getAndSet(long update) { - long current = value; - while (!UNSAFE.compareAndSwapLong(this, OFFSET, current, update)) - current = value; - return current; - } - - public long getAndAdd(long delta) { - long current; - do { - current = UNSAFE.getLongVolatile(this, OFFSET); - } while (!UNSAFE.compareAndSwapLong(this, OFFSET, current, current+delta)); - return current; - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128Java7BoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128Java7BoxedObject.java deleted file mode 100644 index 82bd73d1a..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128Java7BoxedObject.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Left128Java7BoxedObject extends LeftPadding120 implements BoxedObject { - public volatile Object value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Left128Java7BoxedObject.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Left128Java7BoxedObject(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UNSAFE.putOrderedObject(this, OFFSET, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UNSAFE.compareAndSwapObject(this, OFFSET, current, update); - } - - public Object getAndSet(Object update) { - Object current = value; - while (!UNSAFE.compareAndSwapObject(this, OFFSET, current, update)) - current = value; - return current; - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128Java8BoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128Java8BoxedInt.java deleted file mode 100644 index 3c9e25e9d..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128Java8BoxedInt.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Left128Java8BoxedInt extends LeftPadding120 implements BoxedInt { - public volatile int value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Left128Java8BoxedInt.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Left128Java8BoxedInt(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UNSAFE.putOrderedInt(this, OFFSET, update); - } - - public boolean compareAndSet(int current, int update) { - return UNSAFE.compareAndSwapInt(this, OFFSET, current, update); - } - - public int getAndSet(int update) { - return UNSAFE.getAndSetInt(this, OFFSET, update); - } - - public int getAndAdd(int delta) { - return UNSAFE.getAndAddInt(this, OFFSET, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128Java8BoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128Java8BoxedLong.java deleted file mode 100644 index 54c8b7363..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128Java8BoxedLong.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Left128Java8BoxedLong extends LeftPadding120 implements BoxedLong { - public volatile long value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Left128Java8BoxedLong.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Left128Java8BoxedLong(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UNSAFE.putOrderedLong(this, OFFSET, update); - } - - public boolean compareAndSet(long current, long update) { - return UNSAFE.compareAndSwapLong(this, OFFSET, current, update); - } - - public long getAndSet(long update) { - return UNSAFE.getAndSetLong(this, OFFSET, update); - } - - public long getAndAdd(long delta) { - return UNSAFE.getAndAddLong(this, OFFSET, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128Java8BoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128Java8BoxedObject.java deleted file mode 100644 index 18c798aa9..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128Java8BoxedObject.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Left128Java8BoxedObject extends LeftPadding120 implements BoxedObject { - public volatile Object value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Left128Java8BoxedObject.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Left128Java8BoxedObject(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UNSAFE.putOrderedObject(this, OFFSET, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UNSAFE.compareAndSwapObject(this, OFFSET, current, update); - } - - public Object getAndSet(Object update) { - return UNSAFE.getAndSetObject(this, OFFSET, update); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128JavaXBoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128JavaXBoxedInt.java deleted file mode 100644 index 35cdc9a52..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128JavaXBoxedInt.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Left128JavaXBoxedInt extends LeftPadding120 implements BoxedInt { - public volatile int value; - - private static final AtomicIntegerFieldUpdater UPDATER = - AtomicIntegerFieldUpdater.newUpdater(Left128JavaXBoxedInt.class, "value"); - - Left128JavaXBoxedInt(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(int current, int update) { - return UPDATER.compareAndSet(this, current, update); - } - - public int getAndSet(int update) { - return UPDATER.getAndSet(this, update); - } - - public int getAndAdd(int delta) { - return UPDATER.getAndAdd(this, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128JavaXBoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128JavaXBoxedLong.java deleted file mode 100644 index 25613d178..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128JavaXBoxedLong.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicLongFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Left128JavaXBoxedLong extends LeftPadding120 implements BoxedLong { - public volatile long value; - - private static final AtomicLongFieldUpdater UPDATER = - AtomicLongFieldUpdater.newUpdater(Left128JavaXBoxedLong.class, "value"); - - Left128JavaXBoxedLong(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(long current, long update) { - return UPDATER.compareAndSet(this, current, update); - } - - public long getAndSet(long update) { - return UPDATER.getAndSet(this, update); - } - - public long getAndAdd(long delta) { - return UPDATER.getAndAdd(this, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128JavaXBoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128JavaXBoxedObject.java deleted file mode 100644 index a1f319d38..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left128JavaXBoxedObject.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Left128JavaXBoxedObject extends LeftPadding120 implements BoxedObject { - public volatile Object value; - - private static final AtomicReferenceFieldUpdater UPDATER = - AtomicReferenceFieldUpdater.newUpdater(Left128JavaXBoxedObject.class, Object.class, "value"); - - Left128JavaXBoxedObject(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UPDATER.compareAndSet(this, current, update); - } - - public Object getAndSet(Object update) { - return UPDATER.getAndSet(this, update); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64Java7BoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64Java7BoxedInt.java deleted file mode 100644 index c02d98000..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64Java7BoxedInt.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Left64Java7BoxedInt extends LeftPadding56 implements BoxedInt { - public volatile int value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Left64Java7BoxedInt.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Left64Java7BoxedInt(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UNSAFE.putOrderedInt(this, OFFSET, update); - } - - public boolean compareAndSet(int current, int update) { - return UNSAFE.compareAndSwapInt(this, OFFSET, current, update); - } - - public int getAndSet(int update) { - int current = value; - while (!UNSAFE.compareAndSwapInt(this, OFFSET, current, update)) - current = value; - return current; - } - - public int getAndAdd(int delta) { - int current; - do { - current = UNSAFE.getIntVolatile(this, OFFSET); - } while (!UNSAFE.compareAndSwapInt(this, OFFSET, current, current+ delta)); - return current; - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64Java7BoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64Java7BoxedLong.java deleted file mode 100644 index efee26e1b..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64Java7BoxedLong.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Left64Java7BoxedLong extends LeftPadding56 implements BoxedLong { - public volatile long value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Left64Java7BoxedLong.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Left64Java7BoxedLong(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UNSAFE.putOrderedLong(this, OFFSET, update); - } - - public boolean compareAndSet(long current, long update) { - return UNSAFE.compareAndSwapLong(this, OFFSET, current, update); - } - - public long getAndSet(long update) { - long current = value; - while (!UNSAFE.compareAndSwapLong(this, OFFSET, current, update)) - current = value; - return current; - } - - public long getAndAdd(long delta) { - long current; - do { - current = UNSAFE.getLongVolatile(this, OFFSET); - } while (!UNSAFE.compareAndSwapLong(this, OFFSET, current, current+delta)); - return current; - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64Java7BoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64Java7BoxedObject.java deleted file mode 100644 index 58b6aa32f..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64Java7BoxedObject.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Left64Java7BoxedObject extends LeftPadding56 implements BoxedObject { - public volatile Object value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Left64Java7BoxedObject.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Left64Java7BoxedObject(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UNSAFE.putOrderedObject(this, OFFSET, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UNSAFE.compareAndSwapObject(this, OFFSET, current, update); - } - - public Object getAndSet(Object update) { - Object current = value; - while (!UNSAFE.compareAndSwapObject(this, OFFSET, current, update)) - current = value; - return current; - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64Java8BoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64Java8BoxedInt.java deleted file mode 100644 index fbefe1162..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64Java8BoxedInt.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Left64Java8BoxedInt extends LeftPadding56 implements BoxedInt { - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Left64Java8BoxedInt.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - public volatile int value; - - Left64Java8BoxedInt(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UNSAFE.putOrderedInt(this, OFFSET, update); - } - - public boolean compareAndSet(int current, int update) { - return UNSAFE.compareAndSwapInt(this, OFFSET, current, update); - } - - public int getAndSet(int update) { - return UNSAFE.getAndSetInt(this, OFFSET, update); - } - - public int getAndAdd(int delta) { - return UNSAFE.getAndAddInt(this, OFFSET, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64Java8BoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64Java8BoxedLong.java deleted file mode 100644 index 1adc54488..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64Java8BoxedLong.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Left64Java8BoxedLong extends LeftPadding56 implements BoxedLong { - public volatile long value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Left64Java8BoxedLong.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Left64Java8BoxedLong(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UNSAFE.putOrderedLong(this, OFFSET, update); - } - - public boolean compareAndSet(long current, long update) { - return UNSAFE.compareAndSwapLong(this, OFFSET, current, update); - } - - public long getAndSet(long update) { - return UNSAFE.getAndSetLong(this, OFFSET, update); - } - - public long getAndAdd(long delta) { - return UNSAFE.getAndAddLong(this, OFFSET, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64Java8BoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64Java8BoxedObject.java deleted file mode 100644 index fff31a96e..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64Java8BoxedObject.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Left64Java8BoxedObject extends LeftPadding56 implements BoxedObject { - public volatile Object value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Left64Java8BoxedObject.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Left64Java8BoxedObject(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UNSAFE.putOrderedObject(this, OFFSET, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UNSAFE.compareAndSwapObject(this, OFFSET, current, update); - } - - public Object getAndSet(Object update) { - return UNSAFE.getAndSetObject(this, OFFSET, update); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64JavaXBoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64JavaXBoxedInt.java deleted file mode 100644 index abf49809d..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64JavaXBoxedInt.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Left64JavaXBoxedInt extends LeftPadding56 implements BoxedInt { - public volatile int value; - - private static final AtomicIntegerFieldUpdater UPDATER = - AtomicIntegerFieldUpdater.newUpdater(Left64JavaXBoxedInt.class, "value"); - - Left64JavaXBoxedInt(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(int current, int update) { - return UPDATER.compareAndSet(this, current, update); - } - - public int getAndSet(int update) { - return UPDATER.getAndSet(this, update); - } - - public int getAndAdd(int delta) { - return UPDATER.getAndAdd(this, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64JavaXBoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64JavaXBoxedLong.java deleted file mode 100644 index 94d9596d1..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64JavaXBoxedLong.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicLongFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Left64JavaXBoxedLong extends LeftPadding56 implements BoxedLong { - - public volatile long value; - - private static final AtomicLongFieldUpdater UPDATER = - AtomicLongFieldUpdater.newUpdater(Left64JavaXBoxedLong.class, "value"); - - Left64JavaXBoxedLong(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(long current, long update) { - return UPDATER.compareAndSet(this, current, update); - } - - public long getAndSet(long update) { - return UPDATER.getAndSet(this, update); - } - - public long getAndAdd(long delta) { - return UPDATER.getAndAdd(this, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64JavaXBoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64JavaXBoxedObject.java deleted file mode 100644 index d040a6fd2..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Left64JavaXBoxedObject.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Left64JavaXBoxedObject extends LeftPadding56 implements BoxedObject { - - public volatile Object value; - - private static final AtomicReferenceFieldUpdater UPDATER = - AtomicReferenceFieldUpdater.newUpdater(Left64JavaXBoxedObject.class, Object.class, "value"); - - Left64JavaXBoxedObject(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UPDATER.compareAndSet(this, current, update); - } - - public Object getAndSet(Object update) { - return UPDATER.getAndSet(this, update); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128Java7BoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128Java7BoxedInt.java deleted file mode 100644 index 7c0daa50b..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128Java7BoxedInt.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class LeftRight128Java7BoxedInt extends LeftRight128Java7BoxedIntImpl { - public volatile long r1, r2, r3, r4, r5, r6, r7, r8 = 11; - @Override public long sum() { - return p1 + p2 + p3 + p4 + p5 + p6 + p7 + - r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8; - } - - LeftRight128Java7BoxedInt(int initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class LeftRight128Java7BoxedIntImpl extends LeftPadding56 implements BoxedInt { - public volatile int value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = LeftRight128Java7BoxedIntImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - LeftRight128Java7BoxedIntImpl(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UNSAFE.putOrderedInt(this, OFFSET, update); - } - - public boolean compareAndSet(int current, int update) { - return UNSAFE.compareAndSwapInt(this, OFFSET, current, update); - } - - public int getAndSet(int update) { - int current = value; - while (!UNSAFE.compareAndSwapInt(this, OFFSET, current, update)) - current = value; - return current; - } - - public int getAndAdd(int delta) { - int current; - do { - current = UNSAFE.getIntVolatile(this, OFFSET); - } while (!UNSAFE.compareAndSwapInt(this, OFFSET, current, current+delta)); - return current; - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128Java7BoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128Java7BoxedLong.java deleted file mode 100644 index 1b19b664c..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128Java7BoxedLong.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class LeftRight128Java7BoxedLong extends LeftRight128Java7BoxedLongImpl { - public volatile long r1, r2, r3, r4, r5, r6, r7, r8 = 11; - @Override public long sum() { - return p1 + p2 + p3 + p4 + p5 + p6 + p7 + - r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8; - } - - LeftRight128Java7BoxedLong(long initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class LeftRight128Java7BoxedLongImpl extends LeftPadding56 implements BoxedLong { - public volatile long value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = LeftRight128Java7BoxedLongImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - LeftRight128Java7BoxedLongImpl(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UNSAFE.putOrderedLong(this, OFFSET, update); - } - - public boolean compareAndSet(long current, long update) { - return UNSAFE.compareAndSwapLong(this, OFFSET, current, update); - } - - public long getAndSet(long update) { - long current = value; - while (!UNSAFE.compareAndSwapLong(this, OFFSET, current, update)) - current = value; - return current; - } - - public long getAndAdd(long delta) { - long current; - do { - current = UNSAFE.getLongVolatile(this, OFFSET); - } while (!UNSAFE.compareAndSwapLong(this, OFFSET, current, current+delta)); - return current; - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128Java7BoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128Java7BoxedObject.java deleted file mode 100644 index 2716a919c..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128Java7BoxedObject.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class LeftRight128Java7BoxedObject extends LeftRight128Java7BoxedObjectImpl { - public volatile long r1, r2, r3, r4, r5, r6, r7, r8 = 11; - @Override public long sum() { - return p1 + p2 + p3 + p4 + p5 + p6 + p7 + - r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8; - } - - LeftRight128Java7BoxedObject(Object initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class LeftRight128Java7BoxedObjectImpl extends LeftPadding56 implements BoxedObject { - public volatile Object value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = LeftRight128Java7BoxedObjectImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - LeftRight128Java7BoxedObjectImpl(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UNSAFE.putOrderedObject(this, OFFSET, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UNSAFE.compareAndSwapObject(this, OFFSET, current, update); - } - - public Object getAndSet(Object update) { - Object current = value; - while (!UNSAFE.compareAndSwapObject(this, OFFSET, current, update)) - current = value; - return current; - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128Java8BoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128Java8BoxedInt.java deleted file mode 100644 index 0bca0d655..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128Java8BoxedInt.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class LeftRight128Java8BoxedInt extends LeftRight128Java8BoxedIntImpl { - public volatile long r1, r2, r3, r4, r5, r6, r7, r8 = 11; - @Override public long sum() { - return p1 + p2 + p3 + p4 + p5 + p6 + p7 + - r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8; - } - - LeftRight128Java8BoxedInt(int initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class LeftRight128Java8BoxedIntImpl extends LeftPadding56 implements BoxedInt { - public volatile int value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = LeftRight128Java8BoxedIntImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - LeftRight128Java8BoxedIntImpl(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UNSAFE.putOrderedInt(this, OFFSET, update); - } - - public boolean compareAndSet(int current, int update) { - return UNSAFE.compareAndSwapInt(this, OFFSET, current, update); - } - - public int getAndSet(int update) { - return UNSAFE.getAndSetInt(this, OFFSET, update); - } - - public int getAndAdd(int delta) { - return UNSAFE.getAndAddInt(this, OFFSET, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128Java8BoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128Java8BoxedLong.java deleted file mode 100644 index aa2d5d8fc..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128Java8BoxedLong.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class LeftRight128Java8BoxedLong extends LeftRight128Java8BoxedLongImpl { - public volatile long r1, r2, r3, r4, r5, r6, r7, r8 = 11; - @Override public long sum() { - return p1 + p2 + p3 + p4 + p5 + p6 + p7 + - r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8; - } - - LeftRight128Java8BoxedLong(long initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class LeftRight128Java8BoxedLongImpl extends LeftPadding56 implements BoxedLong { - public volatile long value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = LeftRight128Java8BoxedLongImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - LeftRight128Java8BoxedLongImpl(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UNSAFE.putOrderedLong(this, OFFSET, update); - } - - public boolean compareAndSet(long current, long update) { - return UNSAFE.compareAndSwapLong(this, OFFSET, current, update); - } - - public long getAndSet(long update) { - return UNSAFE.getAndSetLong(this, OFFSET, update); - } - - public long getAndAdd(long delta) { - return UNSAFE.getAndAddLong(this, OFFSET, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128Java8BoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128Java8BoxedObject.java deleted file mode 100644 index 0ad133610..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128Java8BoxedObject.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class LeftRight128Java8BoxedObject extends LeftRight128Java8BoxedObjectImpl { - public volatile long r1, r2, r3, r4, r5, r6, r7, r8 = 11; - @Override public long sum() { - return p1 + p2 + p3 + p4 + p5 + p6 + p7 + - r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8; - } - - LeftRight128Java8BoxedObject(Object initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class LeftRight128Java8BoxedObjectImpl extends LeftPadding56 implements BoxedObject { - public volatile Object value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = LeftRight128Java8BoxedObjectImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - LeftRight128Java8BoxedObjectImpl(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UNSAFE.putOrderedObject(this, OFFSET, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UNSAFE.compareAndSwapObject(this, OFFSET, current, update); - } - - public Object getAndSet(Object update) { - Object current = value; - while (!UNSAFE.compareAndSwapObject(this, OFFSET, current, update)) - current = value; - return current; - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128JavaXBoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128JavaXBoxedInt.java deleted file mode 100644 index 60dc88649..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128JavaXBoxedInt.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class LeftRight128JavaXBoxedInt extends LeftRight128JavaXBoxedIntImpl { - public volatile long r1, r2, r3, r4, r5, r6, r7, r8 = 11; - @Override public long sum() { - return p1 + p2 + p3 + p4 + p5 + p6 + p7 + - r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8; - } - - LeftRight128JavaXBoxedInt(int initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class LeftRight128JavaXBoxedIntImpl extends LeftPadding56 implements BoxedInt { - public volatile int value; - - private static final AtomicIntegerFieldUpdater UPDATER = - AtomicIntegerFieldUpdater.newUpdater(LeftRight128JavaXBoxedIntImpl.class, "value"); - - LeftRight128JavaXBoxedIntImpl(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(int current, int update) { - return UPDATER.compareAndSet(this, current, update); - } - - public int getAndSet(int update) { - return UPDATER.getAndSet(this, update); - } - - public int getAndAdd(int delta) { - return UPDATER.getAndAdd(this, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128JavaXBoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128JavaXBoxedLong.java deleted file mode 100644 index d5ea21cb8..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128JavaXBoxedLong.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicLongFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class LeftRight128JavaXBoxedLong extends LeftRight128JavaXBoxedLongImpl { - public volatile long r1, r2, r3, r4, r5, r6, r7, r8 = 11; - @Override public long sum() { - return p1 + p2 + p3 + p4 + p5 + p6 + p7 + - r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8; - } - - LeftRight128JavaXBoxedLong(long initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class LeftRight128JavaXBoxedLongImpl extends LeftPadding56 implements BoxedLong { - public volatile long value; - - private static final AtomicLongFieldUpdater UPDATER = - AtomicLongFieldUpdater.newUpdater(LeftRight128JavaXBoxedLongImpl.class, "value"); - - LeftRight128JavaXBoxedLongImpl(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(long current, long update) { - return UPDATER.compareAndSet(this, current, update); - } - - public long getAndSet(long update) { - return UPDATER.getAndSet(this, update); - } - - public long getAndAdd(long delta) { - return UPDATER.getAndAdd(this, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128JavaXBoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128JavaXBoxedObject.java deleted file mode 100644 index 7862cafd5..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight128JavaXBoxedObject.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class LeftRight128JavaXBoxedObject extends LeftRight128JavaXBoxedObjectImpl { - public volatile long r1, r2, r3, r4, r5, r6, r7, r8 = 11; - @Override public long sum() { - return p1 + p2 + p3 + p4 + p5 + p6 + p7 + - r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8; - } - - LeftRight128JavaXBoxedObject(Object initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class LeftRight128JavaXBoxedObjectImpl extends LeftPadding56 implements BoxedObject { - public volatile Object value; - - private static final AtomicReferenceFieldUpdater UPDATER = - AtomicReferenceFieldUpdater.newUpdater(LeftRight128JavaXBoxedObjectImpl.class, Object.class, "value"); - - LeftRight128JavaXBoxedObjectImpl(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UPDATER.compareAndSet(this, current, update); - } - - public Object getAndSet(Object update) { - return UPDATER.getAndSet(this, update); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256Java7BoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256Java7BoxedInt.java deleted file mode 100644 index f0307bf03..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256Java7BoxedInt.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class LeftRight256Java7BoxedInt extends LeftRight256Java7BoxedIntImpl { - public volatile long r01, r02, r03, r04, r05, r06, r07, r08 = 7; - public volatile long r09, r10, r11, r12, r13, r14, r15, r16 = 8; - @Override public long sum() { - return p01 + p02 + p03 + p04 + p05 + p06 + p07 + p08 + - p09 + p10 + p11 + p12 + p13 + p14 + p15 + - r01 + r02 + r03 + r04 + r05 + r06 + r07 + r08 + - r09 + r10 + r11 + r12 + r13 + r14 + r15 + r16; - } - - LeftRight256Java7BoxedInt(int initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class LeftRight256Java7BoxedIntImpl extends LeftPadding120 implements BoxedInt { - public volatile int value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = LeftRight256Java7BoxedIntImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - LeftRight256Java7BoxedIntImpl(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UNSAFE.putOrderedInt(this, OFFSET, update); - } - - public boolean compareAndSet(int current, int update) { - return UNSAFE.compareAndSwapInt(this, OFFSET, current, update); - } - - public int getAndSet(int update) { - int current = value; - while (!UNSAFE.compareAndSwapInt(this, OFFSET, current, update)) - current = value; - return current; - } - - public int getAndAdd(int delta) { - int current; - do { - current = UNSAFE.getIntVolatile(this, OFFSET); - } while (!UNSAFE.compareAndSwapInt(this, OFFSET, current, current+delta)); - return current; - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256Java7BoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256Java7BoxedLong.java deleted file mode 100644 index af4b971a3..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256Java7BoxedLong.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class LeftRight256Java7BoxedLong extends LeftRight256Java7BoxedLongImpl { - public volatile long r01, r02, r03, r04, r05, r06, r07, r08 = 7; - public volatile long r09, r10, r11, r12, r13, r14, r15, r16 = 8; - @Override public long sum() { - return - p01 + p02 + p03 + p04 + p05 + p06 + p07 + p08 + - p09 + p10 + p11 + p12 + p13 + p14 + p15 + - r01 + r02 + r03 + r04 + r05 + r06 + r07 + r08 + - r09 + r10 + r11 + r12 + r13 + r14 + r15 + r16; - } - - LeftRight256Java7BoxedLong(long initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class LeftRight256Java7BoxedLongImpl extends LeftPadding120 implements BoxedLong { - public volatile long value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = LeftRight256Java7BoxedLongImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - LeftRight256Java7BoxedLongImpl(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UNSAFE.putOrderedLong(this, OFFSET, update); - } - - public boolean compareAndSet(long current, long update) { - return UNSAFE.compareAndSwapLong(this, OFFSET, current, update); - } - - public long getAndSet(long update) { - long current = value; - while (!UNSAFE.compareAndSwapLong(this, OFFSET, current, update)) - current = value; - return current; - } - - public long getAndAdd(long delta) { - long current; - do { - current = UNSAFE.getLongVolatile(this, OFFSET); - } while (!UNSAFE.compareAndSwapLong(this, OFFSET, current, current+delta)); - return current; - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256Java7BoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256Java7BoxedObject.java deleted file mode 100644 index ba77a5263..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256Java7BoxedObject.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class LeftRight256Java7BoxedObject extends LeftRight256Java7BoxedObjectImpl { - public volatile long r01, r02, r03, r04, r05, r06, r07, r08 = 7; - public volatile long r09, r10, r11, r12, r13, r14, r15, r16 = 8; - @Override public long sum() { - return - p01 + p02 + p03 + p04 + p05 + p06 + p07 + p08 + - p09 + p10 + p11 + p12 + p13 + p14 + p15 + - r01 + r02 + r03 + r04 + r05 + r06 + r07 + r08 + - r09 + r10 + r11 + r12 + r13 + r14 + r15 + r16; - } - - LeftRight256Java7BoxedObject(Object initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class LeftRight256Java7BoxedObjectImpl extends LeftPadding120 implements BoxedObject { - public volatile Object value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = LeftRight256Java7BoxedObjectImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - LeftRight256Java7BoxedObjectImpl(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UNSAFE.putOrderedObject(this, OFFSET, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UNSAFE.compareAndSwapObject(this, OFFSET, current, update); - } - - public Object getAndSet(Object update) { - Object current = value; - while (!UNSAFE.compareAndSwapObject(this, OFFSET, current, update)) - current = value; - return current; - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256Java8BoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256Java8BoxedInt.java deleted file mode 100644 index 3684f8888..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256Java8BoxedInt.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class LeftRight256Java8BoxedInt extends LeftRight256Java8BoxedIntImpl { - public volatile long r01, r02, r03, r04, r05, r06, r07, r08 = 7; - public volatile long r09, r10, r11, r12, r13, r14, r15, r16 = 8; - @Override public long sum() { - return - p01 + p02 + p03 + p04 + p05 + p06 + p07 + p08 + - p09 + p10 + p11 + p12 + p13 + p14 + p15 + - r01 + r02 + r03 + r04 + r05 + r06 + r07 + r08 + - r09 + r10 + r11 + r12 + r13 + r14 + r15 + r16; - } - - LeftRight256Java8BoxedInt(int initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class LeftRight256Java8BoxedIntImpl extends LeftPadding120 implements BoxedInt { - public volatile int value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = LeftRight256Java8BoxedIntImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - LeftRight256Java8BoxedIntImpl(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UNSAFE.putOrderedInt(this, OFFSET, update); - } - - public boolean compareAndSet(int current, int update) { - return UNSAFE.compareAndSwapInt(this, OFFSET, current, update); - } - - public int getAndSet(int update) { - return UNSAFE.getAndSetInt(this, OFFSET, update); - } - - public int getAndAdd(int delta) { - return UNSAFE.getAndAddInt(this, OFFSET, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256Java8BoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256Java8BoxedLong.java deleted file mode 100644 index 9fe8e3389..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256Java8BoxedLong.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class LeftRight256Java8BoxedLong extends LeftRight256Java8BoxedLongImpl { - public volatile long r01, r02, r03, r04, r05, r06, r07, r08 = 7; - public volatile long r09, r10, r11, r12, r13, r14, r15, r16 = 8; - @Override public long sum() { - return - p01 + p02 + p03 + p04 + p05 + p06 + p07 + p08 + - p09 + p10 + p11 + p12 + p13 + p14 + p15 + - r01 + r02 + r03 + r04 + r05 + r06 + r07 + r08 + - r09 + r10 + r11 + r12 + r13 + r14 + r15 + r16; - } - - LeftRight256Java8BoxedLong(long initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class LeftRight256Java8BoxedLongImpl extends LeftPadding120 implements BoxedLong { - public volatile long value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = LeftRight256Java8BoxedLongImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - LeftRight256Java8BoxedLongImpl(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UNSAFE.putOrderedLong(this, OFFSET, update); - } - - public boolean compareAndSet(long current, long update) { - return UNSAFE.compareAndSwapLong(this, OFFSET, current, update); - } - - public long getAndSet(long update) { - return UNSAFE.getAndSetLong(this, OFFSET, update); - } - - public long getAndAdd(long delta) { - return UNSAFE.getAndAddLong(this, OFFSET, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256Java8BoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256Java8BoxedObject.java deleted file mode 100644 index 6679e892b..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256Java8BoxedObject.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class LeftRight256Java8BoxedObject extends LeftRight256Java8BoxedObjectImpl { - public volatile long r01, r02, r03, r04, r05, r06, r07, r08 = 7; - public volatile long r09, r10, r11, r12, r13, r14, r15, r16 = 8; - - @Override public long sum() { - return - p01 + p02 + p03 + p04 + p05 + p06 + p07 + p08 + - p09 + p10 + p11 + p12 + p13 + p14 + p15 + - r01 + r02 + r03 + r04 + r05 + r06 + r07 + r08 + - r09 + r10 + r11 + r12 + r13 + r14 + r15 + r16; - } - - LeftRight256Java8BoxedObject(Object initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class LeftRight256Java8BoxedObjectImpl extends LeftPadding120 implements BoxedObject { - public volatile Object value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = LeftRight256Java8BoxedObjectImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - LeftRight256Java8BoxedObjectImpl(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UNSAFE.putOrderedObject(this, OFFSET, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UNSAFE.compareAndSwapObject(this, OFFSET, current, update); - } - - public Object getAndSet(Object update) { - return UNSAFE.getAndSetObject(this, OFFSET, update); - } -} diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256JavaXBoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256JavaXBoxedInt.java deleted file mode 100644 index 5fb91556b..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256JavaXBoxedInt.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class LeftRight256JavaXBoxedInt extends LeftRight256JavaXBoxedIntImpl { - public volatile long r01, r02, r03, r04, r05, r06, r07, r08 = 7; - public volatile long r09, r10, r11, r12, r13, r14, r15, r16 = 8; - @Override public long sum() { - return - p01 + p02 + p03 + p04 + p05 + p06 + p07 + p08 + - p09 + p10 + p11 + p12 + p13 + p14 + p15 + - r01 + r02 + r03 + r04 + r05 + r06 + r07 + r08 + - r09 + r10 + r11 + r12 + r13 + r14 + r15 + r16; - } - - LeftRight256JavaXBoxedInt(int initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class LeftRight256JavaXBoxedIntImpl extends LeftPadding120 implements BoxedInt { - public volatile int value; - - private static final AtomicIntegerFieldUpdater UPDATER = - AtomicIntegerFieldUpdater.newUpdater(LeftRight256JavaXBoxedIntImpl.class, "value"); - - LeftRight256JavaXBoxedIntImpl(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(int current, int update) { - return UPDATER.compareAndSet(this, current, update); - } - - public int getAndSet(int update) { - return UPDATER.getAndSet(this, update); - } - - public int getAndAdd(int delta) { - return UPDATER.getAndAdd(this, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256JavaXBoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256JavaXBoxedLong.java deleted file mode 100644 index 2a2db927a..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256JavaXBoxedLong.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicLongFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class LeftRight256JavaXBoxedLong extends LeftRight256JavaXBoxedLongImpl { - public volatile long r01, r02, r03, r04, r05, r06, r07, r08 = 7; - public volatile long r09, r10, r11, r12, r13, r14, r15, r16 = 8; - @Override public long sum() { - return - p01 + p02 + p03 + p04 + p05 + p06 + p07 + p08 + - p09 + p10 + p11 + p12 + p13 + p14 + p15 + - r01 + r02 + r03 + r04 + r05 + r06 + r07 + r08 + - r09 + r10 + r11 + r12 + r13 + r14 + r15 + r16; - } - - LeftRight256JavaXBoxedLong(long initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class LeftRight256JavaXBoxedLongImpl extends LeftPadding120 implements BoxedLong { - public volatile long value; - - private static final AtomicLongFieldUpdater UPDATER = - AtomicLongFieldUpdater.newUpdater(LeftRight256JavaXBoxedLongImpl.class, "value"); - - LeftRight256JavaXBoxedLongImpl(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(long current, long update) { - return UPDATER.compareAndSet(this, current, update); - } - - public long getAndSet(long update) { - return UPDATER.getAndSet(this, update); - } - - public long getAndAdd(long delta) { - return UPDATER.getAndAdd(this, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256JavaXBoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256JavaXBoxedObject.java deleted file mode 100644 index 2bf4e885c..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/LeftRight256JavaXBoxedObject.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class LeftRight256JavaXBoxedObject extends LeftRight256JavaXBoxedObjectImpl { - public volatile long r01, r02, r03, r04, r05, r06, r07, r08 = 7; - public volatile long r09, r10, r11, r12, r13, r14, r15, r16 = 8; - @Override public long sum() { - return - p01 + p02 + p03 + p04 + p05 + p06 + p07 + p08 + - p09 + p10 + p11 + p12 + p13 + p14 + p15 + - r01 + r02 + r03 + r04 + r05 + r06 + r07 + r08 + - r09 + r10 + r11 + r12 + r13 + r14 + r15 + r16; - } - - LeftRight256JavaXBoxedObject(Object initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class LeftRight256JavaXBoxedObjectImpl extends LeftPadding120 implements BoxedObject { - public volatile Object value; - - private static final AtomicReferenceFieldUpdater UPDATER = - AtomicReferenceFieldUpdater.newUpdater(LeftRight256JavaXBoxedObjectImpl.class, Object.class, "value"); - - LeftRight256JavaXBoxedObjectImpl(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UPDATER.compareAndSet(this, current, update); - } - - public Object getAndSet(Object update) { - return UPDATER.getAndSet(this, update); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJava7BoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJava7BoxedInt.java deleted file mode 100644 index e4a627806..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJava7BoxedInt.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class NormalJava7BoxedInt implements BoxedInt { - public volatile int value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = NormalJava7BoxedInt.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - NormalJava7BoxedInt(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UNSAFE.putOrderedInt(this, OFFSET, update); - } - - public boolean compareAndSet(int current, int update) { - return UNSAFE.compareAndSwapInt(this, OFFSET, current, update); - } - - public int getAndSet(int update) { - int current = value; - while (!UNSAFE.compareAndSwapInt(this, OFFSET, current, update)) - current = value; - return current; - } - - public int getAndAdd(int delta) { - int current; - do { - current = UNSAFE.getIntVolatile(this, OFFSET); - } while (!UNSAFE.compareAndSwapInt(this, OFFSET, current, current+delta)); - return current; - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJava7BoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJava7BoxedLong.java deleted file mode 100644 index 069a3c745..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJava7BoxedLong.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class NormalJava7BoxedLong implements BoxedLong { - public volatile long value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = NormalJava7BoxedLong.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - NormalJava7BoxedLong(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UNSAFE.putOrderedLong(this, OFFSET, update); - } - - public boolean compareAndSet(long current, long update) { - return UNSAFE.compareAndSwapLong(this, OFFSET, current, update); - } - - public long getAndSet(long update) { - long current = value; - while (!UNSAFE.compareAndSwapLong(this, OFFSET, current, update)) - current = value; - return current; - } - - public long getAndAdd(long delta) { - long current; - do { - current = UNSAFE.getLongVolatile(this, OFFSET); - } while (!UNSAFE.compareAndSwapLong(this, OFFSET, current, current+delta)); - return current; - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJava7BoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJava7BoxedObject.java deleted file mode 100644 index 48bc50ec8..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJava7BoxedObject.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class NormalJava7BoxedObject implements BoxedObject { - public volatile Object value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = NormalJava7BoxedObject.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - NormalJava7BoxedObject(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UNSAFE.putOrderedObject(this, OFFSET, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UNSAFE.compareAndSwapObject(this, OFFSET, current, update); - } - - public Object getAndSet(Object update) { - Object current = value; - while (!UNSAFE.compareAndSwapObject(this, OFFSET, current, update)) - current = value; - return current; - } -} diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJava8BoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJava8BoxedInt.java deleted file mode 100644 index 39cfab7e9..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJava8BoxedInt.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class NormalJava8BoxedInt implements BoxedInt { - public volatile int value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = NormalJava8BoxedInt.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - NormalJava8BoxedInt(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UNSAFE.putOrderedInt(this, OFFSET, update); - } - - public boolean compareAndSet(int current, int update) { - return UNSAFE.compareAndSwapInt(this, OFFSET, current, update); - } - - public int getAndSet(int update) { - return UNSAFE.getAndSetInt(this, OFFSET, update); - } - - public int getAndAdd(int delta) { - return UNSAFE.getAndAddInt(this, OFFSET, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJava8BoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJava8BoxedLong.java deleted file mode 100644 index a60b1768b..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJava8BoxedLong.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class NormalJava8BoxedLong implements BoxedLong { - public volatile long value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = NormalJava8BoxedLong.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - NormalJava8BoxedLong(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UNSAFE.putOrderedLong(this, OFFSET, update); - } - - public boolean compareAndSet(long current, long update) { - return UNSAFE.compareAndSwapLong(this, OFFSET, current, update); - } - - public long getAndSet(long update) { - return UNSAFE.getAndSetLong(this, OFFSET, update); - } - - public long getAndAdd(long delta) { - return UNSAFE.getAndAddLong(this, OFFSET, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJava8BoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJava8BoxedObject.java deleted file mode 100644 index 10aa5f42d..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJava8BoxedObject.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class NormalJava8BoxedObject implements BoxedObject { - public volatile Object value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = NormalJava8BoxedObject.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - NormalJava8BoxedObject(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UNSAFE.putOrderedObject(this, OFFSET, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UNSAFE.compareAndSwapObject(this, OFFSET, current, update); - } - - public Object getAndSet(Object update) { - return UNSAFE.getAndSetObject(this, OFFSET, update); - } -} diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJavaXBoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJavaXBoxedInt.java deleted file mode 100644 index d0a1c1e97..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJavaXBoxedInt.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class NormalJavaXBoxedInt implements BoxedInt { - public volatile int value; - - private static final AtomicIntegerFieldUpdater UPDATER = - AtomicIntegerFieldUpdater.newUpdater(NormalJavaXBoxedInt.class, "value"); - - NormalJavaXBoxedInt(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(int current, int update) { - return UPDATER.compareAndSet(this, current, update); - } - - public int getAndSet(int update) { - return UPDATER.getAndSet(this, update); - } - - public int getAndAdd(int delta) { - return UPDATER.getAndAdd(this, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJavaXBoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJavaXBoxedLong.java deleted file mode 100644 index ef5525aa1..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJavaXBoxedLong.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicLongFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class NormalJavaXBoxedLong implements BoxedLong { - - public volatile long value; - - private static final AtomicLongFieldUpdater UPDATER = - AtomicLongFieldUpdater.newUpdater(NormalJavaXBoxedLong.class, "value"); - - NormalJavaXBoxedLong(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(long current, long update) { - return UPDATER.compareAndSet(this, current, update); - } - - public long getAndSet(long update) { - return UPDATER.getAndSet(this, update); - } - - public long getAndAdd(long delta) { - return UPDATER.getAndAdd(this, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJavaXBoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJavaXBoxedObject.java deleted file mode 100644 index 12368acd2..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/NormalJavaXBoxedObject.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class NormalJavaXBoxedObject implements BoxedObject { - public volatile Object value; - - private static final AtomicReferenceFieldUpdater UPDATER = - AtomicReferenceFieldUpdater.newUpdater(NormalJavaXBoxedObject.class, Object.class, "value"); - - NormalJavaXBoxedObject(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UPDATER.compareAndSet(this, current, update); - } - - public Object getAndSet(Object update) { - return UPDATER.getAndSet(this, update); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128Java7BoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128Java7BoxedInt.java deleted file mode 100644 index 347bbe82b..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128Java7BoxedInt.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Right128Java7BoxedInt extends Right128Java7BoxedIntImpl { - public volatile long p1, p2, p3, p4, p5, p6, p7, p8 = 7; - public volatile long p9, p10, p11, p12, p13, p14, p15 = 7; - public long sum() { - return p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + - p9 + p10 + p11 + p12 + p13 + p14 + p15; - } - - Right128Java7BoxedInt(int initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class Right128Java7BoxedIntImpl implements BoxedInt { - public volatile int value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Right128Java7BoxedIntImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Right128Java7BoxedIntImpl(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UNSAFE.putOrderedInt(this, OFFSET, update); - } - - public boolean compareAndSet(int current, int update) { - return UNSAFE.compareAndSwapInt(this, OFFSET, current, update); - } - - public int getAndSet(int update) { - int current = value; - while (!UNSAFE.compareAndSwapInt(this, OFFSET, current, update)) - current = value; - return current; - } - - public int getAndAdd(int delta) { - int current; - do { - current = UNSAFE.getIntVolatile(this, OFFSET); - } while (!UNSAFE.compareAndSwapInt(this, OFFSET, current, current+delta)); - return current; - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128Java7BoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128Java7BoxedLong.java deleted file mode 100644 index d1d62d8a1..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128Java7BoxedLong.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Right128Java7BoxedLong extends Right128Java7BoxedLongImpl { - public volatile long p1, p2, p3, p4, p5, p6, p7, p8 = 7; - public volatile long p9, p10, p11, p12, p13, p14, p15 = 7; - public long sum() { - return p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + - p9 + p10 + p11 + p12 + p13 + p14 + p15; - } - - Right128Java7BoxedLong(long initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class Right128Java7BoxedLongImpl implements BoxedLong { - public volatile long value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Right128Java7BoxedLongImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Right128Java7BoxedLongImpl(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UNSAFE.putOrderedLong(this, OFFSET, update); - } - - public boolean compareAndSet(long current, long update) { - return UNSAFE.compareAndSwapLong(this, OFFSET, current, update); - } - - public long getAndSet(long update) { - long current = value; - while (!UNSAFE.compareAndSwapLong(this, OFFSET, current, update)) - current = value; - return current; - } - - public long getAndAdd(long delta) { - long current; - do { - current = UNSAFE.getLongVolatile(this, OFFSET); - } while (!UNSAFE.compareAndSwapLong(this, OFFSET, current, current+delta)); - return current; - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128Java7BoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128Java7BoxedObject.java deleted file mode 100644 index 044dd9e6d..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128Java7BoxedObject.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Right128Java7BoxedObject extends Right128Java7BoxedObjectImpl { - public volatile long p1, p2, p3, p4, p5, p6, p7, p8 = 7; - public volatile long p9, p10, p11, p12, p13, p14, p15 = 7; - public long sum() { - return p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + - p9 + p10 + p11 + p12 + p13 + p14 + p15; - } - - Right128Java7BoxedObject(Object initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class Right128Java7BoxedObjectImpl implements BoxedObject { - public volatile Object value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Right128Java7BoxedObjectImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Right128Java7BoxedObjectImpl(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UNSAFE.putOrderedObject(this, OFFSET, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UNSAFE.compareAndSwapObject(this, OFFSET, current, update); - } - - public Object getAndSet(Object update) { - Object current = value; - while (!UNSAFE.compareAndSwapObject(this, OFFSET, current, update)) - current = value; - return current; - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128Java8BoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128Java8BoxedInt.java deleted file mode 100644 index ecda8c0eb..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128Java8BoxedInt.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Right128Java8BoxedInt extends Right128Java8BoxedIntImpl { - public volatile long p1, p2, p3, p4, p5, p6, p7, p8 = 7; - public volatile long p9, p10, p11, p12, p13, p14, p15 = 7; - public long sum() { - return p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + - p9 + p10 + p11 + p12 + p13 + p14 + p15; - } - - Right128Java8BoxedInt(int initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class Right128Java8BoxedIntImpl implements BoxedInt { - public volatile int value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Right128Java8BoxedIntImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Right128Java8BoxedIntImpl(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UNSAFE.putOrderedInt(this, OFFSET, update); - } - - public boolean compareAndSet(int current, int update) { - return UNSAFE.compareAndSwapInt(this, OFFSET, current, update); - } - - public int getAndSet(int update) { - return UNSAFE.getAndSetInt(this, OFFSET, update); - } - - public int getAndAdd(int delta) { - return UNSAFE.getAndAddInt(this, OFFSET, delta); - } -} diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128Java8BoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128Java8BoxedLong.java deleted file mode 100644 index 86c0a41a0..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128Java8BoxedLong.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Right128Java8BoxedLong extends Right128Java8BoxedLongImpl { - public volatile long p1, p2, p3, p4, p5, p6, p7, p8 = 7; - public volatile long p9, p10, p11, p12, p13, p14, p15 = 7; - public long sum() { - return p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + - p9 + p10 + p11 + p12 + p13 + p14 + p15; - } - - Right128Java8BoxedLong(long initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class Right128Java8BoxedLongImpl implements BoxedLong { - public volatile long value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Right128Java8BoxedLongImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Right128Java8BoxedLongImpl(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UNSAFE.putOrderedLong(this, OFFSET, update); - } - - public boolean compareAndSet(long current, long update) { - return UNSAFE.compareAndSwapLong(this, OFFSET, current, update); - } - - public long getAndSet(long update) { - return UNSAFE.getAndSetLong(this, OFFSET, update); - } - - public long getAndAdd(long delta) { - return UNSAFE.getAndAddLong(this, OFFSET, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128Java8BoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128Java8BoxedObject.java deleted file mode 100644 index 792da0eb7..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128Java8BoxedObject.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Right128Java8BoxedObject extends Right128Java8BoxedObjectImpl { - public volatile long p1, p2, p3, p4, p5, p6, p7, p8 = 7; - public volatile long p9, p10, p11, p12, p13, p14, p15 = 7; - public long sum() { - return p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + - p9 + p10 + p11 + p12 + p13 + p14 + p15; - } - - Right128Java8BoxedObject(Object initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class Right128Java8BoxedObjectImpl implements BoxedObject { - public volatile Object value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Right128Java8BoxedObjectImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Right128Java8BoxedObjectImpl(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UNSAFE.putOrderedObject(this, OFFSET, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UNSAFE.compareAndSwapObject(this, OFFSET, current, update); - } - - public Object getAndSet(Object update) { - return UNSAFE.getAndSetObject(this, OFFSET, update); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128JavaXBoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128JavaXBoxedInt.java deleted file mode 100644 index f4b121584..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128JavaXBoxedInt.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Right128JavaXBoxedInt extends Right128JavaXBoxedIntImpl { - public volatile long p1, p2, p3, p4, p5, p6, p7, p8 = 7; - public volatile long p9, p10, p11, p12, p13, p14, p15 = 7; - public long sum() { - return p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + - p9 + p10 + p11 + p12 + p13 + p14 + p15; - } - - Right128JavaXBoxedInt(int initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class Right128JavaXBoxedIntImpl implements BoxedInt { - public volatile int value; - - private static final AtomicIntegerFieldUpdater UPDATER = - AtomicIntegerFieldUpdater.newUpdater(Right128JavaXBoxedIntImpl.class, "value"); - - Right128JavaXBoxedIntImpl(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(int current, int update) { - return UPDATER.compareAndSet(this, current, update); - } - - public int getAndSet(int update) { - return UPDATER.getAndSet(this, update); - } - - public int getAndAdd(int delta) { - return UPDATER.getAndAdd(this, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128JavaXBoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128JavaXBoxedLong.java deleted file mode 100644 index 4448412b3..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128JavaXBoxedLong.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicLongFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Right128JavaXBoxedLong extends Right128JavaXBoxedLongImpl { - public volatile long p1, p2, p3, p4, p5, p6, p7, p8 = 7; - public volatile long p9, p10, p11, p12, p13, p14, p15 = 7; - public long sum() { - return p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + - p9 + p10 + p11 + p12 + p13 + p14 + p15; - } - - Right128JavaXBoxedLong(long initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class Right128JavaXBoxedLongImpl implements BoxedLong { - public volatile long value; - - private static final AtomicLongFieldUpdater UPDATER = - AtomicLongFieldUpdater.newUpdater(Right128JavaXBoxedLongImpl.class, "value"); - - Right128JavaXBoxedLongImpl(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(long current, long update) { - return UPDATER.compareAndSet(this, current, update); - } - - public long getAndSet(long update) { - return UPDATER.getAndSet(this, update); - } - - public long getAndAdd(long delta) { - return UPDATER.getAndAdd(this, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128JavaXBoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128JavaXBoxedObject.java deleted file mode 100644 index 0df549f19..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right128JavaXBoxedObject.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Right128JavaXBoxedObject extends Right128JavaXBoxedObjectImpl { - public volatile long p1, p2, p3, p4, p5, p6, p7, p8 = 7; - public volatile long p9, p10, p11, p12, p13, p14, p15 = 7; - public long sum() { - return p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + - p9 + p10 + p11 + p12 + p13 + p14 + p15; - } - - Right128JavaXBoxedObject(Object initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class Right128JavaXBoxedObjectImpl implements BoxedObject { - public volatile Object value; - - private static final AtomicReferenceFieldUpdater UPDATER = - AtomicReferenceFieldUpdater.newUpdater(Right128JavaXBoxedObjectImpl.class, Object.class, "value"); - - Right128JavaXBoxedObjectImpl(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UPDATER.compareAndSet(this, current, update); - } - - public Object getAndSet(Object update) { - return UPDATER.getAndSet(this, update); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64Java7BoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64Java7BoxedInt.java deleted file mode 100644 index 9c9b92650..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64Java7BoxedInt.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class Right64Java7BoxedIntImpl implements BoxedInt { - public volatile int value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Right64Java7BoxedIntImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Right64Java7BoxedIntImpl(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UNSAFE.putOrderedInt(this, OFFSET, update); - } - - public boolean compareAndSet(int current, int update) { - return UNSAFE.compareAndSwapInt(this, OFFSET, current, update); - } - - public int getAndSet(int update) { - int current = value; - while (!UNSAFE.compareAndSwapInt(this, OFFSET, current, update)) - current = value; - return current; - } - - public int getAndAdd(int delta) { - int current; - do { - current = UNSAFE.getIntVolatile(this, OFFSET); - } while (!UNSAFE.compareAndSwapInt(this, OFFSET, current, current+delta)); - return current; - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Right64Java7BoxedInt extends Right64Java7BoxedIntImpl { - public volatile long p1, p2, p3, p4, p5, p6, p7 = 7; - public long sum() { return p1 + p2 + p3 + p4 + p5 + p6 + p7; } - - Right64Java7BoxedInt(int initialValue) { - super(initialValue); - } -} diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64Java7BoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64Java7BoxedLong.java deleted file mode 100644 index e9b5b1df5..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64Java7BoxedLong.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class Right64Java7BoxedLongImpl implements BoxedLong { - public volatile long value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Right64Java7BoxedLongImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Right64Java7BoxedLongImpl(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UNSAFE.putOrderedLong(this, OFFSET, update); - } - - public boolean compareAndSet(long current, long update) { - return UNSAFE.compareAndSwapLong(this, OFFSET, current, update); - } - - public long getAndSet(long update) { - long current = value; - while (!UNSAFE.compareAndSwapLong(this, OFFSET, current, update)) - current = value; - return current; - } - - public long getAndAdd(long delta) { - long current; - do { - current = UNSAFE.getLongVolatile(this, OFFSET); - } while (!UNSAFE.compareAndSwapLong(this, OFFSET, current, current+delta)); - return current; - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Right64Java7BoxedLong extends Right64Java7BoxedLongImpl { - public volatile long p1, p2, p3, p4, p5, p6, p7 = 7; - public long sum() { return p1 + p2 + p3 + p4 + p5 + p6 + p7; } - - Right64Java7BoxedLong(long initialValue) { - super(initialValue); - } -} diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64Java7BoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64Java7BoxedObject.java deleted file mode 100644 index 037bac470..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64Java7BoxedObject.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class Right64Java7BoxedObjectImpl implements BoxedObject { - public volatile Object value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Right64Java7BoxedObjectImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Right64Java7BoxedObjectImpl(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UNSAFE.putOrderedObject(this, OFFSET, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UNSAFE.compareAndSwapObject(this, OFFSET, current, update); - } - - public Object getAndSet(Object update) { - Object current = value; - while (!UNSAFE.compareAndSwapObject(this, OFFSET, current, update)) - current = value; - return current; - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Right64Java7BoxedObject extends Right64Java7BoxedObjectImpl { - public volatile long p1, p2, p3, p4, p5, p6, p7 = 7; - public long sum() { return p1 + p2 + p3 + p4 + p5 + p6 + p7; } - - Right64Java7BoxedObject(Object initialValue) { - super(initialValue); - } -} diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64Java8BoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64Java8BoxedInt.java deleted file mode 100644 index f7838101a..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64Java8BoxedInt.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class Right64Java8BoxedIntImpl implements BoxedInt { - public volatile int value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Right64Java8BoxedIntImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Right64Java8BoxedIntImpl(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UNSAFE.putOrderedInt(this, OFFSET, update); - } - - public boolean compareAndSet(int current, int update) { - return UNSAFE.compareAndSwapInt(this, OFFSET, current, update); - } - - public int getAndSet(int update) { - return UNSAFE.getAndSetInt(this, OFFSET, update); - } - - public int getAndAdd(int delta) { - return UNSAFE.getAndAddInt(this, OFFSET, delta); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Right64Java8BoxedInt extends Right64Java8BoxedIntImpl { - public volatile long p1, p2, p3, p4, p5, p6, p7 = 7; - public long sum() { return p1 + p2 + p3 + p4 + p5 + p6 + p7; } - - Right64Java8BoxedInt(int initialValue) { - super(initialValue); - } -} diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64Java8BoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64Java8BoxedLong.java deleted file mode 100644 index 8400074a4..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64Java8BoxedLong.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class Right64Java8BoxedLongImpl implements BoxedLong { - public volatile long value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Right64Java8BoxedLongImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Right64Java8BoxedLongImpl(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UNSAFE.putOrderedLong(this, OFFSET, update); - } - - public boolean compareAndSet(long current, long update) { - return UNSAFE.compareAndSwapLong(this, OFFSET, current, update); - } - - public long getAndSet(long update) { - return UNSAFE.getAndSetLong(this, OFFSET, update); - } - - public long getAndAdd(long delta) { - return UNSAFE.getAndAddLong(this, OFFSET, delta); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Right64Java8BoxedLong extends Right64Java8BoxedLongImpl { - public volatile long p1, p2, p3, p4, p5, p6, p7 = 7; - public long sum() { return p1 + p2 + p3 + p4 + p5 + p6 + p7; } - - Right64Java8BoxedLong(long initialValue) { - super(initialValue); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64Java8BoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64Java8BoxedObject.java deleted file mode 100644 index ecdef6a79..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64Java8BoxedObject.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class Right64Java8BoxedObjectImpl implements BoxedObject { - public volatile Object value; - private static final long OFFSET; - private static final Unsafe UNSAFE = (Unsafe) UnsafeAccess.getInstance(); - - static { - try { - Field field = Right64Java8BoxedObjectImpl.class.getDeclaredField("value"); - OFFSET = UNSAFE.objectFieldOffset(field); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - Right64Java8BoxedObjectImpl(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UNSAFE.putOrderedObject(this, OFFSET, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UNSAFE.compareAndSwapObject(this, OFFSET, current, update); - } - - public Object getAndSet(Object update) { - return UNSAFE.getAndSetObject(this, OFFSET, update); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Right64Java8BoxedObject extends Right64Java8BoxedObjectImpl { - public volatile long p1, p2, p3, p4, p5, p6, p7 = 7; - public long sum() { return p1 + p2 + p3 + p4 + p5 + p6 + p7; } - - Right64Java8BoxedObject(Object initialValue) { - super(initialValue); - } -} diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64JavaXBoxedInt.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64JavaXBoxedInt.java deleted file mode 100644 index e96b2b82f..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64JavaXBoxedInt.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Right64JavaXBoxedInt extends Right64JavaXBoxedIntImpl { - public volatile long p1, p2, p3, p4, p5, p6, p7 = 7; - public long sum() { return p1 + p2 + p3 + p4 + p5 + p6 + p7; } - - Right64JavaXBoxedInt(int initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class Right64JavaXBoxedIntImpl implements BoxedInt { - public volatile int value; - - private static final AtomicIntegerFieldUpdater UPDATER = - AtomicIntegerFieldUpdater.newUpdater(Right64JavaXBoxedIntImpl.class, "value"); - - Right64JavaXBoxedIntImpl(int initialValue) { - this.value = initialValue; - } - - public int volatileGet() { - return value; - } - - public void volatileSet(int update) { - value = update; - } - - public void lazySet(int update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(int current, int update) { - return UPDATER.compareAndSet(this, current, update); - } - - public int getAndSet(int update) { - return UPDATER.getAndSet(this, update); - } - - public int getAndAdd(int delta) { - return UPDATER.getAndAdd(this, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64JavaXBoxedLong.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64JavaXBoxedLong.java deleted file mode 100644 index e3892b265..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64JavaXBoxedLong.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicLongFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Right64JavaXBoxedLong extends Right64JavaXBoxedLongImpl { - public volatile long p1, p2, p3, p4, p5, p6, p7 = 7; - public long sum() { return p1 + p2 + p3 + p4 + p5 + p6 + p7; } - - Right64JavaXBoxedLong(long initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class Right64JavaXBoxedLongImpl implements BoxedLong { - public volatile long value; - - private static final AtomicLongFieldUpdater UPDATER = - AtomicLongFieldUpdater.newUpdater(Right64JavaXBoxedLongImpl.class, "value"); - - Right64JavaXBoxedLongImpl(long initialValue) { - this.value = initialValue; - } - - public long volatileGet() { - return value; - } - - public void volatileSet(long update) { - value = update; - } - - public void lazySet(long update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(long current, long update) { - return UPDATER.compareAndSet(this, current, update); - } - - public long getAndSet(long update) { - return UPDATER.getAndSet(this, update); - } - - public long getAndAdd(long delta) { - return UPDATER.getAndAdd(this, delta); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64JavaXBoxedObject.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64JavaXBoxedObject.java deleted file mode 100644 index de464ad6b..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/Right64JavaXBoxedObject.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; - -import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -final class Right64JavaXBoxedObject extends Right64JavaXBoxedObjectImpl { - public volatile long p1, p2, p3, p4, p5, p6, p7 = 7; - public long sum() { return p1 + p2 + p3 + p4 + p5 + p6 + p7; } - - Right64JavaXBoxedObject(Object initialValue) { - super(initialValue); - } -} - -/** - * INTERNAL API — used in the implementation of - * `monix.execution.atomic.Atomic`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi -abstract class Right64JavaXBoxedObjectImpl implements BoxedObject { - public volatile Object value; - - private static final AtomicReferenceFieldUpdater UPDATER = - AtomicReferenceFieldUpdater.newUpdater(Right64JavaXBoxedObjectImpl.class, Object.class, "value"); - - Right64JavaXBoxedObjectImpl(Object initialValue) { - this.value = initialValue; - } - - public Object volatileGet() { - return value; - } - - public void volatileSet(Object update) { - value = update; - } - - public void lazySet(Object update) { - UPDATER.lazySet(this, update); - } - - public boolean compareAndSet(Object current, Object update) { - return UPDATER.compareAndSet(this, current, update); - } - - public Object getAndSet(Object update) { - return UPDATER.getAndSet(this, update); - } -} \ No newline at end of file diff --git a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/UnsafeAccess.java b/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/UnsafeAccess.java deleted file mode 100644 index a7c3e6bb4..000000000 --- a/monix-execution/jvm/src/main/java/monix/execution/internal/atomic/UnsafeAccess.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.internal.atomic; - -import monix.execution.internal.InternalApi; -import scala.util.control.NonFatal; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -/** - * INTERNAL API — Provides access to `sun.misc.Unsafe`. - * - * Being internal it can always change between minor versions, - * providing no backwards compatibility guarantees and is only public - * because Java does not provide the capability of marking classes as - * "internal" to a package and all its sub-packages. - */ -@InternalApi public final class UnsafeAccess { - private static final Object UNSAFE; - - /** True in case the underlying platform supports - * `sun.misc.Unsafe`, `false` otherwise. - * - * In case [[IS_ALLOWED]] is set to `false`, then - * [[IS_AVAILABLE]] is also going to be set to `false`. - */ - public static final boolean IS_AVAILABLE; - - /** - * True in case the `sun.misc.Unsafe` usage is disabled - * by means of setting `-Dmonix.environment.canUseUnsafe=false`. - * - * In case this is set to `false`, then [[IS_AVAILABLE]] is - * also going to be set to `false`. - */ - public static final boolean IS_ALLOWED; - - /** - * True in case the underlying platform supports Java 8's - * `Unsafe` features for platform intrinsics. - */ - public static final boolean HAS_JAVA8_INTRINSICS; - - /** - * Some platforms do not expose a `theUnsafe` private reference - * to a `sun.misc.Unsafe` instance, but unfortunately some libraries - * (notably version 2.0 of JCTools) depends on this. - * - * This reference is set to `true` in case `Unsafe.theUnsafe` exists, - * or `false` otherwise. - */ - public static final boolean IS_OPENJDK_COMPATIBLE; - - /** - * Returns a reusable reference for `sun.misc.Unsafe`. - */ - public static Object getInstance() { - if (UNSAFE == null) - throw new AssertionError( - "Platform does not support sun.misc.Unsafe, " + - "please file a bug report for the Monix project " + - "(see https://monix.io)" - ); - - return UNSAFE; - } - - private static boolean isUnsafeAllowed() { - String env = System.getProperty("monix.environment.canUseUnsafe", "").trim().toLowerCase(); - boolean disabled = env.equals("no") || env.equals("false") || env.equals("0"); - return !disabled; - } - - static { - Object instance = null; - boolean isJava8 = false; - boolean isAllowed = false; - boolean isOpenJDKCompatible = false; - - try { - isAllowed = isUnsafeAllowed(); - - if (isAllowed) { - Class cls = Class.forName("sun.misc.Unsafe", true, UnsafeAccess.class.getClassLoader()); - try { - Field field = cls.getDeclaredField("theUnsafe"); - field.setAccessible(true); - instance = field.get(null); - if (instance == null) throw null; - isOpenJDKCompatible = true; - } - catch (Exception ex) { - if (!NonFatal.apply(ex)) { - throw ex; - } - else { - // Workaround for older Android versions or other non-OpenJDK - // implementations that may not have a `theUnsafe` instance - Constructor c = cls.getDeclaredConstructor(); - c.setAccessible(true); - instance = c.newInstance(); - } - } - - boolean supportsGetAndSet = false; - try { - cls.getMethod("getAndSetObject", Object.class, Long.TYPE, Object.class); - supportsGetAndSet = true; - } - catch (Exception e) { - if (!NonFatal.apply(e)) throw e; - } - - boolean supportsGetAndAddInt = false; - try { - cls.getMethod("getAndAddInt", Object.class, Long.TYPE, Integer.TYPE); - supportsGetAndAddInt = true; - } - catch (Exception e) { - if (!NonFatal.apply(e)) throw e; - } - - boolean supportsGetAndAddLong = false; - try { - cls.getMethod("getAndAddLong", Object.class, Long.TYPE, Long.TYPE); - supportsGetAndAddLong = true; - } - catch (Exception e) { - if (!NonFatal.apply(e)) throw e; - } - - boolean supportsMemoryFences = false; - try { - Method m = cls.getDeclaredMethod("fullFence"); - supportsMemoryFences = m != null; - } - catch (Exception e) { - if (!NonFatal.apply(e)) throw e; - } - - isJava8 = supportsGetAndSet && - supportsGetAndAddInt && - supportsGetAndAddLong && - supportsMemoryFences; - } - } - catch (Exception ex) { - instance = null; - isJava8 = false; - if (!NonFatal.apply(ex)) - throw new RuntimeException(ex); - } - finally { - UNSAFE = instance; - IS_AVAILABLE = instance != null; - IS_ALLOWED = isAllowed; - HAS_JAVA8_INTRINSICS = isJava8; - IS_OPENJDK_COMPATIBLE = isOpenJDKCompatible; - } - } -} diff --git a/monix-execution/jvm/src/main/scala/monix/execution/cancelables/ChainedCancelable.scala b/monix-execution/jvm/src/main/scala/monix/execution/cancelables/ChainedCancelable.scala index ecc8f8aae..cf54ca967 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/cancelables/ChainedCancelable.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/cancelables/ChainedCancelable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.execution.cancelables import java.lang.ref.WeakReference import monix.execution.Cancelable import monix.execution.Cancelable.IsDummy -import monix.execution.atomic.{AtomicAny, PaddingStrategy} +import monix.execution.atomic.{ AtomicAny, PaddingStrategy } import monix.execution.internal.exceptions.matchError /** Represents a [[monix.execution.Cancelable]] whose underlying @@ -107,13 +107,13 @@ final class ChainedCancelable private (private val state: AtomicAny[AnyRef]) ext state.getAndSet(Canceled) match { case null | Canceled => () case ref: Cancelable => ref.cancel() - case wr: WeakReference[_] => + case wr: WeakReference[?] => val cc = wr.get.asInstanceOf[CC] if (cc != null) cc.cancel() case other => // $COVERAGE-OFF$ matchError(other) - // $COVERAGE-ON$ + // $COVERAGE-ON$ } } @@ -125,7 +125,7 @@ final class ChainedCancelable private (private val state: AtomicAny[AnyRef]) ext case Canceled => value.cancel() return - case wr: WeakReference[_] => + case wr: WeakReference[?] => val cc = wr.get.asInstanceOf[CC] if (cc != null) cc.update(value) return @@ -178,7 +178,7 @@ final class ChainedCancelable private (private val state: AtomicAny[AnyRef]) ext // Short-circuit if we discover a cycle if (cursor eq this) return cursor.state.get() match { - case ref2: WeakReference[_] => + case ref2: WeakReference[?] => cursor = ref2.get.asInstanceOf[CC] if (cursor eq null) { cursor = null @@ -202,7 +202,7 @@ final class ChainedCancelable private (private val state: AtomicAny[AnyRef]) ext case null => () case Canceled => cancel() case _: IsDummy => () - case w: WeakReference[_] => + case w: WeakReference[?] => val cc = w.get if (cc != null) cc.asInstanceOf[CC].update(newRoot) case prev: Cancelable => @@ -210,7 +210,7 @@ final class ChainedCancelable private (private val state: AtomicAny[AnyRef]) ext case other => // $COVERAGE-OFF$ matchError(other) - // $COVERAGE-ON$ + // $COVERAGE-ON$ } } } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/internal/CancelableFutureForPlatform.scala b/monix-execution/jvm/src/main/scala/monix/execution/internal/CancelableFutureForPlatform.scala index 1ef39750e..f0bb32c68 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/internal/CancelableFutureForPlatform.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/internal/CancelableFutureForPlatform.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,10 +18,10 @@ package monix.execution package internal -import java.util.concurrent.{CancellationException, CompletableFuture, CompletionException} +import java.util.concurrent.{ CancellationException, CompletableFuture, CompletionException } import java.util.function.BiFunction import scala.concurrent.ExecutionContext -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } private[execution] abstract class CancelableFutureForPlatform { /** diff --git a/monix-execution/jvm/src/main/scala/monix/execution/internal/DefaultUncaughtExceptionReporter.scala b/monix-execution/jvm/src/main/scala/monix/execution/internal/DefaultUncaughtExceptionReporter.scala index 2d32a2b04..08c1f3b62 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/internal/DefaultUncaughtExceptionReporter.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/internal/DefaultUncaughtExceptionReporter.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/jvm/src/main/scala/monix/execution/internal/FutureUtilsForPlatform.scala b/monix-execution/jvm/src/main/scala/monix/execution/internal/FutureUtilsForPlatform.scala index 73d09bf9d..3126101a3 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/internal/FutureUtilsForPlatform.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/internal/FutureUtilsForPlatform.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,8 +20,8 @@ package internal import java.util.concurrent.CompletableFuture import monix.execution.CancelableFuture -import scala.concurrent.{ExecutionContext, Future} -import scala.util.{Failure, Success} +import scala.concurrent.{ ExecutionContext, Future } +import scala.util.{ Failure, Success } private[execution] abstract class FutureUtilsForPlatform { self => /** diff --git a/monix-execution/jvm/src/main/scala/monix/execution/internal/Platform.scala b/monix-execution/jvm/src/main/scala/monix/execution/internal/Platform.scala index 4c957888e..bb7826db9 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/internal/Platform.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/internal/Platform.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,9 +18,9 @@ package monix.execution.internal import monix.execution.schedulers.CanBlock - import scala.annotation.nowarn -import scala.concurrent.{Await, Awaitable} +import scala.annotation.unused +import scala.concurrent.{ Await, Awaitable } import scala.concurrent.duration.Duration import scala.util.Try @@ -143,7 +143,7 @@ private[monix] object Platform { * This operation is only supported on top of the JVM, whereas for * JavaScript a dummy is provided. */ - def await[A](fa: Awaitable[A], timeout: Duration)(implicit permit: CanBlock): A = + def await[A](fa: Awaitable[A], timeout: Duration)(implicit @unused permit: CanBlock): A = Await.result(fa, timeout) /** Composes multiple errors together, meant for those cases in which @@ -162,7 +162,7 @@ private[monix] object Platform { /** Useful utility that combines an `Either` result, which is what * `MonadError#attempt` returns. */ - def composeErrors(first: Throwable, second: Either[Throwable, _]): Throwable = + def composeErrors(first: Throwable, second: Either[Throwable, Any]): Throwable = second match { case Left(e2) if first ne e2 => first.addSuppressed(e2) @@ -177,7 +177,7 @@ private[monix] object Platform { * To be used for multi-threading optimizations. Note that * in JavaScript this always returns the same value. */ - @nowarn("msg=deprecated") + @nowarn("cat=deprecation") def currentThreadId(): Long = { Thread.currentThread().getId } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/internal/ScheduledExecutors.scala b/monix-execution/jvm/src/main/scala/monix/execution/internal/ScheduledExecutors.scala index 587bfaae4..38f91e867 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/internal/ScheduledExecutors.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/internal/ScheduledExecutors.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.execution.internal import java.util.concurrent.ScheduledExecutorService import monix.execution.schedulers.ShiftedRunnable -import monix.execution.{Cancelable, Scheduler} +import monix.execution.{ Cancelable, Scheduler } import scala.concurrent.duration.TimeUnit private[execution] object ScheduledExecutors { diff --git a/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/FromCircularQueue.scala b/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/FromCircularQueue.scala index c6d97d201..9e3482b2b 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/FromCircularQueue.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/FromCircularQueue.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,14 +17,10 @@ package monix.execution.internal.collection.queues +import java.lang.invoke.VarHandle import monix.execution.ChannelType -import monix.execution.ChannelType.{SingleConsumer, SingleProducer} -import monix.execution.internal.atomic.UnsafeAccess import monix.execution.internal.collection.LowLevelConcurrentQueue import monix.execution.internal.jctools.queues.MessagePassingQueue -import sun.misc.Unsafe - -import scala.annotation.nowarn import scala.collection.mutable private[internal] abstract class FromCircularQueue[A](queue: MessagePassingQueue[A]) @@ -62,14 +58,11 @@ private[internal] object FromCircularQueue { case ChannelType.MPMC => new MPMC[A](queue) case ChannelType.MPSC => - if (UnsafeAccess.HAS_JAVA8_INTRINSICS) new Java8MPSC[A](queue) - else new Java7[A](queue, ct) + new Java8MPSC[A](queue) case ChannelType.SPMC => - if (UnsafeAccess.HAS_JAVA8_INTRINSICS) new Java8SPMC[A](queue) - else new Java7[A](queue, ct) + new Java8SPMC[A](queue) case ChannelType.SPSC => - if (UnsafeAccess.HAS_JAVA8_INTRINSICS) new Java8SPSC[A](queue) - else new Java7[A](queue, ct) + new Java8SPSC[A](queue) } private final class MPMC[A](queue: MessagePassingQueue[A]) extends FromCircularQueue[A](queue) { @@ -80,46 +73,19 @@ private[internal] object FromCircularQueue { private final class Java8SPMC[A](queue: MessagePassingQueue[A]) extends FromCircularQueue[A](queue) { - private[this] val UNSAFE = - UnsafeAccess.getInstance().asInstanceOf[Unsafe] - - def fenceOffer(): Unit = UNSAFE.fullFence() + def fenceOffer(): Unit = VarHandle.fullFence() def fencePoll(): Unit = () } private final class Java8MPSC[A](queue: MessagePassingQueue[A]) extends FromCircularQueue[A](queue) { - private[this] val UNSAFE = - UnsafeAccess.getInstance().asInstanceOf[Unsafe] - def fenceOffer(): Unit = () - def fencePoll(): Unit = UNSAFE.fullFence() + def fencePoll(): Unit = VarHandle.fullFence() } private final class Java8SPSC[A](queue: MessagePassingQueue[A]) extends FromCircularQueue[A](queue) { - private[this] val UNSAFE = - UnsafeAccess.getInstance().asInstanceOf[Unsafe] - - def fenceOffer(): Unit = UNSAFE.fullFence() - def fencePoll(): Unit = UNSAFE.fullFence() - } - - private final class Java7[A](queue: MessagePassingQueue[A], ct: ChannelType) - extends FromCircularQueue[A](queue) { - - def fenceOffer(): Unit = - if (ct.producerType == SingleProducer) { - raise() - } - - def fencePoll(): Unit = - if (ct.consumerType == SingleConsumer) { - raise() - } - - private def raise(): Unit = { - throw new IllegalAccessException("Unsafe.fullFence not supported on this platform! (please report bug)") - } + def fenceOffer(): Unit = VarHandle.fullFence() + def fencePoll(): Unit = VarHandle.fullFence() } } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/FromJavaQueue.scala b/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/FromJavaQueue.scala index e2d30aa4f..16d190c89 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/FromJavaQueue.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/FromJavaQueue.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/FromMessagePassingQueue.scala b/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/FromMessagePassingQueue.scala index 847272e75..b8a2ba5f9 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/FromMessagePassingQueue.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/FromMessagePassingQueue.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,14 +17,10 @@ package monix.execution.internal.collection.queues +import java.lang.invoke.VarHandle import monix.execution.ChannelType -import monix.execution.ChannelType.{SingleConsumer, SingleProducer} -import monix.execution.internal.atomic.UnsafeAccess import monix.execution.internal.collection.LowLevelConcurrentQueue import monix.execution.internal.jctools.queues.MessagePassingQueue -import sun.misc.Unsafe - -import scala.annotation.nowarn import scala.collection.mutable private[internal] abstract class FromMessagePassingQueue[A](queue: MessagePassingQueue[A]) @@ -59,14 +55,11 @@ private[internal] object FromMessagePassingQueue { case ChannelType.MPMC => new MPMC[A](queue) case ChannelType.MPSC => - if (UnsafeAccess.HAS_JAVA8_INTRINSICS) new Java8MPSC[A](queue) - else new Java7[A](queue, ct) + new Java8MPSC[A](queue) case ChannelType.SPMC => - if (UnsafeAccess.HAS_JAVA8_INTRINSICS) new Java8SPMC[A](queue) - else new Java7[A](queue, ct) + new Java8SPMC[A](queue) case ChannelType.SPSC => - if (UnsafeAccess.HAS_JAVA8_INTRINSICS) new Java8SPSC[A](queue) - else new Java7[A](queue, ct) + new Java8SPSC[A](queue) } private final class MPMC[A](queue: MessagePassingQueue[A]) extends FromMessagePassingQueue[A](queue) { @@ -77,46 +70,19 @@ private[internal] object FromMessagePassingQueue { private final class Java8SPMC[A](queue: MessagePassingQueue[A]) extends FromMessagePassingQueue[A](queue) { - private[this] val UNSAFE = - UnsafeAccess.getInstance().asInstanceOf[Unsafe] - - def fenceOffer(): Unit = UNSAFE.fullFence() + def fenceOffer(): Unit = VarHandle.fullFence() def fencePoll(): Unit = () } private final class Java8MPSC[A](queue: MessagePassingQueue[A]) extends FromMessagePassingQueue[A](queue) { - private[this] val UNSAFE = - UnsafeAccess.getInstance().asInstanceOf[Unsafe] - def fenceOffer(): Unit = () - def fencePoll(): Unit = UNSAFE.fullFence() + def fencePoll(): Unit = VarHandle.fullFence() } private final class Java8SPSC[A](queue: MessagePassingQueue[A]) extends FromMessagePassingQueue[A](queue) { - private[this] val UNSAFE = - UnsafeAccess.getInstance().asInstanceOf[Unsafe] - - def fenceOffer(): Unit = UNSAFE.fullFence() - def fencePoll(): Unit = UNSAFE.fullFence() - } - - private final class Java7[A](queue: MessagePassingQueue[A], ct: ChannelType) - extends FromMessagePassingQueue[A](queue) { - - def fenceOffer(): Unit = - if (ct.producerType == SingleProducer) { - raise() - } - - def fencePoll(): Unit = - if (ct.consumerType == SingleConsumer) { - raise() - } - - private def raise(): Unit = { - throw new IllegalAccessException("Unsafe.fullFence not supported on this platform! (please report bug)") - } + def fenceOffer(): Unit = VarHandle.fullFence() + def fencePoll(): Unit = VarHandle.fullFence() } } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/LowLevelConcurrentQueueBuilders.scala b/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/LowLevelConcurrentQueueBuilders.scala index a3de27783..f8d6b6914 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/LowLevelConcurrentQueueBuilders.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/LowLevelConcurrentQueueBuilders.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,13 +18,11 @@ package monix.execution.internal.collection.queues import java.util.concurrent.ConcurrentLinkedQueue -import monix.execution.{BufferCapacity, ChannelType} -import monix.execution.ChannelType.{MPMC, MPSC, SPMC, SPSC} +import monix.execution.{ BufferCapacity, ChannelType } +import monix.execution.ChannelType.{ MPMC, MPSC, SPMC, SPSC } import monix.execution.internal.Platform -import monix.execution.internal.atomic.UnsafeAccess import monix.execution.internal.collection.LowLevelConcurrentQueue import monix.execution.internal.jctools.queues._ -import monix.execution.internal.jctools.queues.atomic._ private[internal] trait LowLevelConcurrentQueueBuilders { /** @@ -39,59 +37,27 @@ private[internal] trait LowLevelConcurrentQueueBuilders { /** * Builds a bounded `ConcurrentQueue` reference. */ - private def bounded[A](capacity: Int, ct: ChannelType, fenced: Boolean): LowLevelConcurrentQueue[A] = - if (UnsafeAccess.IS_OPENJDK_COMPATIBLE) { - // Support for memory fences in Unsafe is only available in Java 8+ - if (UnsafeAccess.HAS_JAVA8_INTRINSICS || !fenced) - ct match { - case MPMC => FromCircularQueue[A](new MpmcArrayQueue[A](capacity), ct) - case MPSC => FromCircularQueue[A](new MpscArrayQueue[A](capacity), ct) - case SPMC => FromCircularQueue[A](new SpmcArrayQueue[A](capacity), ct) - case SPSC => FromCircularQueue[A](new SpscArrayQueue[A](capacity), ct) - } - else { - // Without support for Unsafe.fullFence, falling back to a MPMC queue - FromCircularQueue[A](new MpmcArrayQueue[A](capacity), ct) - } - } else if (UnsafeAccess.HAS_JAVA8_INTRINSICS || !fenced) { - ct match { - case MPMC => FromMessagePassingQueue[A](new MpmcAtomicArrayQueue[A](capacity), ct) - case MPSC => FromMessagePassingQueue[A](new MpscAtomicArrayQueue[A](capacity), ct) - case SPMC => FromMessagePassingQueue[A](new SpmcAtomicArrayQueue[A](capacity), ct) - case SPSC => FromMessagePassingQueue[A](new SpscAtomicArrayQueue[A](capacity), ct) - } - } else { - // Without support for Unsafe.fullFence, falling back to a MPMC queue - FromMessagePassingQueue[A](new MpmcAtomicArrayQueue[A](capacity), ct) + private def bounded[A](capacity: Int, ct: ChannelType, fenced: Boolean): LowLevelConcurrentQueue[A] = { + val _ = fenced + ct match { + case MPMC => FromCircularQueue[A](new MpmcArrayQueue[A](capacity), ct) + case MPSC => FromCircularQueue[A](new MpscArrayQueue[A](capacity), ct) + case SPMC => FromCircularQueue[A](new SpmcArrayQueue[A](capacity), ct) + case SPSC => FromCircularQueue[A](new SpscArrayQueue[A](capacity), ct) } + } /** * Builds an bounded `ConcurrentQueue` reference. */ private def unbounded[A](chunkSize: Option[Int], ct: ChannelType, fenced: Boolean): LowLevelConcurrentQueue[A] = { + val _ = fenced val chunk = chunkSize.getOrElse(Platform.recommendedBufferChunkSize) - if (UnsafeAccess.IS_OPENJDK_COMPATIBLE) { - // Support for memory fences in Unsafe is only available in Java 8+ - if (UnsafeAccess.HAS_JAVA8_INTRINSICS || !fenced) { - ct match { - case MPSC => FromMessagePassingQueue[A](new MpscUnboundedArrayQueue(chunk), ct) - case SPSC => FromMessagePassingQueue[A](new SpscUnboundedArrayQueue(chunk), ct) - case _ => new FromJavaQueue[A](new ConcurrentLinkedQueue[A]()) - } - } else { - // Without support for Unsafe.fullFence, falling back to a MPMC queue - new FromJavaQueue[A](new ConcurrentLinkedQueue[A]()) - } - } else if (UnsafeAccess.HAS_JAVA8_INTRINSICS || !fenced) { - ct match { - case MPSC => FromMessagePassingQueue[A](new MpscUnboundedAtomicArrayQueue(chunk), ct) - case SPSC => FromMessagePassingQueue[A](new SpscUnboundedAtomicArrayQueue(chunk), ct) - case _ => new FromJavaQueue[A](new ConcurrentLinkedQueue[A]()) - } - } else { - // Without support for Unsafe.fullFence, falling back to a MPMC queue - new FromJavaQueue[A](new ConcurrentLinkedQueue[A]()) + ct match { + case MPSC => FromMessagePassingQueue[A](new MpscUnboundedArrayQueue(chunk), ct) + case SPSC => FromMessagePassingQueue[A](new SpscUnboundedArrayQueue(chunk), ct) + case _ => new FromJavaQueue[A](new ConcurrentLinkedQueue[A]()) } } } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/QueueDrain.scala b/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/QueueDrain.scala index fa42a2f73..d179584b9 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/QueueDrain.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/internal/collection/queues/QueueDrain.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ import scala.collection.mutable private[internal] final class QueueDrain[A](buffer: mutable.Buffer[A]) extends Consumer[A] { - private[this] var _count = 0 + private var _count = 0 def count: Int = _count def accept(e: A): Unit = { diff --git a/monix-execution/jvm/src/main/scala/monix/execution/internal/forkJoin/AdaptedForkJoinPool.scala b/monix-execution/jvm/src/main/scala/monix/execution/internal/forkJoin/AdaptedForkJoinPool.scala index 6e899d056..bc325534b 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/internal/forkJoin/AdaptedForkJoinPool.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/internal/forkJoin/AdaptedForkJoinPool.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,32 +19,17 @@ package monix.execution.internal.forkJoin import java.lang.Thread.UncaughtExceptionHandler import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory -import java.util.concurrent.{ForkJoinPool, ForkJoinTask, ForkJoinWorkerThread, TimeUnit} +import java.util.concurrent.{ ForkJoinPool, ForkJoinWorkerThread } private[monix] final class AdaptedForkJoinPool( parallelism: Int, - maxThreads: Int, factory: ForkJoinWorkerThreadFactory, handler: UncaughtExceptionHandler, - asyncMode: Boolean) - extends ForkJoinPool( - parallelism, - factory, - handler, - asyncMode, - 0, - maxThreads, - 1, - (_: ForkJoinPool) => true, - AdaptedForkJoinPool.DefaultKeepAliveMillis, - TimeUnit.MILLISECONDS - ) { + asyncMode: Boolean +) extends ForkJoinPool(parallelism, factory, handler, asyncMode) { override def execute(runnable: Runnable): Unit = { - val fjt: ForkJoinTask[_] = runnable match { - case t: ForkJoinTask[_] => t - case r => new AdaptedForkJoinTask(r) - } + val fjt = new AdaptedForkJoinTask(runnable) Thread.currentThread match { case fjw: ForkJoinWorkerThread if fjw.getPool eq this => fjt.fork() @@ -54,7 +39,3 @@ private[monix] final class AdaptedForkJoinPool( } } } -private[monix] object AdaptedForkJoinPool { - // the same as ForkJoinPool.DEFAULT_KEEPALIVE (which is private) - final val DefaultKeepAliveMillis = 60000L -} diff --git a/monix-execution/jvm/src/main/scala/monix/execution/internal/forkJoin/AdaptedForkJoinTask.scala b/monix-execution/jvm/src/main/scala/monix/execution/internal/forkJoin/AdaptedForkJoinTask.scala index a486e2267..63e082b09 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/internal/forkJoin/AdaptedForkJoinTask.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/internal/forkJoin/AdaptedForkJoinTask.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,13 +20,13 @@ package monix.execution.internal.forkJoin import java.util.concurrent.ForkJoinTask private[monix] final class AdaptedForkJoinTask(runnable: Runnable) extends ForkJoinTask[Unit] { - def setRawResult(u: Unit): Unit = () def getRawResult(): Unit = () def exec(): Boolean = try { - runnable.run(); true + runnable.run() + true } catch { case anything: Throwable => val t = Thread.currentThread diff --git a/monix-execution/jvm/src/main/scala/monix/execution/internal/forkJoin/DynamicWorkerThreadFactory.scala b/monix-execution/jvm/src/main/scala/monix/execution/internal/forkJoin/DynamicWorkerThreadFactory.scala index 8e297e2c6..01abf4ffd 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/internal/forkJoin/DynamicWorkerThreadFactory.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/internal/forkJoin/DynamicWorkerThreadFactory.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,23 +17,42 @@ package monix.execution.internal.forkJoin -import java.util.concurrent.ForkJoinPool.{ForkJoinWorkerThreadFactory, ManagedBlocker} -import java.util.concurrent.{ForkJoinPool, ForkJoinWorkerThread, ThreadFactory} +import java.util.concurrent.ForkJoinPool.{ ForkJoinWorkerThreadFactory, ManagedBlocker } +import java.util.concurrent.{ ForkJoinPool, ForkJoinWorkerThread, ThreadFactory } + +import monix.execution.atomic.AtomicInt import monix.execution.internal.forkJoin.DynamicWorkerThreadFactory.EmptyBlockContext +import scala.annotation.tailrec import scala.annotation.nowarn -import scala.concurrent.{BlockContext, CanAwait} +import scala.concurrent.{ BlockContext, CanAwait } // Implement BlockContext on FJP threads private[monix] final class DynamicWorkerThreadFactory( prefix: String, + maxThreads: Int, uncaught: Thread.UncaughtExceptionHandler, daemonic: Boolean ) extends ThreadFactory with ForkJoinWorkerThreadFactory { require(prefix ne null, "DefaultWorkerThreadFactory.prefix must be non null") + require(maxThreads > 0, "DefaultWorkerThreadFactory.maxThreads must be greater than 0") + + private val currentNumberOfThreads = AtomicInt(0) + + @tailrec private def reserveThread(): Boolean = + currentNumberOfThreads.get() match { + case `maxThreads` | Int.`MaxValue` => false + case other => currentNumberOfThreads.compareAndSet(other, other + 1) || reserveThread() + } - @nowarn("msg=deprecated") + @tailrec private def deregisterThread(): Boolean = + currentNumberOfThreads.get() match { + case 0 => false + case other => currentNumberOfThreads.compareAndSet(other, other - 1) || deregisterThread() + } + + @nowarn("cat=deprecation") def wire[T <: Thread](thread: T): T = { thread.setDaemon(daemonic) thread.setUncaughtExceptionHandler(uncaught) @@ -41,35 +60,52 @@ private[monix] final class DynamicWorkerThreadFactory( thread } + // As per ThreadFactory contract newThread should return `null` if cannot create new thread. def newThread(runnable: Runnable): Thread = - wire(new Thread(runnable)) + if (!reserveThread()) null + else + wire(new Thread(() => { + try { + runnable.run() + } finally { + val _ = deregisterThread() + () + } + })) def newThread(fjp: ForkJoinPool): ForkJoinWorkerThread = - wire(new ForkJoinWorkerThread(fjp) with BlockContext { - final override def blockOn[T](thunk: => T)(implicit permission: CanAwait): T = { - var result: T = null.asInstanceOf[T] - ForkJoinPool.managedBlock(new ManagedBlocker { - @volatile - private[this] var isDone = false - def isReleasable = isDone - - def block(): Boolean = { - result = - try { - // When we block, switch out the BlockContext temporarily so that nested - // blocking does not created N new Threads - BlockContext.withBlockContext(EmptyBlockContext) { thunk } - } finally { - isDone = true - } - true - } - }) - - result - } - }) + if (!reserveThread()) null + else { + wire(new ForkJoinWorkerThread(fjp) with BlockContext { + // We have to decrement the current thread count when the thread exits + final override def onTermination(exception: Throwable): Unit = { + val _ = deregisterThread() + () + } + + final override def blockOn[T](thunk: => T)(implicit permission: CanAwait): T = { + var result: T = null.asInstanceOf[T] + ForkJoinPool.managedBlock(new ManagedBlocker { + @volatile private var isDone = false + def isReleasable = isDone + + def block(): Boolean = { + result = + try { + // When we block, switch out the BlockContext temporarily so that nested + // blocking does not created N new Threads + BlockContext.withBlockContext(EmptyBlockContext) { thunk } + } finally { + isDone = true + } + true + } + }) + result + } + }) + } } private[monix] object DynamicWorkerThreadFactory { diff --git a/monix-execution/jvm/src/main/scala/monix/execution/internal/forkJoin/StandardWorkerThreadFactory.scala b/monix-execution/jvm/src/main/scala/monix/execution/internal/forkJoin/StandardWorkerThreadFactory.scala index 2edcfc0f5..3d8acea2c 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/internal/forkJoin/StandardWorkerThreadFactory.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/internal/forkJoin/StandardWorkerThreadFactory.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,9 @@ package monix.execution.internal.forkJoin import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory -import java.util.concurrent.{ForkJoinPool, ForkJoinWorkerThread, ThreadFactory} +import java.util.concurrent.{ ForkJoinPool, ForkJoinWorkerThread, ThreadFactory } + +import scala.annotation.nowarn import scala.annotation.nowarn @@ -28,7 +30,7 @@ private[monix] final class StandardWorkerThreadFactory( daemonic: Boolean ) extends ThreadFactory with ForkJoinWorkerThreadFactory { - @nowarn("msg=deprecated") + @nowarn("cat=deprecation") def wire[T <: Thread](thread: T): T = { thread.setDaemon(daemonic) thread.setUncaughtExceptionHandler(uncaught) diff --git a/monix-execution/jvm/src/main/scala/monix/execution/misc/ThreadLocal.scala b/monix-execution/jvm/src/main/scala/monix/execution/misc/ThreadLocal.scala index ab69bce17..0e0daab82 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/misc/ThreadLocal.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/misc/ThreadLocal.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,7 +31,7 @@ package monix.execution.misc * any values yet. */ final class ThreadLocal[A] private (val initial: A) { - private[this] val tl = new java.lang.ThreadLocal[A]() { + private val tl = new java.lang.ThreadLocal[A]() { override def initialValue(): A = initial } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/schedulers/AdaptedThreadPoolExecutor.scala b/monix-execution/jvm/src/main/scala/monix/execution/schedulers/AdaptedThreadPoolExecutor.scala index 7bde71c5a..3c61385d6 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/schedulers/AdaptedThreadPoolExecutor.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/schedulers/AdaptedThreadPoolExecutor.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,10 +30,12 @@ private[schedulers] abstract class AdaptedThreadPoolExecutor(corePoolSize: Int, super.afterExecute(r, t) var exception: Throwable = t - if ((exception eq null) && r.isInstanceOf[Future[_]]) { + if ((exception eq null) && classOf[Future[AnyRef]].isInstance(r)) { try { - val future = r.asInstanceOf[Future[_]] - if (future.isDone) future.get() + val future = r.asInstanceOf[Future[AnyRef]] + if (future.isDone) { + val _ = future.get() + } } catch { case ex: ExecutionException => exception = ex.getCause diff --git a/monix-execution/jvm/src/main/scala/monix/execution/schedulers/AsyncScheduler.scala b/monix-execution/jvm/src/main/scala/monix/execution/schedulers/AsyncScheduler.scala index 1872a293e..315937e08 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/schedulers/AsyncScheduler.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/schedulers/AsyncScheduler.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,12 +17,12 @@ package monix.execution.schedulers -import java.util.concurrent.{ScheduledExecutorService, TimeUnit} +import java.util.concurrent.{ ScheduledExecutorService, TimeUnit } -import monix.execution.{Cancelable, Features, Scheduler, UncaughtExceptionReporter, ExecutionModel => ExecModel} +import monix.execution.{ Cancelable, ExecutionModel => ExecModel, Features, Scheduler, UncaughtExceptionReporter } import scala.concurrent.ExecutionContext -import monix.execution.internal.{InterceptRunnable, ScheduledExecutors} +import monix.execution.internal.{ InterceptRunnable, ScheduledExecutors } /** An `AsyncScheduler` schedules tasks to happen in the future with the * given `ScheduledExecutorService` and the tasks themselves are executed on @@ -32,8 +32,8 @@ final class AsyncScheduler private ( scheduler: ScheduledExecutorService, ec: ExecutionContext, val executionModel: ExecModel, - r: UncaughtExceptionReporter) - extends ReferenceScheduler with BatchingScheduler { + r: UncaughtExceptionReporter +) extends ReferenceScheduler with BatchingScheduler { protected def executeAsync(runnable: Runnable): Unit = { if (((r: AnyRef) eq ec) || (r eq null)) ec.execute(runnable) @@ -69,6 +69,7 @@ object AsyncScheduler { schedulerService: ScheduledExecutorService, ec: ExecutionContext, executionModel: ExecModel, - reporter: UncaughtExceptionReporter = null): AsyncScheduler = + reporter: UncaughtExceptionReporter = null + ): AsyncScheduler = new AsyncScheduler(schedulerService, ec, executionModel, reporter) } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/schedulers/CanBlock.scala b/monix-execution/jvm/src/main/scala/monix/execution/schedulers/CanBlock.scala index 7b9ecbfcd..1e4670d03 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/schedulers/CanBlock.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/schedulers/CanBlock.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -73,7 +73,8 @@ import scala.annotation.implicitNotFound */ @implicitNotFound( "For blocking operations on the JVM, there should be an implicit " + - "available by default, or import monix.execution.schedulers.CanBlock.permit.") + "available by default, or import monix.execution.schedulers.CanBlock.permit." +) final class CanBlock private () object CanBlock { diff --git a/monix-execution/jvm/src/main/scala/monix/execution/schedulers/Defaults.scala b/monix-execution/jvm/src/main/scala/monix/execution/schedulers/Defaults.scala index 76c118265..82995d5e0 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/schedulers/Defaults.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/schedulers/Defaults.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.execution.schedulers -import java.util.concurrent.{ScheduledExecutorService, ScheduledThreadPoolExecutor} +import java.util.concurrent.{ ScheduledExecutorService, ScheduledThreadPoolExecutor } import monix.execution.UncaughtExceptionReporter @@ -28,7 +28,8 @@ private[schedulers] object Defaults { lazy val scheduledExecutor: ScheduledExecutorService = { val tp = new ScheduledThreadPoolExecutor( 1, - ThreadFactoryBuilder("monix-scheduler", UncaughtExceptionReporter.default, daemonic = true)) + ThreadFactoryBuilder("monix-scheduler", UncaughtExceptionReporter.default, daemonic = true) + ) tp.setRemoveOnCancelPolicy(true) tp } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/schedulers/ExecutorScheduler.scala b/monix-execution/jvm/src/main/scala/monix/execution/schedulers/ExecutorScheduler.scala index 51ea65143..bceb2410c 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/schedulers/ExecutorScheduler.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/schedulers/ExecutorScheduler.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,14 +17,18 @@ package monix.execution.schedulers -import java.util.concurrent.{ExecutorService, ForkJoinPool, ScheduledExecutorService} -import monix.execution.internal.forkJoin.{AdaptedForkJoinPool, DynamicWorkerThreadFactory, StandardWorkerThreadFactory} -import monix.execution.internal.{InterceptRunnable, Platform, ScheduledExecutors} -import monix.execution.{Cancelable, UncaughtExceptionReporter} -import monix.execution.{Features, Scheduler} +import java.util.concurrent.{ ExecutorService, ScheduledExecutorService } +import monix.execution.internal.forkJoin.{ + AdaptedForkJoinPool, + DynamicWorkerThreadFactory, + StandardWorkerThreadFactory +} +import monix.execution.internal.{ InterceptRunnable, Platform, ScheduledExecutors } +import monix.execution.{ Cancelable, UncaughtExceptionReporter } +import monix.execution.{ Features, Scheduler } // Prevents conflict with the deprecated symbol -import monix.execution.{ExecutionModel => ExecModel} -import scala.concurrent.{ExecutionContext, Future, Promise, blocking} +import monix.execution.{ ExecutionModel => ExecModel } +import scala.concurrent.{ blocking, ExecutionContext, Future, Promise } import scala.concurrent.duration.TimeUnit import scala.util.control.NonFatal @@ -51,16 +55,16 @@ abstract class ExecutorScheduler(e: ExecutorService, r: UncaughtExceptionReporte override final def awaitTermination(timeout: Long, unit: TimeUnit, awaitOn: ExecutionContext): Future[Boolean] = { val p = Promise[Boolean]() - awaitOn.execute(new Runnable { - override def run() = - try blocking { + awaitOn.execute(() => + try blocking { p.success(e.awaitTermination(timeout, unit)) () - } catch { - case ex if NonFatal(ex) => - p.failure(ex); () } - }) + catch { + case ex if NonFatal(ex) => + p.failure(ex); () + } + ) p.future } @@ -95,7 +99,8 @@ object ExecutorScheduler { service: ExecutorService, reporter: UncaughtExceptionReporter, executionModel: ExecModel, - features: Features): ExecutorScheduler = { + features: Features + ): ExecutorScheduler = { // Implementations will inherit BatchingScheduler, so this is guaranteed val ft = features + Scheduler.BATCHING @@ -117,7 +122,8 @@ object ExecutorScheduler { def apply( service: ExecutorService, reporter: UncaughtExceptionReporter, - executionModel: ExecModel): ExecutorScheduler = { + executionModel: ExecModel + ): ExecutorScheduler = { // $COVERAGE-OFF$ apply(service, reporter, executionModel, Features.empty) // $COVERAGE-ON$ @@ -131,12 +137,12 @@ object ExecutorScheduler { parallelism: Int, daemonic: Boolean, reporter: UncaughtExceptionReporter, - executionModel: ExecModel): ExecutorScheduler = { + executionModel: ExecModel + ): ExecutorScheduler = { val handler = reporter.asJava val pool = new AdaptedForkJoinPool( parallelism, - Int.MaxValue, // actually capped to 32k by ForkJoinPool new StandardWorkerThreadFactory(name, handler, daemonic), handler, asyncMode = true @@ -154,13 +160,13 @@ object ExecutorScheduler { maxThreads: Int, daemonic: Boolean, reporter: UncaughtExceptionReporter, - executionModel: ExecModel): ExecutorScheduler = { + executionModel: ExecModel + ): ExecutorScheduler = { val exceptionHandler = reporter.asJava val pool = new AdaptedForkJoinPool( parallelism, - maxThreads, - new DynamicWorkerThreadFactory(name, exceptionHandler, daemonic), + new DynamicWorkerThreadFactory(name, maxThreads, exceptionHandler, daemonic), exceptionHandler, asyncMode = true ) @@ -180,15 +186,16 @@ object ExecutorScheduler { executor: ExecutorService, r: UncaughtExceptionReporter, override val executionModel: ExecModel, - override val features: Features) - extends ExecutorScheduler(executor, r) { + override val features: Features + ) extends ExecutorScheduler(executor, r) { @deprecated("Provided for backwards compatibility", "3.0.0") def this( scheduler: ScheduledExecutorService, executor: ExecutorService, r: UncaughtExceptionReporter, - executionModel: ExecModel) = { + executionModel: ExecModel + ) = { // $COVERAGE-OFF$ this(scheduler, executor, r, executionModel, Features.empty) // $COVERAGE-ON$ @@ -209,8 +216,8 @@ object ExecutorScheduler { s: ScheduledExecutorService, r: UncaughtExceptionReporter, override val executionModel: ExecModel, - override val features: Features) - extends ExecutorScheduler(s, r) { + override val features: Features + ) extends ExecutorScheduler(s, r) { @deprecated("Provided for backwards compatibility", "3.0.0") def this(scheduler: ScheduledExecutorService, r: UncaughtExceptionReporter, executionModel: ExecModel) = { diff --git a/monix-execution/jvm/src/main/scala/monix/execution/schedulers/SchedulerCompanionImpl.scala b/monix-execution/jvm/src/main/scala/monix/execution/schedulers/SchedulerCompanionImpl.scala index 3cff896e5..611ba4d76 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/schedulers/SchedulerCompanionImpl.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/schedulers/SchedulerCompanionImpl.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,9 +19,9 @@ package monix.execution.schedulers import java.util.concurrent._ -import monix.execution.{Features, Scheduler, SchedulerCompanion, UncaughtExceptionReporter} +import monix.execution.{ Features, Scheduler, SchedulerCompanion, UncaughtExceptionReporter } // Prevents conflict with the deprecated symbol -import monix.execution.{ExecutionModel => ExecModel} +import monix.execution.{ ExecutionModel => ExecModel } import scala.concurrent.ExecutionContext import scala.concurrent.duration._ @@ -77,7 +77,8 @@ private[execution] class SchedulerCompanionImpl extends SchedulerCompanion { executor: ScheduledExecutorService, ec: ExecutionContext, reporter: UncaughtExceptionReporter, - executionModel: ExecModel): Scheduler = + executionModel: ExecModel + ): Scheduler = AsyncScheduler(executor, ec, executionModel, reporter) /** [[monix.execution.Scheduler Scheduler]] builder. @@ -124,7 +125,8 @@ private[execution] class SchedulerCompanionImpl extends SchedulerCompanion { def apply( executor: ExecutorService, reporter: UncaughtExceptionReporter, - executionModel: ExecModel): SchedulerService = { + executionModel: ExecModel + ): SchedulerService = { ExecutorScheduler(executor, reporter, executionModel, Features.empty) } @@ -235,7 +237,8 @@ private[execution] class SchedulerCompanionImpl extends SchedulerCompanion { name: String = "monix-computation", daemonic: Boolean = true, reporter: UncaughtExceptionReporter = UncaughtExceptionReporter.default, - executionModel: ExecModel = ExecModel.Default): SchedulerService = { + executionModel: ExecModel = ExecModel.Default + ): SchedulerService = { ExecutorScheduler.forkJoinStatic(name, parallelism, daemonic, reporter, executionModel) } @@ -263,7 +266,8 @@ private[execution] class SchedulerCompanionImpl extends SchedulerCompanion { name: String = "monix-forkjoin", daemonic: Boolean = true, reporter: UncaughtExceptionReporter = UncaughtExceptionReporter.default, - executionModel: ExecModel = ExecModel.Default): SchedulerService = { + executionModel: ExecModel = ExecModel.Default + ): SchedulerService = { ExecutorScheduler.forkJoinDynamic(name, parallelism, maxThreads, daemonic, reporter, executionModel) } @@ -287,7 +291,8 @@ private[execution] class SchedulerCompanionImpl extends SchedulerCompanion { name: String = "monix-io", daemonic: Boolean = true, reporter: UncaughtExceptionReporter = UncaughtExceptionReporter.default, - executionModel: ExecModel = ExecModel.Default): SchedulerService = { + executionModel: ExecModel = ExecModel.Default + ): SchedulerService = { val threadFactory = ThreadFactoryBuilder(name, reporter, daemonic) val executor = new ThreadPoolExecutor( @@ -296,7 +301,8 @@ private[execution] class SchedulerCompanionImpl extends SchedulerCompanion { 60, TimeUnit.SECONDS, new SynchronousQueue[Runnable](false), - threadFactory) + threadFactory + ) ExecutorScheduler(executor, reporter, executionModel, Features.empty) } @@ -324,7 +330,8 @@ private[execution] class SchedulerCompanionImpl extends SchedulerCompanion { keepAliveTime: FiniteDuration = 60.seconds, daemonic: Boolean = true, reporter: UncaughtExceptionReporter = UncaughtExceptionReporter.default, - executionModel: ExecModel = ExecModel.Default): SchedulerService = { + executionModel: ExecModel = ExecModel.Default + ): SchedulerService = { require(minThreads >= 0, "minThreads >= 0") require(maxThreads > 0, "maxThreads > 0") @@ -338,7 +345,8 @@ private[execution] class SchedulerCompanionImpl extends SchedulerCompanion { keepAliveTime.toMillis, TimeUnit.MILLISECONDS, new SynchronousQueue[Runnable](false), - threadFactory) + threadFactory + ) ExecutorScheduler(executor, reporter, executionModel, Features.empty) } @@ -362,7 +370,8 @@ private[execution] class SchedulerCompanionImpl extends SchedulerCompanion { name: String, daemonic: Boolean = true, reporter: UncaughtExceptionReporter = UncaughtExceptionReporter.default, - executionModel: ExecModel = ExecModel.Default): SchedulerService = { + executionModel: ExecModel = ExecModel.Default + ): SchedulerService = { val factory = ThreadFactoryBuilder(name, reporter, daemonic) val executor = new AdaptedThreadPoolExecutor(1, factory) { @@ -391,7 +400,8 @@ private[execution] class SchedulerCompanionImpl extends SchedulerCompanion { poolSize: Int, daemonic: Boolean = true, reporter: UncaughtExceptionReporter = UncaughtExceptionReporter.default, - executionModel: ExecModel = ExecModel.Default): SchedulerService = { + executionModel: ExecModel = ExecModel.Default + ): SchedulerService = { val factory = ThreadFactoryBuilder(name, reporter, daemonic) val executor = new AdaptedThreadPoolExecutor(poolSize, factory) { diff --git a/monix-execution/jvm/src/main/scala/monix/execution/schedulers/ThreadFactoryBuilder.scala b/monix-execution/jvm/src/main/scala/monix/execution/schedulers/ThreadFactoryBuilder.scala index 4a0b2b4f2..d91e994f8 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/schedulers/ThreadFactoryBuilder.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/schedulers/ThreadFactoryBuilder.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,6 @@ package monix.execution.schedulers import monix.execution.UncaughtExceptionReporter -import java.util.concurrent.ThreadFactory import scala.annotation.nowarn private[schedulers] object ThreadFactoryBuilder { @@ -30,17 +29,13 @@ private[schedulers] object ThreadFactoryBuilder { * @param daemonic specifies whether the created threads should be daemonic * (non-daemonic threads are blocking the JVM process on exit). */ - - def apply(name: String, reporter: UncaughtExceptionReporter, daemonic: Boolean): ThreadFactory = { - new ThreadFactory { - @nowarn("msg=deprecated") - def newThread(r: Runnable) = { - val thread = new Thread(r) - thread.setName(name + "-" + thread.getId) - thread.setDaemon(daemonic) - thread.setUncaughtExceptionHandler(reporter.asJava) - thread - } + @nowarn("cat=deprecation") + def apply(name: String, reporter: UncaughtExceptionReporter, daemonic: Boolean): ThreadFactory = + (r: Runnable) => { + val thread = new Thread(r) + thread.setName(name + "-" + thread.getId) + thread.setDaemon(daemonic) + thread.setUncaughtExceptionHandler(reporter.asJava) + thread } - } } diff --git a/monix-execution/jvm/src/main/scala/monix/execution/schedulers/TrampolineExecutionContext.scala b/monix-execution/jvm/src/main/scala/monix/execution/schedulers/TrampolineExecutionContext.scala index cd82fad74..b512e85ee 100644 --- a/monix-execution/jvm/src/main/scala/monix/execution/schedulers/TrampolineExecutionContext.scala +++ b/monix-execution/jvm/src/main/scala/monix/execution/schedulers/TrampolineExecutionContext.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,9 +18,9 @@ package monix.execution.schedulers import monix.execution.internal.Trampoline -import monix.execution.internal.Trampoline.{ForkingTrampolineEC, ImmediateTrampolineEC, TrampolineEC} +import monix.execution.internal.Trampoline.{ ForkingTrampolineEC, ImmediateTrampolineEC, TrampolineEC } -import scala.concurrent.{BlockContext, ExecutionContext, ExecutionContextExecutor} +import scala.concurrent.{ BlockContext, ExecutionContext, ExecutionContextExecutor } import scala.util.control.NonFatal /** A `scala.concurrentExecutionContext` implementation @@ -92,7 +92,7 @@ object TrampolineExecutionContext { private val localContext: ThreadLocal[BlockContext] = { try { val methods = BlockContext.getClass.getDeclaredMethods - .filter(m => m.getParameterCount == 0 && m.getReturnType == classOf[ThreadLocal[_]]) + .filter(m => m.getParameterCount == 0 && m.getReturnType == classOf[ThreadLocal[AnyRef]]) .toList methods match { diff --git a/monix-execution/jvm/src/main/scala_3.0/monix/execution/atomic/Atomic.scala b/monix-execution/jvm/src/main/scala_3.0/monix/execution/atomic/Atomic.scala deleted file mode 100644 index 203f78ca4..000000000 --- a/monix-execution/jvm/src/main/scala_3.0/monix/execution/atomic/Atomic.scala +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (c) 2014-2021 by The Monix Project Developers. - * See the project homepage at: https://monix.io - * - * 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 monix.execution.atomic - -/** - * Base trait of all atomic references, no matter the type. - */ -abstract class Atomic[A] extends Serializable { - /** Get the current value persisted by this Atomic. */ - def get(): A - - /** Get the current value persisted by this Atomic, an alias for `get()`. */ - inline final def apply(): A = get() - - /** Updates the current value. - * - * @param update will be the new value returned by `get()` - */ - def set(update: A): Unit - - /** Alias for [[set]]. Updates the current value. - * - * @param value will be the new value returned by `get()` - */ - inline final def update(value: A): Unit = set(value) - - /** Alias for [[set]]. Updates the current value. - * - * @param value will be the new value returned by `get()` - */ - inline final def `:=`(value: A): Unit = set(value) - - /** Does a compare-and-set operation on the current value. For more info, checkout the related - * [[https://en.wikipedia.org/wiki/Compare-and-swap Compare-and-swap Wikipedia page]]. - * - * It's an atomic, worry free operation. - * - * @param expect is the value you expect to be persisted when the operation happens - * @param update will be the new value, should the check for `expect` succeeds - * @return either true in case the operation succeeded or false otherwise - */ - def compareAndSet(expect: A, update: A): Boolean - - /** Sets the persisted value to `update` and returns the old value that was in place. - * It's an atomic, worry free operation. - */ - def getAndSet(update: A): A - - /** Eventually sets to the given value. - * Has weaker visibility guarantees than the normal `set()`. - */ - def lazySet(update: A): Unit - - /** Abstracts over `compareAndSet`. You specify a transformation by specifying a callback to be - * executed, a callback that transforms the current value. This method will loop until it will - * succeed in replacing the current value with the one produced by your callback. - * - * Note that the callback will be executed on each iteration of the loop, so it can be called - * multiple times - don't do destructive I/O or operations that mutate global state in it. - * - * @param cb is a callback that receives the current value as input and returns a tuple that specifies - * the update + what should this method return when the operation succeeds. - * @return whatever was specified by your callback, once the operation succeeds - */ - inline final def transformAndExtract[U](inline cb: (A) => (U, A)): U = { - var current = get() - var result = null.asInstanceOf[U] - var continue = true - - while (continue) { - val (resultTmp, update) = cb(current) - if (compareAndSet(current, update)) { - result = resultTmp - continue = false - } else { - current = get() - } - } - result - } - - /** Abstracts over `compareAndSet`. You specify a transformation by specifying a callback to be - * executed, a callback that transforms the current value. This method will loop until it will - * succeed in replacing the current value with the one produced by the given callback. - * - * Note that the callback will be executed on each iteration of the loop, so it can be called - * multiple times - don't do destructive I/O or operations that mutate global state in it. - * - * @param cb is a callback that receives the current value as input and returns the `update` which is the - * new value that should be persisted - * @return whatever the update is, after the operation succeeds - */ - inline final def transformAndGet(inline cb: (A) => A): A = { - var current = get() - var update = null.asInstanceOf[A] - var continue = true - - while (continue) { - update = cb(current) - if (compareAndSet(current, update)) - continue = false - else - current = get() - } - update - } - - /** Abstracts over `compareAndSet`. You specify a transformation by specifying a callback to be - * executed, a callback that transforms the current value. This method will loop until it will - * succeed in replacing the current value with the one produced by the given callback. - * - * Note that the callback will be executed on each iteration of the loop, so it can be called - * multiple times - don't do destructive I/O or operations that mutate global state in it. - * - * @param cb is a callback that receives the current value as input and returns the `update` which is the - * new value that should be persisted - * @return the old value, just prior to when the successful update happened - */ - inline final def getAndTransform(inline cb: (A) => A): A = { - var current = get() - var continue = true - - while (continue) { - val update = cb(current) - if (compareAndSet(current, update)) - continue = false - else - current = get() - } - current - } - - /** Abstracts over `compareAndSet`. You specify a transformation by specifying a callback to be - * executed, a callback that transforms the current value. This method will loop until it will - * succeed in replacing the current value with the one produced by the given callback. - * - * Note that the callback will be executed on each iteration of the loop, so it can be called - * multiple times - don't do destructive I/O or operations that mutate global state in it. - * - * @param cb is a callback that receives the current value as input and returns the `update` which is the - * new value that should be persisted - */ - inline final def transform(inline cb: (A) => A): Unit = { - var continue = true - - while (continue) { - val current = get() - val update = cb(current) - continue = !compareAndSet(current, update) - } - } -} - -object Atomic { - /** Constructs an `Atomic[A]` reference. - * - * Based on the `initialValue`, it will return the best, most - * specific type. E.g. you give it a number, it will return - * something inheriting from `AtomicNumber[A]`. That's why it takes - * an `AtomicBuilder[T, R]` as an implicit parameter - but worry - * not about such details as it just works. - * - * @param initialValue is the initial value with which to - * initialize the Atomic reference - * - * @param builder is the builder that helps us to build the - * best reference possible, based on our `initialValue` - */ - inline def apply[A, R <: Atomic[A]](initialValue: A)(implicit builder: AtomicBuilder[A, R]): R = - builder.buildInstance(initialValue, PaddingStrategy.NoPadding, allowPlatformIntrinsics = true) - - /** Constructs an `Atomic[A]` reference, applying the provided - * [[PaddingStrategy]] in order to counter the "false sharing" - * problem. - * - * Based on the `initialValue`, it will return the best, most - * specific type. E.g. you give it a number, it will return - * something inheriting from `AtomicNumber[A]`. That's why it takes - * an `AtomicBuilder[A, R]` as an implicit parameter - but worry - * not about such details as it just works. - * - * Note that for ''Scala.js'' we aren't applying any padding, as it - * doesn't make much sense, since Javascript execution is single - * threaded, but this builder is provided for syntax compatibility - * anyway across the JVM and Javascript and we never know how - * Javascript engines will evolve. - * - * @param initialValue is the initial value with which to - * initialize the Atomic reference - * - * @param padding is the [[PaddingStrategy]] to apply - * - * @param builder is the builder that helps us to build the - * best reference possible, based on our `initialValue` - */ - inline def withPadding[A, R <: Atomic[A]](initialValue: A, padding: PaddingStrategy)( - implicit builder: AtomicBuilder[A, R]): R = - builder.buildInstance(initialValue, padding, allowPlatformIntrinsics = true) - - /** Returns the builder that would be chosen to construct Atomic - * references for the given `initialValue`. - */ - def builderFor[A, R <: Atomic[A]](initialValue: A)(implicit builder: AtomicBuilder[A, R]): AtomicBuilder[A, R] = - builder -} diff --git a/monix-execution/jvm/src/test/scala/monix/execution/AckJVMSuite.scala b/monix-execution/jvm/src/test/scala/monix/execution/AckJVMSuite.scala index e8e3dc71d..c7ad060ab 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/AckJVMSuite.scala +++ b/monix-execution/jvm/src/test/scala/monix/execution/AckJVMSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.execution import minitest.SimpleTestSuite -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import scala.concurrent.Await import scala.concurrent.duration.Duration diff --git a/monix-execution/jvm/src/test/scala/monix/execution/AsyncQueueJVMSuite.scala b/monix-execution/jvm/src/test/scala/monix/execution/AsyncQueueJVMSuite.scala index e285c0aae..26a3f0148 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/AsyncQueueJVMSuite.scala +++ b/monix-execution/jvm/src/test/scala/monix/execution/AsyncQueueJVMSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/jvm/src/test/scala/monix/execution/CallbackSafetyJVMSuite.scala b/monix-execution/jvm/src/test/scala/monix/execution/CallbackSafetyJVMSuite.scala index 0f74acd32..1ed510ece 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/CallbackSafetyJVMSuite.scala +++ b/monix-execution/jvm/src/test/scala/monix/execution/CallbackSafetyJVMSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,16 +17,16 @@ package monix.execution -import java.util.concurrent.{CountDownLatch, TimeUnit} +import java.util.concurrent.{ CountDownLatch, TimeUnit } import minitest.TestSuite -import minitest.api.{AssertionException, MiniTestException} -import monix.execution.exceptions.{CallbackCalledMultipleTimesException, DummyException} +import minitest.api.{ AssertionException, MiniTestException } +import monix.execution.exceptions.{ CallbackCalledMultipleTimesException, DummyException } import monix.execution.schedulers.SchedulerService import scala.concurrent.Promise import scala.concurrent.duration._ -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } object CallbackSafetyJVMSuite extends TestSuite[SchedulerService] with TestUtils { val WORKERS = 10 @@ -38,39 +38,39 @@ object CallbackSafetyJVMSuite extends TestSuite[SchedulerService] with TestUtils override def tearDown(env: SchedulerService): Unit = { env.shutdown() - env.awaitTermination(10.seconds) + val _ = env.awaitTermination(10.seconds) () } test("Callback.safe is thread-safe onSuccess") { implicit sc => - executeOnSuccessTest(Callback[Throwable].safe) + executeOnSuccessTest(Callback.safe) } test("Callback.safe is thread-safe onError") { implicit sc => - executeOnErrorTest(Callback[Throwable].safe) + executeOnErrorTest(Callback.safe) } test("Callback.trampolined is thread-safe onSuccess") { implicit sc => - executeOnSuccessTest(Callback[Throwable].trampolined) + executeOnSuccessTest(Callback.trampolined) } test("Callback.trampolined is thread-safe onError") { implicit sc => - executeOnErrorTest(Callback[Throwable].trampolined) + executeOnErrorTest(Callback.trampolined) } test("Callback.forked is thread-safe onSuccess") { implicit sc => - executeOnSuccessTest(Callback[Throwable].forked, isForked = true) + executeOnSuccessTest(Callback.forked, isForked = true) } test("Callback.forked is thread-safe onError") { implicit sc => - executeOnErrorTest(Callback[Throwable].forked, isForked = true) + executeOnErrorTest(Callback.forked, isForked = true) } test("Callback.fromPromise is thread-safe onSuccess") { implicit sc => val wrap = { (cb: Callback[Throwable, Int]) => val p = Promise[Int]() p.future.onComplete(cb.apply) - Callback[Throwable].fromPromise(p) + Callback.fromPromise(p) } executeOnSuccessTest(wrap, isForked = true) } @@ -79,18 +79,18 @@ object CallbackSafetyJVMSuite extends TestSuite[SchedulerService] with TestUtils val wrap = { (cb: Callback[Throwable, String]) => val p = Promise[String]() p.future.onComplete(cb.apply) - Callback[Throwable].fromPromise(p) + Callback.fromPromise(p) } executeOnErrorTest(wrap, isForked = true) } test("Normal callback is not thread-safe via onSuccess") { implicit sc => - intercept[AssertionException] { executeOnSuccessTest(x => x) } + val _ = intercept[AssertionException] { executeOnSuccessTest(x => x) } () } test("Normal callback is not thread-safe via onError") { implicit sc => - intercept[AssertionException] { executeOnErrorTest(x => x) } + val _ = intercept[AssertionException] { executeOnErrorTest(x => x) } () } @@ -101,7 +101,7 @@ object CallbackSafetyJVMSuite extends TestSuite[SchedulerService] with TestUtils val f = (r: Either[Throwable, Int]) => cb(r) Callback.fromAttempt(f) } - intercept[AssertionException] { executeOnSuccessTest(wrap, retries = RETRIES * 100) } + val _ = intercept[AssertionException] { executeOnSuccessTest(wrap, retries = RETRIES * 100) } () } @@ -112,7 +112,7 @@ object CallbackSafetyJVMSuite extends TestSuite[SchedulerService] with TestUtils val f = (r: Either[Throwable, String]) => cb(r) Callback.fromAttempt(f) } - intercept[AssertionException] { executeOnErrorTest(wrap, retries = RETRIES * 100) } + val _ = intercept[AssertionException] { executeOnErrorTest(wrap, retries = RETRIES * 100) } () } @@ -121,9 +121,9 @@ object CallbackSafetyJVMSuite extends TestSuite[SchedulerService] with TestUtils val wrap = { (cb: Callback[Throwable, Int]) => val f = (r: Try[Int]) => cb(r) - Callback[Throwable].fromTry(f) + Callback.fromTry(f) } - intercept[AssertionException] { executeOnSuccessTest(wrap, retries = RETRIES * 100) } + val _ = intercept[AssertionException] { executeOnSuccessTest(wrap, retries = RETRIES * 100) } () } @@ -132,49 +132,49 @@ object CallbackSafetyJVMSuite extends TestSuite[SchedulerService] with TestUtils val wrap = { (cb: Callback[Throwable, String]) => val f = (r: Try[String]) => cb(r) - Callback[Throwable].fromTry(f) + Callback.fromTry(f) } - intercept[AssertionException] { executeOnErrorTest(wrap, retries = RETRIES * 100) } + val _ = intercept[AssertionException] { executeOnErrorTest(wrap, retries = RETRIES * 100) } () } - test("Callback.fromAttempt is quasi-safe via onSuccess") { implicit sc => + test("Callback.fromAttempt is quasi-safe via onSuccess") { _ => executeQuasiSafeOnSuccessTest { cb => val f = (r: Either[Throwable, Int]) => cb(r) Callback.fromAttempt(f) } } - test("Callback.fromAttempt is quasi-safe via onError") { implicit sc => + test("Callback.fromAttempt is quasi-safe via onError") { _ => executeQuasiSafeOnFailureTest { cb => val f = (r: Either[Throwable, Int]) => cb(r) Callback.fromAttempt(f) } } - test("Callback.fromTry is quasi-safe via onSuccess") { implicit sc => + test("Callback.fromTry is quasi-safe via onSuccess") { _ => executeQuasiSafeOnSuccessTest { cb => val f = (r: Try[Int]) => cb(r) Callback.fromTry(f) } } - test("Callback.fromTry is quasi-safe via onError") { implicit sc => + test("Callback.fromTry is quasi-safe via onError") { _ => executeQuasiSafeOnFailureTest { cb => val f = (r: Try[Int]) => cb(r) Callback.fromTry(f) } } - test("Normal callback is not quasi-safe via onSuccess") { implicit sc => - intercept[MiniTestException] { + test("Normal callback is not quasi-safe via onSuccess") { _ => + val _ = intercept[MiniTestException] { executeQuasiSafeOnSuccessTest(x => x) } () } - test("Normal callback is not quasi-safe via onError") { implicit sc => - intercept[MiniTestException] { + test("Normal callback is not quasi-safe via onError") { _ => + val _ = intercept[MiniTestException] { executeQuasiSafeOnFailureTest(x => x) } () @@ -194,7 +194,7 @@ object CallbackSafetyJVMSuite extends TestSuite[SchedulerService] with TestUtils assert(tryTrigger(cb), "cb.tryOnSuccess(1)") assert(!tryTrigger(cb), "!cb.tryOnSuccess(1)") - intercept[CallbackCalledMultipleTimesException] { trigger(cb) } + val _ = intercept[CallbackCalledMultipleTimesException] { trigger(cb) } assertEquals(effect, 1) } @@ -216,7 +216,7 @@ object CallbackSafetyJVMSuite extends TestSuite[SchedulerService] with TestUtils assert(tryTrigger(cb), "cb.tryOnError(1)") assert(!tryTrigger(cb), "!cb.tryOnError(1)") - intercept[CallbackCalledMultipleTimesException] { trigger(cb) } + val _ = intercept[CallbackCalledMultipleTimesException] { trigger(cb) } assertEquals(effect, 1) } @@ -228,7 +228,8 @@ object CallbackSafetyJVMSuite extends TestSuite[SchedulerService] with TestUtils def executeOnSuccessTest( wrap: Callback[Throwable, Int] => Callback[Throwable, Int], isForked: Boolean = false, - retries: Int = RETRIES)(implicit sc: Scheduler): Unit = { + retries: Int = RETRIES + )(implicit sc: Scheduler): Unit = { def run(trigger: Callback[Throwable, Int] => Any): Unit = { for (_ <- 0 until retries) { @@ -258,19 +259,23 @@ object CallbackSafetyJVMSuite extends TestSuite[SchedulerService] with TestUtils run(cb => try cb.onSuccess(1) - catch { case _: CallbackCalledMultipleTimesException => () }) + catch { case _: CallbackCalledMultipleTimesException => () } + ) run(cb => try cb(Right(1)) - catch { case _: CallbackCalledMultipleTimesException => () }) + catch { case _: CallbackCalledMultipleTimesException => () } + ) run(cb => try cb(Success(1)) - catch { case _: CallbackCalledMultipleTimesException => () }) + catch { case _: CallbackCalledMultipleTimesException => () } + ) } def executeOnErrorTest( wrap: Callback[Throwable, String] => Callback[Throwable, String], isForked: Boolean = false, - retries: Int = RETRIES)(implicit sc: Scheduler): Unit = { + retries: Int = RETRIES + )(implicit sc: Scheduler): Unit = { def run(trigger: Callback[Throwable, String] => Any): Unit = { for (_ <- 0 until retries) { @@ -297,13 +302,16 @@ object CallbackSafetyJVMSuite extends TestSuite[SchedulerService] with TestUtils run(cb => try cb.onError(DUMMY) - catch { case _: CallbackCalledMultipleTimesException => () }) + catch { case _: CallbackCalledMultipleTimesException => () } + ) run(cb => try cb.tryApply(Left(DUMMY)) - catch { case _: CallbackCalledMultipleTimesException => () }) + catch { case _: CallbackCalledMultipleTimesException => () } + ) run(cb => try cb.tryApply(Failure(DUMMY)) - catch { case _: CallbackCalledMultipleTimesException => () }) + catch { case _: CallbackCalledMultipleTimesException => () } + ) } def runConcurrently(sc: Scheduler)(f: => Any): Unit = { @@ -313,7 +321,7 @@ object CallbackSafetyJVMSuite extends TestSuite[SchedulerService] with TestUtils for (_ <- 0 until WORKERS) { sc.execute { () => latchWorkersStart.countDown() - try { f; () } + try { val _ = f; () } finally latchWorkersFinished.countDown() } } diff --git a/monix-execution/jvm/src/test/scala/monix/execution/CancelableFutureJVMSuite.scala b/monix-execution/jvm/src/test/scala/monix/execution/CancelableFutureJVMSuite.scala index 687f6b533..b9f9bc9a9 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/CancelableFutureJVMSuite.scala +++ b/monix-execution/jvm/src/test/scala/monix/execution/CancelableFutureJVMSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import minitest.SimpleTestSuite import monix.execution.Scheduler.Implicits.global import scala.concurrent.duration._ -import scala.concurrent.{Await, Future, TimeoutException} +import scala.concurrent.{ Await, Future, TimeoutException } import scala.util.Success object CancelableFutureJVMSuite extends SimpleTestSuite { @@ -51,8 +51,8 @@ object CancelableFutureJVMSuite extends SimpleTestSuite { test("never") { val f = CancelableFuture.never[Int] - intercept[TimeoutException] { Await.result(f, 1.milli); () } - intercept[TimeoutException] { Await.ready(f, 1.milli); () } + val _ = intercept[TimeoutException] { val _ = Await.result(f, 1.milli); () } + val _ = intercept[TimeoutException] { Await.ready(f, 1.milli); () } () } } diff --git a/monix-execution/jvm/src/test/scala/monix/execution/CompletableFutureConversionsSuite.scala b/monix-execution/jvm/src/test/scala/monix/execution/CompletableFutureConversionsSuite.scala index 3fdfbf6fa..dc7c8c1cd 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/CompletableFutureConversionsSuite.scala +++ b/monix-execution/jvm/src/test/scala/monix/execution/CompletableFutureConversionsSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,14 +17,14 @@ package monix.execution -import java.util.concurrent.{CompletableFuture, CompletionException} +import java.util.concurrent.{ CompletableFuture, CompletionException } import minitest.TestSuite import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler -import scala.concurrent.{Future, Promise} -import scala.util.{Failure, Success} +import scala.concurrent.{ Future, Promise } +import scala.util.{ Failure, Success } object CompletableFutureConversionsSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() @@ -53,7 +53,7 @@ object CompletableFutureConversionsSuite extends TestSuite[TestScheduler] { test("FutureUtils.toJavaCompletable works") { implicit s => val f = Future.successful(42) val cf = FutureUtils.toJavaCompletable(f) - s.tickOne() + val _ = s.tickOne() assertEquals(cf.getNow(-1), 42) } @@ -61,7 +61,7 @@ object CompletableFutureConversionsSuite extends TestSuite[TestScheduler] { val dummy = DummyException("dummy") val ef = Future.failed[Int](dummy) val ecf = FutureUtils.toJavaCompletable(ef) - s.tickOne() + val _ = s.tickOne() try { ecf.getNow(-1) fail("Should throw an error") diff --git a/monix-execution/jvm/src/test/scala/monix/execution/FeaturesJVMSuite.scala b/monix-execution/jvm/src/test/scala/monix/execution/FeaturesJVMSuite.scala index dec28e227..5542559a3 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/FeaturesJVMSuite.scala +++ b/monix-execution/jvm/src/test/scala/monix/execution/FeaturesJVMSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/jvm/src/test/scala/monix/execution/FutureUtilsJVMSuite.scala b/monix-execution/jvm/src/test/scala/monix/execution/FutureUtilsJVMSuite.scala index 49835893f..077d13e08 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/FutureUtilsJVMSuite.scala +++ b/monix-execution/jvm/src/test/scala/monix/execution/FutureUtilsJVMSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -55,16 +55,18 @@ object FutureUtilsJVMSuite extends TestSuite[TestScheduler] { .delayedResult(originalTimeout) { 15 } - .timeoutTo(timeout, { - sideEffect.incrementAndGet() - Future.failed(TestException()) - })(Scheduler.Implicits.global) + .timeoutTo( + timeout, { + sideEffect.incrementAndGet() + Future.failed(TestException()) + } + )(Scheduler.Implicits.global) _ <- FutureUtils.delayedResult(100.millis)(()) // wait for all concurrent processes } yield ()).map { _ => success.incrementAndGet() () }.recover { - case _: TestException => + case _ => error.incrementAndGet() () } diff --git a/monix-execution/jvm/src/test/scala/monix/execution/cancelables/ChainedCancelableJVMSuite.scala b/monix-execution/jvm/src/test/scala/monix/execution/cancelables/ChainedCancelableJVMSuite.scala index e97913e9e..fc1ebae6f 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/cancelables/ChainedCancelableJVMSuite.scala +++ b/monix-execution/jvm/src/test/scala/monix/execution/cancelables/ChainedCancelableJVMSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/jvm/src/test/scala/monix/execution/internal/PlatformSuite.scala b/monix-execution/jvm/src/test/scala/monix/execution/internal/PlatformSuite.scala index 617f3cf20..5f5a8ca73 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/internal/PlatformSuite.scala +++ b/monix-execution/jvm/src/test/scala/monix/execution/internal/PlatformSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/jvm/src/test/scala/monix/execution/misc/LocalJVMSuite.scala b/monix-execution/jvm/src/test/scala/monix/execution/misc/LocalJVMSuite.scala index eb1267a72..2c79bdd85 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/misc/LocalJVMSuite.scala +++ b/monix-execution/jvm/src/test/scala/monix/execution/misc/LocalJVMSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.execution.misc import minitest.SimpleTestSuite -import monix.execution.{Cancelable, CancelableFuture, Scheduler} +import monix.execution.{ Cancelable, CancelableFuture, Scheduler } import monix.execution.exceptions.DummyException import monix.execution.schedulers.TracingScheduler import scala.concurrent.Future @@ -50,9 +50,12 @@ object LocalJVMSuite extends SimpleTestSuite { val f = for { _ <- CancelableFuture(Future { local := 50 }, Cancelable()) _ <- Local.isolate { - CancelableFuture(Future { - local := 100 - }, Cancelable()) + CancelableFuture( + Future { + local := 100 + }, + Cancelable() + ) } v <- CancelableFuture(Future { local() }, Cancelable()) } yield v @@ -85,9 +88,12 @@ object LocalJVMSuite extends SimpleTestSuite { val f = for { _ <- Future { local := 50 } - _ <- Local.bindCurrentIf(true)(CancelableFuture(Future { - local := 100 - }, Cancelable.empty)) + _ <- Local.bindCurrentIf(true)(CancelableFuture( + Future { + local := 100 + }, + Cancelable.empty + )) v <- Future { local() } } yield v diff --git a/monix-execution/jvm/src/test/scala/monix/execution/schedulers/AsyncSchedulerJVMSuite.scala b/monix-execution/jvm/src/test/scala/monix/execution/schedulers/AsyncSchedulerJVMSuite.scala index 89915fb69..4c3162820 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/schedulers/AsyncSchedulerJVMSuite.scala +++ b/monix-execution/jvm/src/test/scala/monix/execution/schedulers/AsyncSchedulerJVMSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,14 +17,14 @@ package monix.execution.schedulers -import java.util.concurrent.{CountDownLatch, TimeUnit, TimeoutException} +import java.util.concurrent.{ CountDownLatch, TimeUnit, TimeoutException } import minitest.SimpleTestSuite import monix.execution.ExecutionModel.AlwaysAsyncExecution import monix.execution.cancelables.SingleAssignCancelable -import monix.execution.{Cancelable, Scheduler} -import monix.execution.{ExecutionModel => ExecModel} +import monix.execution.{ Cancelable, Scheduler } +import monix.execution.{ ExecutionModel => ExecModel } import scala.concurrent.duration._ -import scala.concurrent.{Await, Future, Promise} +import scala.concurrent.{ Await, Future, Promise } object AsyncSchedulerJVMSuite extends SimpleTestSuite { val s: Scheduler = monix.execution.Scheduler.global @@ -36,7 +36,7 @@ object AsyncSchedulerJVMSuite extends SimpleTestSuite { test("scheduleOnce with delay") { val p = Promise[Long]() val startedAt = System.nanoTime() - scheduleOnce(s, 100.millis) { p.success(System.nanoTime()); () } + val _ = scheduleOnce(s, 100.millis) { p.success(System.nanoTime()); () } val timeTaken = Await.result(p.future, 3.second) assert((timeTaken - startedAt).nanos.toMillis >= 100) @@ -44,7 +44,7 @@ object AsyncSchedulerJVMSuite extends SimpleTestSuite { test("scheduleOnce with delay lower than 1.milli") { val p = Promise[Int]() - scheduleOnce(s, 20.nanos) { p.success(1); () } + val _ = scheduleOnce(s, 20.nanos) { p.success(1); () } assert(Await.result(p.future, 3.seconds) == 1) } @@ -53,8 +53,8 @@ object AsyncSchedulerJVMSuite extends SimpleTestSuite { val task = scheduleOnce(s, 100.millis) { p.success(1); () } task.cancel() - intercept[TimeoutException] { - Await.result(p.future, 150.millis) + val _ = intercept[TimeoutException] { + val _ = Await.result(p.future, 150.millis) () } () @@ -78,7 +78,8 @@ object AsyncSchedulerJVMSuite extends SimpleTestSuite { } else if (value < 4) { value += 1 } - }) + } + ) assert(Await.result(p.future, 5.second) == 4) } @@ -101,7 +102,8 @@ object AsyncSchedulerJVMSuite extends SimpleTestSuite { } else if (value < 4) { value += 1 } - }) + } + ) assert(Await.result(p.future, 5.second) == 4) } @@ -114,9 +116,7 @@ object AsyncSchedulerJVMSuite extends SimpleTestSuite { assertEquals(s.executionModel, AlwaysAsyncExecution) val latch = new CountDownLatch(1) - s.execute(new Runnable { - def run(): Unit = latch.countDown() - }) + s.execute(() => latch.countDown()) assert(latch.await(15, TimeUnit.MINUTES), "latch.await") } @@ -145,23 +145,23 @@ object AsyncSchedulerJVMSuite extends SimpleTestSuite { test("Scheduler.cached") { import scala.concurrent.duration._ - intercept[IllegalArgumentException] { - monix.execution.Scheduler.cached("dummy", -1, 2, 1.second) + val _ = intercept[IllegalArgumentException] { + val _ = monix.execution.Scheduler.cached("dummy", -1, 2, 1.second) () } - intercept[IllegalArgumentException] { - monix.execution.Scheduler.cached("dummy", 0, 0, 1.second) + val _ = intercept[IllegalArgumentException] { + val _ = monix.execution.Scheduler.cached("dummy", 0, 0, 1.second) () } - intercept[IllegalArgumentException] { - monix.execution.Scheduler.cached("dummy", 2, 1, 1.second) + val _ = intercept[IllegalArgumentException] { + val _ = monix.execution.Scheduler.cached("dummy", 2, 1, 1.second) () } - intercept[IllegalArgumentException] { - monix.execution.Scheduler.cached("dummy", 2, 10, -1.second) + val _ = intercept[IllegalArgumentException] { + val _ = monix.execution.Scheduler.cached("dummy", 2, 10, -1.second) () } @@ -197,5 +197,5 @@ object AsyncSchedulerJVMSuite extends SimpleTestSuite { } def runnableAction(f: => Unit): Runnable = - new Runnable { def run() = f } + () => f } diff --git a/monix-execution/jvm/src/test/scala/monix/execution/schedulers/ExecutorSchedulerSuite.scala b/monix-execution/jvm/src/test/scala/monix/execution/schedulers/ExecutorSchedulerSuite.scala index 56280681a..708eb4705 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/schedulers/ExecutorSchedulerSuite.scala +++ b/monix-execution/jvm/src/test/scala/monix/execution/schedulers/ExecutorSchedulerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,16 +17,16 @@ package monix.execution.schedulers -import java.util.concurrent.{CountDownLatch, TimeUnit, TimeoutException} +import java.util.concurrent.{ CountDownLatch, TimeUnit, TimeoutException } import minitest.TestSuite -import monix.execution.ExecutionModel.{AlwaysAsyncExecution, Default => DefaultExecutionModel} +import monix.execution.ExecutionModel.{ AlwaysAsyncExecution, Default => DefaultExecutionModel } import monix.execution.cancelables.SingleAssignCancelable import monix.execution.exceptions.DummyException -import monix.execution.{Cancelable, Scheduler, UncaughtExceptionReporter} +import monix.execution.{ Cancelable, Scheduler, UncaughtExceptionReporter } import scala.concurrent.duration._ -import scala.concurrent.{blocking, Await, Promise} +import scala.concurrent.{ blocking, Await, Promise } abstract class ExecutorSchedulerSuite extends TestSuite[SchedulerService] { self => var lastReportedFailure = null: Throwable @@ -57,7 +57,7 @@ abstract class ExecutorSchedulerSuite extends TestSuite[SchedulerService] { self test("scheduleOnce with delay") { scheduler => val p = Promise[Long]() val startedAt = System.nanoTime() - scheduleOnce(scheduler, 100.millis) { + val _ = scheduleOnce(scheduler, 100.millis) { p.success(System.nanoTime()) () } @@ -67,7 +67,7 @@ abstract class ExecutorSchedulerSuite extends TestSuite[SchedulerService] { self test("scheduleOnce with delay lower than 1.milli") { scheduler => val p = Promise[Int]() - scheduleOnce(scheduler, 20.nanos) { p.success(1); () } + val _ = scheduleOnce(scheduler, 20.nanos) { p.success(1); () } assert(Await.result(p.future, 3.seconds) == 1) } @@ -76,8 +76,8 @@ abstract class ExecutorSchedulerSuite extends TestSuite[SchedulerService] { self val task = scheduleOnce(scheduler, 100.millis) { p.success(1); () } task.cancel() - intercept[TimeoutException] { - Await.result(p.future, 150.millis) + val _ = intercept[TimeoutException] { + val _ = Await.result(p.future, 150.millis) () } () @@ -101,7 +101,8 @@ abstract class ExecutorSchedulerSuite extends TestSuite[SchedulerService] { self } else if (value < 4) { value += 1 } - }) + } + ) assert(Await.result(p.future, 5.second) == 4) } @@ -124,7 +125,8 @@ abstract class ExecutorSchedulerSuite extends TestSuite[SchedulerService] { self } else if (value < 4) { value += 1 } - }) + } + ) assert(Await.result(p.future, 5.second) == 4) } @@ -159,11 +161,7 @@ abstract class ExecutorSchedulerSuite extends TestSuite[SchedulerService] { self try { val ex = DummyException("dummy") - - scheduler.execute(new Runnable { - override def run() = - throw ex - }) + scheduler.execute(() => throw ex) assert(latch.await(15, TimeUnit.MINUTES), "lastReportedFailureLatch.await") self.synchronized(assertEquals(lastReportedFailure, ex)) @@ -185,13 +183,11 @@ abstract class ExecutorSchedulerSuite extends TestSuite[SchedulerService] { self try { val ex = DummyException("dummy") - scheduler.scheduleOnce( + val _ = scheduler.scheduleOnce( 1, TimeUnit.MILLISECONDS, - new Runnable { - override def run() = - throw ex - }) + () => throw ex + ) assert(latch.await(15, TimeUnit.MINUTES), "lastReportedFailureLatch.await") self.synchronized(assertEquals(lastReportedFailure, ex)) @@ -204,7 +200,7 @@ abstract class ExecutorSchedulerSuite extends TestSuite[SchedulerService] { self } def runnableAction(f: => Unit): Runnable = - new Runnable { def run() = f } + () => f } object ComputationSchedulerSuite extends ExecutorSchedulerSuite { diff --git a/monix-execution/jvm/src/test/scala/monix/execution/schedulers/JVMUncaughtExceptionReporterSuite.scala b/monix-execution/jvm/src/test/scala/monix/execution/schedulers/JVMUncaughtExceptionReporterSuite.scala index e586a0484..e89ea87fb 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/schedulers/JVMUncaughtExceptionReporterSuite.scala +++ b/monix-execution/jvm/src/test/scala/monix/execution/schedulers/JVMUncaughtExceptionReporterSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.execution.schedulers -import monix.execution.{Scheduler, UncaughtExceptionReporter} +import monix.execution.{ Scheduler, UncaughtExceptionReporter } import java.util.concurrent.Executors import monix.execution.exceptions.DummyException diff --git a/monix-execution/jvm/src/test/scala/monix/execution/schedulers/ScheduleOnceJVMSuite.scala b/monix-execution/jvm/src/test/scala/monix/execution/schedulers/ScheduleOnceJVMSuite.scala index b2db158cd..2cba14d67 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/schedulers/ScheduleOnceJVMSuite.scala +++ b/monix-execution/jvm/src/test/scala/monix/execution/schedulers/ScheduleOnceJVMSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ package schedulers import java.util.concurrent.ScheduledThreadPoolExecutor import minitest.SimpleTestSuite import scala.concurrent.duration._ -import scala.concurrent.{Await, ExecutionContext, Future, Promise} +import scala.concurrent.{ Await, ExecutionContext, Future, Promise } object ScheduleOnceJVMSuite extends SimpleTestSuite { test("Scheduler.global") { @@ -89,12 +89,14 @@ object ScheduleOnceJVMSuite extends SimpleTestSuite { def runTest(sc: Scheduler, threadPrefix: Option[String] = None): Unit = { def runAndGetThread(sc: Scheduler, delayMs: Int): Future[String] = { val p = Promise[String]() - sc.scheduleOnce(delayMs.toLong, MILLISECONDS, new Runnable { - def run(): Unit = { + val _ = sc.scheduleOnce( + delayMs.toLong, + MILLISECONDS, + () => { p.success(Thread.currentThread().getName) () } - }) + ) p.future } diff --git a/monix-execution/jvm/src/test/scala/monix/execution/schedulers/ScheduledExecutorToSchedulerSuite.scala b/monix-execution/jvm/src/test/scala/monix/execution/schedulers/ScheduledExecutorToSchedulerSuite.scala index c8e549f41..b83c6a8a0 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/schedulers/ScheduledExecutorToSchedulerSuite.scala +++ b/monix-execution/jvm/src/test/scala/monix/execution/schedulers/ScheduledExecutorToSchedulerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,10 +23,10 @@ import minitest.TestSuite import monix.execution.ExecutionModel.AlwaysAsyncExecution import monix.execution.atomic.Atomic import monix.execution.cancelables.SingleAssignCancelable -import monix.execution.{Features, UncaughtExceptionReporter, ExecutionModel => ExecModel} +import monix.execution.{ ExecutionModel => ExecModel, Features, UncaughtExceptionReporter } import scala.concurrent.duration._ -import scala.concurrent.{Await, Promise} +import scala.concurrent.{ Await, Promise } object ScheduledExecutorToSchedulerSuite extends TestSuite[ExecutorScheduler] { val lastError = Atomic(null: Throwable) @@ -39,7 +39,8 @@ object ScheduledExecutorToSchedulerSuite extends TestSuite[ExecutorScheduler] { "ExecutorSchedulerSuite", reporter, daemonic = true - )) + ) + ) ExecutorScheduler(executor, reporter, ExecModel.Default, Features.empty) } @@ -55,7 +56,7 @@ object ScheduledExecutorToSchedulerSuite extends TestSuite[ExecutorScheduler] { test("scheduleOnce with delay") { implicit s => val p = Promise[Long]() val startedAt = System.nanoTime() - s.scheduleOnce(100.millis) { p.success(System.nanoTime()); () } + val _ = s.scheduleOnce(100.millis) { p.success(System.nanoTime()); () } val timeTaken = Await.result(p.future, 30.second) assert((timeTaken - startedAt).nanos.toMillis >= 100) @@ -63,7 +64,7 @@ object ScheduledExecutorToSchedulerSuite extends TestSuite[ExecutorScheduler] { test("scheduleOnce with negative delay") { implicit s => val p = Promise[Boolean]() - s.scheduleOnce(-100.millis) { p.success(true); () } + val _ = s.scheduleOnce(-100.millis) { p.success(true); () } val result = Await.result(p.future, 30.second) assert(result) @@ -77,7 +78,7 @@ object ScheduledExecutorToSchedulerSuite extends TestSuite[ExecutorScheduler] { test("scheduleOnce with delay lower than 1.milli") { implicit s => val p = Promise[Int]() - s.scheduleOnce(20.nanos) { p.success(1); () } + val _ = s.scheduleOnce(20.nanos) { p.success(1); () } assert(Await.result(p.future, 3.seconds) == 1) } @@ -86,8 +87,8 @@ object ScheduledExecutorToSchedulerSuite extends TestSuite[ExecutorScheduler] { val task = s.scheduleOnce(100.millis) { p.success(1); () } task.cancel() - intercept[TimeoutException] { - Await.result(p.future, 150.millis) + val _ = intercept[TimeoutException] { + val _ = Await.result(p.future, 150.millis) () } () diff --git a/monix-execution/jvm/src/test/scala/monix/execution/schedulers/TestSchedulerCompanionSuite.scala b/monix-execution/jvm/src/test/scala/monix/execution/schedulers/TestSchedulerCompanionSuite.scala index 76bd336d4..750b0ecb4 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/schedulers/TestSchedulerCompanionSuite.scala +++ b/monix-execution/jvm/src/test/scala/monix/execution/schedulers/TestSchedulerCompanionSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,9 @@ package monix.execution.schedulers -import java.util.concurrent.{CountDownLatch, Executors, TimeUnit} +import java.util.concurrent.{ CountDownLatch, Executors, TimeUnit } import minitest.SimpleTestSuite -import monix.execution.{Scheduler, UncaughtExceptionReporter} +import monix.execution.{ Scheduler, UncaughtExceptionReporter } object TestSchedulerCompanionSuite extends SimpleTestSuite { test("scheduler builder, apply, test 1") { @@ -29,9 +29,9 @@ object TestSchedulerCompanionSuite extends SimpleTestSuite { try { val latch = new CountDownLatch(2) val s = Scheduler(service, ec) - val r = new Runnable { def run() = latch.countDown() } + val r: Runnable = () => latch.countDown() s.execute(r) - s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) + val _ = s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) assert(latch.await(15, TimeUnit.MINUTES), "latch.await failed") } finally { service.shutdown() @@ -45,9 +45,9 @@ object TestSchedulerCompanionSuite extends SimpleTestSuite { try { val latch = new CountDownLatch(2) val s = Scheduler(service, ec) - val r = new Runnable { def run() = latch.countDown() } + val r: Runnable = () => latch.countDown() s.execute(r) - s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) + val _ = s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) assert(latch.await(15, TimeUnit.MINUTES), "latch.await failed") } finally { service.shutdown() @@ -58,9 +58,9 @@ object TestSchedulerCompanionSuite extends SimpleTestSuite { val ec = scala.concurrent.ExecutionContext.Implicits.global val latch = new CountDownLatch(2) val s = Scheduler(ec, UncaughtExceptionReporter(ec.reportFailure)) - val r = new Runnable { def run() = latch.countDown() } + val r: Runnable = () => latch.countDown() s.execute(r) - s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) + val _ = s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) assert(latch.await(15, TimeUnit.MINUTES), "latch.await failed") } @@ -68,9 +68,9 @@ object TestSchedulerCompanionSuite extends SimpleTestSuite { val ec = scala.concurrent.ExecutionContext.Implicits.global val latch = new CountDownLatch(2) val s = Scheduler(ec) - val r = new Runnable { def run() = latch.countDown() } + val r: Runnable = () => latch.countDown() s.execute(r) - s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) + val _ = s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) assert(latch.await(15, TimeUnit.MINUTES), "latch.await failed") } @@ -80,9 +80,9 @@ object TestSchedulerCompanionSuite extends SimpleTestSuite { try { val latch = new CountDownLatch(2) - val r = new Runnable { def run() = latch.countDown() } + val r: Runnable = () => latch.countDown() s.execute(r) - s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) + val _ = s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) assert(latch.await(15, TimeUnit.MINUTES), "latch.await failed") } finally { s.shutdown() @@ -95,9 +95,9 @@ object TestSchedulerCompanionSuite extends SimpleTestSuite { try { val latch = new CountDownLatch(2) - val r = new Runnable { def run() = latch.countDown() } + val r: Runnable = () => latch.countDown() s.execute(r) - s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) + val _ = s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) assert(latch.await(15, TimeUnit.MINUTES), "latch.await failed") } finally { s.shutdown() @@ -108,9 +108,9 @@ object TestSchedulerCompanionSuite extends SimpleTestSuite { val s: SchedulerService = Scheduler.computation(parallelism = 1) try { val latch = new CountDownLatch(2) - val r = new Runnable { def run() = latch.countDown() } + val r: Runnable = () => latch.countDown() s.execute(r) - s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) + val _ = s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) assert(latch.await(15, TimeUnit.MINUTES), "latch.await failed") } finally { s.shutdown() @@ -121,9 +121,9 @@ object TestSchedulerCompanionSuite extends SimpleTestSuite { val s: SchedulerService = Scheduler.io(name = "monix-tests-io") try { val latch = new CountDownLatch(2) - val r = new Runnable { def run() = latch.countDown() } + val r: Runnable = () => latch.countDown() s.execute(r) - s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) + val _ = s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) assert(latch.await(15, TimeUnit.MINUTES), "latch.await failed") } finally { s.shutdown() @@ -134,9 +134,9 @@ object TestSchedulerCompanionSuite extends SimpleTestSuite { val s: SchedulerService = Scheduler.singleThread(name = "monix-tests-single-thread") try { val latch = new CountDownLatch(2) - val r = new Runnable { def run() = latch.countDown() } + val r: Runnable = () => latch.countDown() s.execute(r) - s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) + val _ = s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) assert(latch.await(15, TimeUnit.MINUTES), "latch.await failed") } finally { s.shutdown() @@ -147,9 +147,9 @@ object TestSchedulerCompanionSuite extends SimpleTestSuite { val s: SchedulerService = Scheduler.fixedPool(name = "monix-tests-fixed-pool", poolSize = 1) try { val latch = new CountDownLatch(2) - val r = new Runnable { def run() = latch.countDown() } + val r: Runnable = () => latch.countDown() s.execute(r) - s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) + val _ = s.scheduleOnce(10, TimeUnit.MILLISECONDS, r) assert(latch.await(15, TimeUnit.MINUTES), "latch.await failed") } finally { s.shutdown() diff --git a/monix-execution/jvm/src/test/scala/monix/execution/schedulers/TracingSchedulerServiceSuite.scala b/monix-execution/jvm/src/test/scala/monix/execution/schedulers/TracingSchedulerServiceSuite.scala index b58234a0b..c3ded3e03 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/schedulers/TracingSchedulerServiceSuite.scala +++ b/monix-execution/jvm/src/test/scala/monix/execution/schedulers/TracingSchedulerServiceSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/jvm/src/test/scala/monix/execution/schedulers/TrampolineExecutionContextSuite.scala b/monix-execution/jvm/src/test/scala/monix/execution/schedulers/TrampolineExecutionContextSuite.scala index 88f7709b1..d49dc7f8c 100644 --- a/monix-execution/jvm/src/test/scala/monix/execution/schedulers/TrampolineExecutionContextSuite.scala +++ b/monix-execution/jvm/src/test/scala/monix/execution/schedulers/TrampolineExecutionContextSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,29 +33,21 @@ object TrampolineExecutionContextSuite extends SimpleTestSuite { val ctx = TrampolineExecutionContext.immediate var effect = 0 - ctx.execute(new Runnable { - def run(): Unit = { - effect += 1 + ctx.execute(() => { + effect += 1 - ctx.execute(new Runnable { - def run(): Unit = { - effect += 1 - } - }) - } + ctx.execute(() => { + effect += 1 + }) }) assertEquals(effect, 2) - intercept[NullPointerException] { - ctx.execute(new Runnable { - def run(): Unit = { - ctx.execute(new Runnable { - def run(): Unit = effect += 1 - }) + val _ = intercept[NullPointerException] { + ctx.execute(() => { + ctx.execute(() => effect += 1) - throw null - } + throw null }) } diff --git a/monix-execution/shared/src/main/scala_2.13+/monix/execution/compat.scala b/monix-execution/shared/src/main/scala-2.13/monix/execution/compat.scala similarity index 81% rename from monix-execution/shared/src/main/scala_2.13+/monix/execution/compat.scala rename to monix-execution/shared/src/main/scala-2.13/monix/execution/compat.scala index 24f29b408..5907d5be5 100644 --- a/monix-execution/shared/src/main/scala_2.13+/monix/execution/compat.scala +++ b/monix-execution/shared/src/main/scala-2.13/monix/execution/compat.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,10 @@ package monix.execution -import scala.collection.{BuildFrom => ScalaBuildFrom} +import scala.collection.{ BuildFrom => ScalaBuildFrom } import scala.collection.mutable object compat { - type BuildFrom[-From, -A, +C] = ScalaBuildFrom[From, A, C] private[monix] object internal { @@ -29,7 +28,8 @@ object compat { def toIterator[X](i: IterableOnce[X]): Iterator[X] = i.iterator def hasDefiniteSize[X](i: IterableOnce[X]): Boolean = i.knownSize >= 0 - def newBuilder[From, A, C](bf: BuildFrom[From, A, C], from: From): mutable.Builder[A, C] = bf.newBuilder(from) + def newBuilder[From, A, C](bf: BuildFrom[From, A, C], from: From): mutable.Builder[A, C] = + bf.newBuilder(from) def toSeq[A](array: Array[AnyRef]): Seq[A] = new scala.collection.immutable.ArraySeq.ofRef(array).asInstanceOf[Seq[A]] @@ -40,4 +40,11 @@ object compat { type Flags <: Long with monix.execution.Features.FlagsTag } + + def uninitialized[@specialized T]: T = + new Uninitialized[T].value + + private final class Uninitialized[@specialized T] { + var value: T = _ + } } diff --git a/monix-execution/shared/src/main/scala_3.0-/monix/execution/misc/Local.scala b/monix-execution/shared/src/main/scala-2/monix/execution/misc/Local.scala similarity index 80% rename from monix-execution/shared/src/main/scala_3.0-/monix/execution/misc/Local.scala rename to monix-execution/shared/src/main/scala-2/monix/execution/misc/Local.scala index b5a866307..0fe1c34c0 100644 --- a/monix-execution/shared/src/main/scala_3.0-/monix/execution/misc/Local.scala +++ b/monix-execution/shared/src/main/scala-2/monix/execution/misc/Local.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,9 +18,7 @@ package monix.execution.misc import monix.execution.atomic.AtomicAny - import scala.annotation.tailrec -import scala.reflect.macros.whitebox /** @define canBindLocalsDesc The implementation uses the [[CanBindLocals]] * type class because in case of asynchronous data types that @@ -61,7 +59,7 @@ object Local extends LocalCompanionDeprecated { def newContext(): Context = new Unbound(AtomicAny(Map())) /** Current [[Context]] kept in a `ThreadLocal`. */ - private[this] val localContext: ThreadLocal[Context] = + private val localContext: ThreadLocal[Context] = ThreadLocal(newContext()) /** Return the state of the current Local state. */ @@ -124,7 +122,7 @@ object Local extends LocalCompanionDeprecated { localContext.get().set(key, null, isPresent = false) } - private def restoreKey(key: Key, value: Option[_]): Unit = + private def restoreKey(key: Key, value: Option[?]): Unit = value match { case None => clearKey(key) case Some(v) => saveKey(key, v) @@ -133,32 +131,10 @@ object Local extends LocalCompanionDeprecated { /** If `b` evaluates to `true`, execute a block of code using a current * state of `Local.Context` and restore the current state when complete. */ - private[monix] def bindCurrentIf[R](b: Boolean)(f: => R): R = - macro Macros.localLetCurrentIf - - /** Macros implementations for [[bind]] and [[bindClear]]. */ - private class Macros(override val c: whitebox.Context) extends InlineMacros with HygieneUtilMacros { - import c.universe._ - - def localLet(ctx: Tree)(f: Tree): Tree = - c.abort(c.macroApplication.pos, "Macro no longer implemented!") - def localLetClear(f: Tree): Tree = - c.abort(c.macroApplication.pos, "Macro no longer implemented!") - def isolate(f: Tree): Tree = - c.abort(c.macroApplication.pos, "Macro no longer implemented!") - - def localLetCurrentIf(b: Tree)(f: Tree): Tree = { - val Local = symbolOf[Local[_]].companion - val CanBindLocals = symbolOf[CanBindLocals[_]].companion - - resetTree( - q"""if (!$b) { $f } else { - import $CanBindLocals.Implicits.synchronousAsDefault - $Local.isolate($f) - }""" - ) - } - } + private[monix] def bindCurrentIf[R](b: Boolean)(f: => R)(implicit + cb: CanBindLocals[R] = CanBindLocals.synchronous[R] + ): R = + if (!b) f else Local.isolate(f) /** Represents the current state of all [[Local locals]] for a given * execution context. @@ -217,34 +193,33 @@ object Local extends LocalCompanionDeprecated { // $COVERAGE-ON$ } - private[this] final def isolateLoop(): Unbound = - this match { - case unbound: Unbound => - val map = unbound.ref.get() - new Unbound(AtomicAny(map)) - case _ => - var it = this - var done = false - var map = Map.empty[Key, Any] - val bannedKeys = collection.mutable.Set.empty[Key] - while (!done) { - it match { - case unbound: Unbound => - done = true - unbound.ref.get().foreach { - case (k, v) if !bannedKeys(k) && !map.contains(k) => map = map.updated(k, v) - case _ => () - } - case bound: Bound => - if (!map.contains(bound.key) && !bannedKeys(bound.key)) { - if (bound.hasValue) map = map.updated(bound.key, bound.value) - else bannedKeys += bound.key - } - it = bound.rest - } + private def isolateLoop(): Unbound = this match { + case unbound: Unbound => + val map = unbound.ref.get() + new Unbound(AtomicAny(map)) + case _ => + var it = this + var done = false + var map = Map.empty[Key, Any] + val bannedKeys = collection.mutable.Set.empty[Key] + while (!done) { + it match { + case unbound: Unbound => + done = true + unbound.ref.get().foreach { + case (k, v) if !bannedKeys(k) && !map.contains(k) => map = map.updated(k, v) + case _ => () + } + case bound: Bound => + if (!map.contains(bound.key) && !bannedKeys(bound.key)) { + if (bound.hasValue) map = map.updated(bound.key, bound.value) + else bannedKeys += bound.key + } + it = bound.rest } - new Unbound(AtomicAny(map)) - } + } + new Unbound(AtomicAny(map)) + } } private[execution] final class Unbound(val ref: AtomicAny[Map[Key, Any]]) extends Context @@ -257,7 +232,6 @@ object Local extends LocalCompanionDeprecated { ) extends Context } - /** A `Local` is a [[ThreadLocal]] whose scope is flexible. The state * of all Locals may be saved or restored onto the current thread by * the user. This is useful for threading Locals through execution @@ -332,4 +306,4 @@ final class Local[A](default: () => A) extends LocalDeprecated[A] { */ def clear(): Unit = Local.clearKey(key) -} \ No newline at end of file +} diff --git a/monix-execution/shared/src/main/scala_3.0/monix/execution/compat.scala b/monix-execution/shared/src/main/scala-3/monix/execution/compat.scala similarity index 76% rename from monix-execution/shared/src/main/scala_3.0/monix/execution/compat.scala rename to monix-execution/shared/src/main/scala-3/monix/execution/compat.scala index 31a494ddf..acab01fc9 100644 --- a/monix-execution/shared/src/main/scala_3.0/monix/execution/compat.scala +++ b/monix-execution/shared/src/main/scala-3/monix/execution/compat.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.execution -import scala.collection.{BuildFrom => ScalaBuildFrom} +import scala.collection.{ BuildFrom => ScalaBuildFrom } import scala.collection.mutable object compat { @@ -42,30 +42,38 @@ object compat { opaque type Flag = Long extension (x: Flag) { - def & (y: Flag): Flag = x & y + def &(y: Flag): Flag = x & y } opaque type Flags = Long extension (x: Flags) { @targetName("and") - def & (y: Flags): Flags = x & y + def &(y: Flags): Flags = x & y @targetName("and2") - def & (y: Flag): Flags = x & y + def &(y: Flag): Flags = x & y @targetName("or") - def | (y: Flags): Flags = x | y + def |(y: Flags): Flags = x | y @targetName("or2") - def | (y: Flag): Flags = x | y + def |(y: Flag): Flags = x | y def unary_~ : Flags = ~x } extension (x: Long) { @targetName("or3") - def | (y: Flag): Long = x | y + def |(y: Flag): Long = x | y } } + + def uninitialized[@specialized T]: T = { + new Uninitialized[T].value + } + + private final class Uninitialized[@specialized T] { + var value: T = scala.compiletime.uninitialized + } } diff --git a/monix-execution/shared/src/main/scala_3.0/monix/execution/misc/Local.scala b/monix-execution/shared/src/main/scala-3/monix/execution/misc/Local.scala similarity index 87% rename from monix-execution/shared/src/main/scala_3.0/monix/execution/misc/Local.scala rename to monix-execution/shared/src/main/scala-3/monix/execution/misc/Local.scala index 0d786269f..6a47e2354 100644 --- a/monix-execution/shared/src/main/scala_3.0/monix/execution/misc/Local.scala +++ b/monix-execution/shared/src/main/scala-3/monix/execution/misc/Local.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -60,7 +60,7 @@ object Local extends LocalCompanionDeprecated { def newContext(): Context = new Unbound(AtomicAny(Map())) /** Current [[Context]] kept in a `ThreadLocal`. */ - private[this] val localContext: ThreadLocal[Context] = + private val localContext: ThreadLocal[Context] = ThreadLocal(newContext()) /** Return the state of the current Local state. */ @@ -123,7 +123,7 @@ object Local extends LocalCompanionDeprecated { localContext.get().set(key, null, isPresent = false) } - private def restoreKey(key: Key, value: Option[_]): Unit = + private def restoreKey(key: Key, value: Option[?]): Unit = value match { case None => clearKey(key) case Some(v) => saveKey(key, v) @@ -132,8 +132,10 @@ object Local extends LocalCompanionDeprecated { /** If `b` evaluates to `true`, execute a block of code using a current * state of `Local.Context` and restore the current state when complete. */ - private[monix] inline def bindCurrentIf[R](b: Boolean)(inline f: => R)(implicit cb: CanBindLocals[R] = CanBindLocals.synchronous[R]): R = - if (!b) f else Local.isolate(f) + private[monix] inline def bindCurrentIf[R](b: Boolean)(inline f: => R)(implicit + cb: CanBindLocals[R] = CanBindLocals.synchronous[R] + ): R = + if (!b) f else Local.isolate(f) /** Represents the current state of all [[Local locals]] for a given * execution context. @@ -192,34 +194,33 @@ object Local extends LocalCompanionDeprecated { // $COVERAGE-ON$ } - private[this] final def isolateLoop(): Unbound = - this match { - case unbound: Unbound => - val map = unbound.ref.get() - new Unbound(AtomicAny(map)) - case _ => - var it = this - var done = false - var map = Map.empty[Key, Any] - val bannedKeys = collection.mutable.Set.empty[Key] - while (!done) { - it match { - case unbound: Unbound => - done = true - unbound.ref.get().foreach { - case (k, v) if !bannedKeys(k) && !map.contains(k) => map = map.updated(k, v) - case _ => () - } - case bound: Bound => - if (!map.contains(bound.key) && !bannedKeys(bound.key)) { - if (bound.hasValue) map = map.updated(bound.key, bound.value) - else bannedKeys += bound.key - } - it = bound.rest - } + private def isolateLoop(): Unbound = this match { + case unbound: Unbound => + val map = unbound.ref.get() + new Unbound(AtomicAny(map)) + case _ => + var it = this + var done = false + var map = Map.empty[Key, Any] + val bannedKeys = collection.mutable.Set.empty[Key] + while (!done) { + it match { + case unbound: Unbound => + done = true + unbound.ref.get().foreach { + case (k, v) if !bannedKeys(k) && !map.contains(k) => map = map.updated(k, v) + case _ => () + } + case bound: Bound => + if (!map.contains(bound.key) && !bannedKeys(bound.key)) { + if (bound.hasValue) map = map.updated(bound.key, bound.value) + else bannedKeys += bound.key + } + it = bound.rest } - new Unbound(AtomicAny(map)) - } + } + new Unbound(AtomicAny(map)) + } } private[execution] final class Unbound(val ref: AtomicAny[Map[Key, Any]]) extends Context @@ -232,7 +233,6 @@ object Local extends LocalCompanionDeprecated { ) extends Context } - /** A `Local` is a [[ThreadLocal]] whose scope is flexible. The state * of all Locals may be saved or restored onto the current thread by * the user. This is useful for threading Locals through execution @@ -307,4 +307,4 @@ final class Local[A](default: () => A) extends LocalDeprecated[A] { */ def clear(): Unit = Local.clearKey(key) -} \ No newline at end of file +} diff --git a/monix-execution/shared/src/main/scala/monix/execution/Ack.scala b/monix-execution/shared/src/main/scala/monix/execution/Ack.scala index d4a401d4d..4cccb87dc 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/Ack.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/Ack.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,8 +20,8 @@ package monix.execution import scala.util.control.NonFatal import monix.execution.schedulers.TrampolineExecutionContext.immediate import scala.concurrent.duration.Duration -import scala.concurrent.{CanAwait, ExecutionContext, Future, Promise} -import scala.util.{Failure, Success, Try} +import scala.concurrent.{ CanAwait, ExecutionContext, Future, Promise } +import scala.util.{ Failure, Success, Try } /** Represents an acknowledgement of processing that a consumer * sends back upstream. Useful to implement back-pressure. @@ -35,7 +35,9 @@ sealed abstract class Ack extends Future[Ack] with Serializable { onComplete(r => p.complete( try f(r) - catch { case t if NonFatal(t) => Failure(t) })) + catch { case t if NonFatal(t) => Failure(t) } + ) + ) p.future } @@ -45,13 +47,16 @@ sealed abstract class Ack extends Future[Ack] with Serializable { onComplete(r => p.completeWith( try f(r) - catch { case t if NonFatal(t) => Future.failed(t) })) + catch { case t if NonFatal(t) => Future.failed(t) } + ) + ) p.future } final def onComplete[U](func: Try[Ack] => U)(implicit executor: ExecutionContext): Unit = - executor.execute(new Runnable { - def run(): Unit = { func(AsSuccess); () } + executor.execute(() => { + val _ = func(AsSuccess) + () }) } @@ -145,10 +150,11 @@ object Ack { else if (source ne Continue) source.onComplete { ack => try ack match { - case Success(Stop) => cb(None) - case Failure(e) => cb(Some(e)) - case _ => () - } catch { + case Success(Stop) => cb(None) + case Failure(e) => cb(Some(e)) + case _ => () + } + catch { case e if NonFatal(e) => r.reportFailure(e) } }(immediate) @@ -212,12 +218,10 @@ object Ack { * promise with a value. */ def syncOnContinueFollow[A](p: Promise[A], value: A): Self = { - if (source eq Continue) - p.trySuccess(value) + if (source eq Continue) { val _ = p.trySuccess(value); () } else if (source ne Stop) source.onComplete { r => - if (r.isSuccess && (r.get eq Continue)) - p.trySuccess(value) + if (r.isSuccess && (r.get eq Continue)) { val _ = p.trySuccess(value); () } }(immediate) source } @@ -226,12 +230,10 @@ object Ack { * promise with a value. */ def syncOnStopFollow[A](p: Promise[A], value: A): Self = { - if (source eq Stop) - p.trySuccess(value) + if (source eq Stop) { val _ = p.trySuccess(value); () } else if (source ne Continue) source.onComplete { r => - if (r.isSuccess && (r.get eq Stop)) - p.trySuccess(value) + if (r.isSuccess && (r.get eq Stop)) { val _ = p.trySuccess(value); () } }(immediate) source } diff --git a/monix-execution/shared/src/main/scala/monix/execution/AsyncQueue.scala b/monix-execution/shared/src/main/scala/monix/execution/AsyncQueue.scala index 845b2a47a..8a3ffba0f 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/AsyncQueue.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/AsyncQueue.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.execution import monix.execution.ChannelType.MPMC -import monix.execution.annotations.{UnsafeBecauseImpure, UnsafeProtocol} +import monix.execution.annotations.{ UnsafeBecauseImpure, UnsafeProtocol } import monix.execution.atomic.AtomicAny import monix.execution.atomic.PaddingStrategy.LeftRight128 import monix.execution.cancelables.MultiAssignCancelable @@ -28,7 +28,6 @@ import monix.execution.internal.collection.LowLevelConcurrentQueue import scala.annotation.tailrec import scala.collection.mutable.ArrayBuffer import scala.concurrent.Promise -import scala.concurrent.duration._ /** * A high-performance, back-pressured, asynchronous queue implementation. @@ -112,8 +111,7 @@ import scala.concurrent.duration._ final class AsyncQueue[A] private[monix] ( capacity: BufferCapacity, channelType: ChannelType, - retryDelay: FiniteDuration = 10.millis)(implicit scheduler: Scheduler) { - +)(implicit scheduler: Scheduler) { /** Try pushing a value to the queue. * * The protocol is unsafe because usage of the "try*" methods imply an @@ -240,7 +238,8 @@ final class AsyncQueue[A] private[monix] ( _ => buffer.length >= minLength, _ => toSeq(buffer), promise, - conn) + conn + ) CancelableFuture(promise.future, conn) } @@ -271,17 +270,15 @@ final class AsyncQueue[A] private[monix] ( def isEmpty: Boolean = queue.isEmpty - private[this] val queue: LowLevelConcurrentQueue[A] = + private val queue: LowLevelConcurrentQueue[A] = LowLevelConcurrentQueue(capacity, channelType, fenced = true) - private[this] val consumersAwaiting = - AtomicAny.withPadding[CancelablePromise[Unit]](null, LeftRight128) + private val consumersAwaiting = AtomicAny.withPadding[CancelablePromise[Unit]](null, LeftRight128) - private[this] val producersAwaiting = - if (capacity.isBounded) - AtomicAny.withPadding[CancelablePromise[Unit]](null, LeftRight128) - else - null + private val producersAwaiting = if (capacity.isBounded) + AtomicAny.withPadding[CancelablePromise[Unit]](null, LeftRight128) + else + null private def tryOfferUnsafe(a: A): Boolean = { if (queue.offer(a) == 0) { @@ -349,11 +346,11 @@ final class AsyncQueue[A] private[monix] ( private def toSeq(buffer: ArrayBuffer[A]): Seq[A] = buffer.toArray[Any].toSeq.asInstanceOf[Seq[A]] - private[this] val pollQueue: () => A = () => tryPollUnsafe() - private[this] val pollTest: A => Boolean = _ != null - private[this] val pollMap: A => A = a => a - private[this] val offerTest: Boolean => Boolean = x => x - private[this] val offerMap: Boolean => Unit = _ => () + private val pollQueue: () => A = () => tryPollUnsafe() + private val pollTest: A => Boolean = _ != null + private val pollMap: A => A = a => a + private val offerTest: Boolean => Boolean = x => x + private val offerMap: Boolean => Unit = _ => () @tailrec private def sleepThenRepeat[T, U]( @@ -362,7 +359,8 @@ final class AsyncQueue[A] private[monix] ( filter: T => Boolean, map: T => U, cb: Promise[U], - token: MultiAssignCancelable): Unit = { + token: MultiAssignCancelable + ): Unit = { // Registering intention to sleep via promise state.get() match { @@ -384,7 +382,8 @@ final class AsyncQueue[A] private[monix] ( filter: T => Boolean, map: T => U, cb: Promise[U], - token: MultiAssignCancelable)(p: CancelablePromise[Unit]): Unit = { + token: MultiAssignCancelable + )(p: CancelablePromise[Unit]): Unit = { // Async boundary, for fairness reasons; also creates a full // memory barrier between the promise registration and what follows @@ -410,7 +409,8 @@ final class AsyncQueue[A] private[monix] ( filter: T => Boolean, map: T => U, cb: Promise[U], - token: MultiAssignCancelable): Unit = { + token: MultiAssignCancelable + ): Unit = { // Trying to read val value = f() @@ -479,7 +479,8 @@ object AsyncQueue { @UnsafeProtocol @UnsafeBecauseImpure def withConfig[A](capacity: BufferCapacity, channelType: ChannelType)(implicit - scheduler: Scheduler): AsyncQueue[A] = { + scheduler: Scheduler + ): AsyncQueue[A] = { new AsyncQueue[A](capacity, channelType) } diff --git a/monix-execution/shared/src/main/scala/monix/execution/AsyncSemaphore.scala b/monix-execution/shared/src/main/scala/monix/execution/AsyncSemaphore.scala index 62224477e..416467a6f 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/AsyncSemaphore.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/AsyncSemaphore.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,14 +17,14 @@ package monix.execution -import monix.execution.annotations.{UnsafeBecauseImpure, UnsafeProtocol} +import monix.execution.annotations.{ UnsafeBecauseImpure, UnsafeProtocol } import monix.execution.atomic.PaddingStrategy import monix.execution.atomic.PaddingStrategy.NoPadding import monix.execution.internal.GenericSemaphore.Listener import monix.execution.internal.GenericSemaphore import monix.execution.schedulers.TrampolineExecutionContext.immediate -import scala.concurrent.{ExecutionContext, Future, Promise} +import scala.concurrent.{ ExecutionContext, Future, Promise } import scala.util.control.NonFatal /** The `AsyncSemaphore` is an asynchronous semaphore implementation that diff --git a/monix-execution/shared/src/main/scala/monix/execution/AsyncVar.scala b/monix-execution/shared/src/main/scala/monix/execution/AsyncVar.scala index 23fb369a8..4ae2ff1be 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/AsyncVar.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/AsyncVar.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.execution -import monix.execution.annotations.{UnsafeBecauseImpure, UnsafeProtocol} +import monix.execution.annotations.{ UnsafeBecauseImpure, UnsafeProtocol } import monix.execution.atomic.PaddingStrategy import monix.execution.atomic.PaddingStrategy.NoPadding import monix.execution.internal.GenericVar diff --git a/monix-execution/shared/src/main/scala/monix/execution/BufferCapacity.scala b/monix-execution/shared/src/main/scala/monix/execution/BufferCapacity.scala index 8100d817b..931b606a5 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/BufferCapacity.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/BufferCapacity.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/Callback.scala b/monix-execution/shared/src/main/scala/monix/execution/Callback.scala index 9c82bb7cd..79b9145a0 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/Callback.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/Callback.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,12 @@ package monix.execution -import monix.execution.exceptions.{CallbackCalledMultipleTimesException, UncaughtErrorException} -import monix.execution.schedulers.{TrampolineExecutionContext, TrampolinedRunnable} -import scala.concurrent.{ExecutionContext, Promise} +import monix.execution.exceptions.{ CallbackCalledMultipleTimesException, UncaughtErrorException } +import monix.execution.schedulers.{ TrampolineExecutionContext, TrampolinedRunnable } +import monix.execution.compat.uninitialized +import scala.concurrent.{ ExecutionContext, Promise } import scala.util.control.NonFatal -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } /** Represents a callback that should be called asynchronously * with the result of a computation. @@ -189,7 +190,7 @@ object Callback { * * For example these are Equivalent: * - * `Callback[Throwable, Throwable].empty[String] <-> Callback.empty[Throwable, String]` + * `Callback[Throwable].empty[String] <-> Callback.empty[Throwable, String]` */ def apply[E]: Builders[E] = new Builders[E] @@ -281,7 +282,7 @@ object Callback { case ref: Callback[E, A] @unchecked => ref case _ => new Callback[E, A] { - private[this] var isActive = true + private var isActive = true override def onSuccess(value: A): Unit = apply(Right(value)) override def onError(e: E): Unit = apply(Left(e)) @@ -310,7 +311,7 @@ object Callback { */ def fromTry[A](cb: Try[A] => Unit): Callback[Throwable, A] = new Callback[Throwable, A] { - private[this] var isActive = true + private var isActive = true override def onSuccess(value: A): Unit = apply(Success(value)) override def onError(e: Throwable): Unit = apply(Failure(e)) @@ -386,9 +387,9 @@ object Callback { /** Base implementation for `trampolined` and `forked`. */ private class Base[E, A](cb: Callback[E, A])(implicit ec: ExecutionContext) extends Callback[E, A] with Runnable { - private[this] val state = monix.execution.atomic.AtomicInt(0) - private[this] var value: A = _ - private[this] var error: E = _ + private val state = monix.execution.atomic.AtomicInt(0) + private var value: A = uninitialized[A] + private var error: E = uninitialized[E] override final def onSuccess(value: A): Unit = if (!tryOnSuccess(value)) { @@ -452,7 +453,7 @@ object Callback { private final class Safe[-E, -A](underlying: Callback[E, A])(implicit r: UncaughtExceptionReporter) extends Callback[E, A] { - private[this] val isActive = + private val isActive = monix.execution.atomic.AtomicBoolean(true) override def onSuccess(value: A): Unit = { diff --git a/monix-execution/shared/src/main/scala/monix/execution/Cancelable.scala b/monix-execution/shared/src/main/scala/monix/execution/Cancelable.scala index c2b7dc9f7..bf87f433a 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/Cancelable.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/Cancelable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,6 @@ package monix.execution import monix.execution.atomic.AtomicAny -import monix.execution.internal.Platform import monix.execution.schedulers.TrampolinedRunnable import scala.collection.mutable.ListBuffer import scala.concurrent.Promise @@ -92,7 +91,10 @@ object Cancelable { */ def fromPromise[A](p: Promise[A], e: Throwable): Cancelable = new Cancelable { - def cancel(): Unit = { p.tryFailure(e); () } + def cancel(): Unit = { + val _ = p.tryFailure(e) + () + } } /** Given a collection of cancelables, cancel them all. @@ -115,7 +117,8 @@ object Cancelable { case one :: Nil => throw one case first :: rest => - throw Platform.composeErrors(first, rest: _*) + rest.foreach(e => if (e ne first) first.addSuppressed(e)) + throw first case _ => () // Nothing } @@ -129,7 +132,7 @@ object Cancelable { private final class CancelableTask(cb: () => Unit) extends Cancelable { - private[this] val callbackRef = /*_*/ AtomicAny(cb) /*_*/ + private val callbackRef = /*_*/ AtomicAny(cb) /*_*/ def cancel(): Unit = { // Setting the callback to null with a `getAndSet` is solving @@ -145,7 +148,7 @@ object Cancelable { private final class CollectionTrampolined(refs: Iterable[Cancelable], sc: Scheduler) extends Cancelable with TrampolinedRunnable { - private[this] val atomic = /*_*/ AtomicAny(refs) /*_*/ + private val atomic = /*_*/ AtomicAny(refs) /*_*/ def cancel(): Unit = sc.execute(this) diff --git a/monix-execution/shared/src/main/scala/monix/execution/CancelableFuture.scala b/monix-execution/shared/src/main/scala/monix/execution/CancelableFuture.scala index 0c08a360c..6c783af72 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/CancelableFuture.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/CancelableFuture.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,15 +18,15 @@ package monix.execution import monix.execution.Cancelable.IsDummy -import monix.execution.CancelableFuture.{Async, Never, Pure} -import monix.execution.cancelables.{ChainedCancelable, SingleAssignCancelable} +import monix.execution.CancelableFuture.{ Async, Never, Pure } +import monix.execution.cancelables.{ ChainedCancelable, SingleAssignCancelable } import monix.execution.misc.Local import monix.execution.schedulers.TrampolinedRunnable import monix.execution.schedulers.TrampolineExecutionContext.immediate import scala.concurrent._ import scala.concurrent.duration.Duration import scala.reflect.ClassTag -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } import scala.util.control.NonFatal /** Represents an asynchronous computation that can be canceled @@ -53,7 +53,8 @@ sealed abstract class CancelableFuture[+A] extends Future[A] with Cancelable { s } override final def transform[S](s: (A) => S, f: (Throwable) => Throwable)(implicit - executor: ExecutionContext): CancelableFuture[S] = + executor: ExecutionContext + ): CancelableFuture[S] = transform { case Success(a) => Success(s(a)) case Failure(e) => Failure(f(e)) @@ -84,7 +85,8 @@ sealed abstract class CancelableFuture[+A] extends Future[A] with Cancelable { s } override final def recover[U >: A](pf: PartialFunction[Throwable, U])(implicit - executor: ExecutionContext): CancelableFuture[U] = + executor: ExecutionContext + ): CancelableFuture[U] = transform { case ref @ Success(_) => ref case Failure(e) => @@ -93,7 +95,8 @@ sealed abstract class CancelableFuture[+A] extends Future[A] with Cancelable { s } override final def recoverWith[U >: A](pf: PartialFunction[Throwable, Future[U]])(implicit - executor: ExecutionContext): CancelableFuture[U] = + executor: ExecutionContext + ): CancelableFuture[U] = transformWith { case Success(_) => this case Failure(e) => @@ -118,7 +121,7 @@ sealed abstract class CancelableFuture[+A] extends Future[A] with Cancelable { s this match { case Async(other, cRef, local) => CancelableFuture.applyWithLocal(other.mapTo[S], cRef, local) - case p: Pure[_] => + case p: Pure[Any] => CancelableFuture.applyWithLocal(super.mapTo[S], Cancelable.empty, p.isolatedCtx) case Never => Never @@ -126,9 +129,12 @@ sealed abstract class CancelableFuture[+A] extends Future[A] with Cancelable { s } override final def andThen[U](pf: PartialFunction[Try[A], U])(implicit - executor: ExecutionContext): CancelableFuture[A] = + executor: ExecutionContext + ): CancelableFuture[A] = transformWith { r => - if (pf.isDefinedAt(r)) pf(r) + if (pf.isDefinedAt(r)) { + val _ = pf(r) + } this } @@ -154,37 +160,40 @@ sealed abstract class CancelableFuture[+A] extends Future[A] with Cancelable { s // FutureUtils will use a polyfill for Scala 2.11 and will // use the real `transformWith` on Scala 2.12 - val f2 = FutureUtils.transformWith(underlying, { (result: Try[A]) => - if (isolatedCtx ne null) Local.setContext(isolatedCtx) - val nextRef: Future[S] = - try f(result) - catch { case e if NonFatal(e) => Future.failed(e) } - - // Checking to see if we are dealing with a "flatMap" - // future, in which case we need to chain the cancelable - // reference in order to not create a memory leak - nextRef match { - case ref: CancelableFuture[_] if ref ne Never => - val cf = ref.asInstanceOf[CancelableFuture[S]] - // If the resulting Future is completed, there's no reason - // to chain cancelable tokens - if (!cf.isCompleted) - cf.cancelable match { - case cRef2: ChainedCancelable => - // Chaining ensures we don't leak - cRef2.forwardTo(cRef) - case cRef2 => - if (!cRef2.isInstanceOf[IsDummy]) cRef := cRef2 - } - - // Returning underlying b/c otherwise we leak memory in - // infinite loops - cf.underlying - - case _ => - nextRef + val f2 = FutureUtils.transformWith( + underlying, + { (result: Try[A]) => + if (isolatedCtx ne null) Local.setContext(isolatedCtx) + val nextRef: Future[S] = + try f(result) + catch { case e if NonFatal(e) => Future.failed(e) } + + // Checking to see if we are dealing with a "flatMap" + // future, in which case we need to chain the cancelable + // reference in order to not create a memory leak + nextRef match { + case ref: CancelableFuture[?] if ref ne Never => + val cf = ref.asInstanceOf[CancelableFuture[S]] + // If the resulting Future is completed, there's no reason + // to chain cancelable tokens + if (!cf.isCompleted) + cf.cancelable match { + case cRef2: ChainedCancelable => + // Chaining ensures we don't leak + cRef2.forwardTo(cRef) + case cRef2 => + if (!cRef2.isInstanceOf[IsDummy]) cRef := cRef2 + } + + // Returning underlying b/c otherwise we leak memory in + // infinite loops + cf.underlying + + case _ => + nextRef + } } - }) + ) CancelableFuture.applyWithLocal(f2, cRef, isolatedCtx) } } @@ -304,7 +313,11 @@ object CancelableFuture extends internal.CancelableFutureForPlatform { private[monix] def successfulWithLocal[A](value: A, isolatedCtx: Local.Context): CancelableFuture[A] = new Pure[A](Success(value), isolatedCtx) - private[monix] def applyWithLocal[A](underlying: Future[A], cancelable: Cancelable, isolatedCtx: Local.Context): CancelableFuture[A] = + private[monix] def applyWithLocal[A]( + underlying: Future[A], + cancelable: Cancelable, + isolatedCtx: Local.Context + ): CancelableFuture[A] = new Async[A](underlying, cancelable, isolatedCtx) /** A [[CancelableFuture]] instance that will never complete. */ @@ -332,12 +345,14 @@ object CancelableFuture extends internal.CancelableFutureForPlatform { override def transform[S](f: (Try[Nothing]) => Try[S])(implicit executor: ExecutionContext): CancelableFuture[S] = this override def transformWith[S](f: (Try[Nothing]) => Future[S])(implicit - executor: ExecutionContext): CancelableFuture[S] = + executor: ExecutionContext + ): CancelableFuture[S] = this } /** An internal [[CancelableFuture]] implementation. */ - private[execution] final class Pure[+A](immediate: Try[A], override val isolatedCtx: Local.Context = null) extends CancelableFuture[A] { + private[execution] final class Pure[+A](immediate: Try[A], override val isolatedCtx: Local.Context = null) + extends CancelableFuture[A] { def ready(atMost: Duration)(implicit permit: CanAwait): this.type = this def result(atMost: Duration)(implicit permit: CanAwait): A = immediate.get @@ -349,14 +364,18 @@ object CancelableFuture extends internal.CancelableFutureForPlatform { def value: Option[Try[A]] = underlying.value def onComplete[U](f: (Try[A]) => U)(implicit executor: ExecutionContext): Unit = - executor.execute(new Runnable { - def run(): Unit = { f(immediate); () } + executor.execute(() => { + val _ = f(immediate) + () }) } /** An actual [[CancelableFuture]] implementation; internal. */ - private[execution] final case class Async[+A](underlying: Future[A], cancelable: Cancelable, override val isolatedCtx: Local.Context = null) - extends CancelableFuture[A] { + private[execution] final case class Async[+A]( + underlying: Future[A], + cancelable: Cancelable, + override val isolatedCtx: Local.Context = null + ) extends CancelableFuture[A] { override def onComplete[U](f: (Try[A]) => U)(implicit executor: ExecutionContext): Unit = { underlying.onComplete(f)(executor) diff --git a/monix-execution/shared/src/main/scala/monix/execution/CancelablePromise.scala b/monix-execution/shared/src/main/scala/monix/execution/CancelablePromise.scala index fc00e7895..7441c1da2 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/CancelablePromise.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/CancelablePromise.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,15 +18,14 @@ package monix.execution import monix.execution.atomic.PaddingStrategy.NoPadding -import monix.execution.internal.Platform import monix.execution.internal.exceptions.matchError -import monix.execution.atomic.{AtomicAny, PaddingStrategy} +import monix.execution.atomic.{ AtomicAny, PaddingStrategy } import scala.annotation.tailrec import scala.collection.immutable.LongMap import scala.collection.mutable.ListBuffer import scala.concurrent.Promise -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } import scala.util.control.NonFatal /** @@ -188,13 +187,13 @@ object CancelablePromise { // States: // - Try[A]: completed with a result // - MapQueue: listeners queue - private[this] val state = AtomicAny.withPadding[AnyRef](emptyMapQueue, ps) + private val state = AtomicAny.withPadding[AnyRef](emptyMapQueue, ps) override def subscribe(cb: Try[A] => Unit): Cancelable = unsafeSubscribe(cb) override def isCompleted: Boolean = - state.get().isInstanceOf[Try[_]] + state.get().isInstanceOf[Try[Any]] override def future: CancelableFuture[A] = state.get() match { @@ -212,7 +211,7 @@ object CancelablePromise { case other => // $COVERAGE-OFF$ matchError(other) - // $COVERAGE-ON$ + // $COVERAGE-ON$ } @tailrec @@ -242,8 +241,11 @@ object CancelablePromise { } if (errors ne null) { // Throws all errors as a composite - val x :: xs = errors.toList - throw Platform.composeErrors(x, xs: _*) + val errorList = errors.toList + val x = errorList.head + val xs = errorList.tail + xs.foreach(e => if (e ne x) x.addSuppressed(e)) + throw x } true } @@ -262,7 +264,7 @@ object CancelablePromise { case other => // $COVERAGE-OFF$ matchError(other) - // $COVERAGE-ON$ + // $COVERAGE-ON$ } @tailrec def unsafeSubscribe(cb: AnyRef): Cancelable = @@ -279,13 +281,13 @@ object CancelablePromise { case other => // $COVERAGE-OFF$ matchError(other) - // $COVERAGE-ON$ + // $COVERAGE-ON$ } private final class IdCancelable(id: Long) extends Cancelable { @tailrec def cancel(): Unit = state.get() match { - case queue: MapQueue[_] => + case queue: MapQueue[Any] => if (!state.compareAndSet(queue, queue.dequeue(id))) cancel() case _ => @@ -306,6 +308,6 @@ object CancelablePromise { map.valuesIterator } - private[this] val emptyMapQueue: MapQueue[Nothing] = + private val emptyMapQueue: MapQueue[Nothing] = MapQueue(LongMap.empty, 0) } diff --git a/monix-execution/shared/src/main/scala/monix/execution/ChannelType.scala b/monix-execution/shared/src/main/scala/monix/execution/ChannelType.scala index e2449e28d..2017dd6fa 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/ChannelType.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/ChannelType.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/ExecutionModel.scala b/monix-execution/shared/src/main/scala/monix/execution/ExecutionModel.scala index 4bcf2abc1..0b6a9c223 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/ExecutionModel.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/ExecutionModel.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/Features.scala b/monix-execution/shared/src/main/scala/monix/execution/Features.scala index fadca66cb..605dbe13e 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/Features.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/Features.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.execution -import monix.execution.Features.{Flag, Flags} +import monix.execution.Features.{ Flag, Flags } /** `Features` describes a set of features described via * bitwise operators applied to ints, but made type safe. diff --git a/monix-execution/shared/src/main/scala/monix/execution/FutureUtils.scala b/monix-execution/shared/src/main/scala/monix/execution/FutureUtils.scala index 506f30c99..6f37c4b92 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/FutureUtils.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/FutureUtils.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,10 +18,9 @@ package monix.execution import java.util.concurrent.TimeoutException -import monix.execution.schedulers.TrampolineExecutionContext.immediate import scala.concurrent.duration._ -import scala.concurrent.{ExecutionContext, Future, Promise} -import scala.util.{Success, Try} +import scala.concurrent.{ ExecutionContext, Future, Promise } +import scala.util.{ Success, Try } /** Utilities for Scala's standard `concurrent.Future`. */ object FutureUtils extends internal.FutureUtilsForPlatform { @@ -38,10 +37,14 @@ object FutureUtils extends internal.FutureUtilsForPlatform { def timeout[A](source: Future[A], atMost: FiniteDuration)(implicit s: Scheduler): Future[A] = { val err = new TimeoutException val promise = Promise[A]() - val task = s.scheduleOnce(atMost.length, atMost.unit, - new Runnable { - def run() = { promise.tryFailure(err); () } - }) + val task = s.scheduleOnce( + atMost.length, + atMost.unit, + () => { + val _ = promise.tryFailure(err) + () + } + ) source.onComplete { r => // canceling task to prevent waisted CPU resources and memory leaks @@ -66,13 +69,18 @@ object FutureUtils extends internal.FutureUtilsForPlatform { * source or with the fallback in case the timeout is reached */ def timeoutTo[A](source: Future[A], atMost: FiniteDuration, fallback: => Future[A])( - implicit s: Scheduler): Future[A] = { + implicit s: Scheduler + ): Future[A] = { val promise = Promise[Option[Try[A]]]() - val task = s.scheduleOnce(atMost.length, atMost.unit, - new Runnable { - def run() = { promise.trySuccess(None); () } - }) + val task = s.scheduleOnce( + atMost.length, + atMost.unit, + () => { + val _ = promise.trySuccess(None) + () + } + ) source.onComplete { r => // canceling task to prevent waisted CPU resources and memory leaks @@ -93,9 +101,8 @@ object FutureUtils extends internal.FutureUtilsForPlatform { /** Utility that lifts a `Future[A]` into a `Future[Try[A]]`, exposing * error explicitly. */ - def materialize[A](source: Future[A])(implicit ec: ExecutionContext): Future[Try[A]] = { - source.transform(t => Success(t))(immediate) - } + def materialize[A](source: Future[A])(implicit ec: ExecutionContext): Future[Try[A]] = + source.transform(t => Success(t)) /** Given a mapping functions that operates on successful results as well as * errors, transforms the source by applying it. @@ -116,16 +123,15 @@ object FutureUtils extends internal.FutureUtilsForPlatform { /** Utility that transforms a `Future[Try[A]]` into a `Future[A]`, * hiding errors, being the opposite of [[materialize]]. */ - def dematerialize[A](source: Future[Try[A]])(implicit ec: ExecutionContext): Future[A] = { - source.map(_.get)(immediate) - } + def dematerialize[A](source: Future[Try[A]])(implicit ec: ExecutionContext): Future[A] = + source.map(_.get) /** Creates a future that completes with the specified `result`, but only * after the specified `delay`. */ def delayedResult[A](delay: FiniteDuration)(result: => A)(implicit s: Scheduler): Future[A] = { val p = Promise[A]() - s.scheduleOnce(delay.length, delay.unit, new Runnable { def run() = p.complete(Try(result)) }) + val _ = s.scheduleOnce(delay.length, delay.unit, () => p.complete(Try(result))) p.future } @@ -147,7 +153,7 @@ object FutureUtils extends internal.FutureUtilsForPlatform { /** [[FutureUtils.dematerialize]] exposed as an extension method. */ def dematerialize[U](implicit ev: A <:< Try[U], ec: ExecutionContext): Future[U] = - FutureUtils.dematerialize(source.asInstanceOf[Future[Try[U]]]) + FutureUtils.dematerialize(source.map(ev.apply)) } /** Provides utility methods for Scala's `concurrent.Future` companion object. */ @@ -157,4 +163,4 @@ object FutureUtils extends internal.FutureUtilsForPlatform { FutureUtils.delayedResult(delay)(result) } } -} \ No newline at end of file +} diff --git a/monix-execution/shared/src/main/scala/monix/execution/Scheduler.scala b/monix-execution/shared/src/main/scala/monix/execution/Scheduler.scala index d28d06bae..e677b31a9 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/Scheduler.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/Scheduler.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,14 +24,15 @@ import monix.execution.schedulers.SchedulerCompanionImpl import scala.annotation.implicitNotFound import scala.concurrent.ExecutionContext -import scala.concurrent.duration.{FiniteDuration, MILLISECONDS, TimeUnit} +import scala.concurrent.duration.{ FiniteDuration, MILLISECONDS, TimeUnit } /** A Scheduler is an `scala.concurrent.ExecutionContext` that additionally can * schedule the execution of units of work to run with a delay or periodically. */ @implicitNotFound( "Cannot find an implicit Scheduler, either " + - "import monix.execution.Scheduler.Implicits.global or use a custom one") + "import monix.execution.Scheduler.Implicits.global or use a custom one" +) trait Scheduler extends ExecutionContext with UncaughtExceptionReporter with Executor { /** Schedules the given `command` for execution at some time in the future. * diff --git a/monix-execution/shared/src/main/scala/monix/execution/UncaughtExceptionReporter.scala b/monix-execution/shared/src/main/scala/monix/execution/UncaughtExceptionReporter.scala index 280dee78e..5eaac0199 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/UncaughtExceptionReporter.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/UncaughtExceptionReporter.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,7 +32,8 @@ import scala.concurrent.ExecutionContext @implicitNotFound( "No ExceptionReporter was found in context for " + "reporting uncaught errors, either build one yourself or use " + - "an implicit Scheduler (schedulers are ExceptionReporters)") + "an implicit Scheduler (schedulers are ExceptionReporters)" +) trait UncaughtExceptionReporter extends Serializable { def reportFailure(ex: Throwable): Unit } diff --git a/monix-execution/shared/src/main/scala/monix/execution/annotations/Unsafe.scala b/monix-execution/shared/src/main/scala/monix/execution/annotations/Unsafe.scala index d45bd064a..483a0d14d 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/annotations/Unsafe.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/annotations/Unsafe.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,7 +30,7 @@ import scala.annotation.StaticAnnotation * as specified or otherwise the behavior can be undefined, * see [[UnsafeProtocol]] */ -class Unsafe(reason: String) extends StaticAnnotation +class Unsafe(val reason: String) extends StaticAnnotation /** An annotation meant to warn users on functions that are * breaking referential transparency. diff --git a/monix-execution/shared/src/main/scala/monix/execution/cancelables/AssignableCancelable.scala b/monix-execution/shared/src/main/scala/monix/execution/cancelables/AssignableCancelable.scala index 8b02cc1ca..6497fff14 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/cancelables/AssignableCancelable.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/cancelables/AssignableCancelable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.execution.cancelables import monix.execution.Cancelable -import monix.execution.Cancelable.{Empty, IsDummy} +import monix.execution.Cancelable.{ Empty, IsDummy } /** Represents a class of cancelables that can hold * an internal reference to another cancelable (and thus @@ -65,7 +65,7 @@ object AssignableCancelable { /** A reusable [[AssignableCancelable]] instance that's already * canceled and that's going to cancel given values on assignment. */ - val alreadyCanceled: Bool with Empty = + val alreadyCanceled: Bool = new Bool with Empty { def isCanceled = true def cancel(): Unit = () diff --git a/monix-execution/shared/src/main/scala/monix/execution/cancelables/BooleanCancelable.scala b/monix-execution/shared/src/main/scala/monix/execution/cancelables/BooleanCancelable.scala index 4e9a514cd..ea6b87324 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/cancelables/BooleanCancelable.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/cancelables/BooleanCancelable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,7 +35,7 @@ object BooleanCancelable { /** Builder for [[BooleanCancelable]]. */ def apply(): BooleanCancelable = new BooleanCancelable { - @volatile private[this] var _isCanceled = false + @volatile private var _isCanceled = false def isCanceled = _isCanceled def cancel(): Unit = { @@ -54,7 +54,7 @@ object BooleanCancelable { /** Returns an instance of a [[BooleanCancelable]] that's * already canceled. */ - val alreadyCanceled: BooleanCancelable with Empty = + val alreadyCanceled: BooleanCancelable = new BooleanCancelable with Empty { val isCanceled = true def cancel() = () @@ -73,7 +73,7 @@ object BooleanCancelable { private final class BooleanCancelableTask(cb: () => Unit) extends BooleanCancelable { - private[this] val callbackRef = AtomicAny(cb) + private val callbackRef = AtomicAny(cb) def isCanceled: Boolean = callbackRef.get() eq null def cancel(): Unit = { diff --git a/monix-execution/shared/src/main/scala/monix/execution/cancelables/CompositeCancelable.scala b/monix-execution/shared/src/main/scala/monix/execution/cancelables/CompositeCancelable.scala index 38ab614c3..10c1ed7fa 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/cancelables/CompositeCancelable.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/cancelables/CompositeCancelable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.execution.cancelables import monix.execution.Cancelable -import monix.execution.atomic.{AtomicAny, PaddingStrategy} +import monix.execution.atomic.{ AtomicAny, PaddingStrategy } import scala.annotation.tailrec /** Represents a composite of multiple cancelables. In case it is canceled, all @@ -74,7 +74,7 @@ import scala.annotation.tailrec final class CompositeCancelable private (stateRef: AtomicAny[CompositeCancelable.State]) extends BooleanCancelable { self => - import CompositeCancelable.{Active, Cancelled} + import CompositeCancelable.{ Active, Cancelled } override def isCanceled: Boolean = stateRef.get() eq Cancelled @@ -223,7 +223,7 @@ final class CompositeCancelable private (stateRef: AtomicAny[CompositeCancelable } that match { - case ref: Set[_] => + case ref: Set[?] => loop(ref.asInstanceOf[Set[Cancelable]]) case _ => loop(that.toSet[Cancelable]) @@ -234,7 +234,7 @@ final class CompositeCancelable private (stateRef: AtomicAny[CompositeCancelable object CompositeCancelable { /** Builder for [[CompositeCancelable]]. */ def apply(initial: Cancelable*): CompositeCancelable = - withPadding(Set(initial: _*), PaddingStrategy.LeftRight128) + withPadding(initial.toSet, PaddingStrategy.LeftRight128) /** Builder for [[CompositeCancelable]]. */ def fromSet(initial: Set[Cancelable]): CompositeCancelable = diff --git a/monix-execution/shared/src/main/scala/monix/execution/cancelables/MultiAssignCancelable.scala b/monix-execution/shared/src/main/scala/monix/execution/cancelables/MultiAssignCancelable.scala index e4b7efbbd..cfcf60871 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/cancelables/MultiAssignCancelable.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/cancelables/MultiAssignCancelable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.execution.cancelables import monix.execution.Cancelable import monix.execution.Cancelable.IsDummy -import monix.execution.atomic.{AtomicAny, PaddingStrategy} +import monix.execution.atomic.{ AtomicAny, PaddingStrategy } import scala.annotation.tailrec @@ -49,7 +49,7 @@ import scala.annotation.tailrec */ final class MultiAssignCancelable private (initial: Cancelable) extends AssignableCancelable.Multi { - private[this] val state = { + private val state = { AtomicAny.withPadding(initial, PaddingStrategy.LeftRight128) } diff --git a/monix-execution/shared/src/main/scala/monix/execution/cancelables/OrderedCancelable.scala b/monix-execution/shared/src/main/scala/monix/execution/cancelables/OrderedCancelable.scala index 4ec911eb2..3a9c3816d 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/cancelables/OrderedCancelable.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/cancelables/OrderedCancelable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.execution.cancelables import monix.execution.Cancelable -import monix.execution.atomic.{AtomicAny, PaddingStrategy} +import monix.execution.atomic.{ AtomicAny, PaddingStrategy } import scala.annotation.tailrec /** Represents a [[monix.execution.Cancelable Cancelable]] whose @@ -64,9 +64,9 @@ import scala.annotation.tailrec */ final class OrderedCancelable private (initial: Cancelable) extends AssignableCancelable.Multi { - import OrderedCancelable.{Active, Cancelled, State} + import OrderedCancelable.{ Active, Cancelled, State } - private[this] val state = { + private val state = { val ref = if (initial != null) initial else Cancelable.empty AtomicAny.withPadding(Active(ref, 0): State, PaddingStrategy.LeftRight128) } diff --git a/monix-execution/shared/src/main/scala/monix/execution/cancelables/RefCountCancelable.scala b/monix-execution/shared/src/main/scala/monix/execution/cancelables/RefCountCancelable.scala index e00421429..8c8f170ae 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/cancelables/RefCountCancelable.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/cancelables/RefCountCancelable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -84,8 +84,8 @@ final class RefCountCancelable private (onCancel: () => Unit) extends BooleanCan } } - private[this] val state = AtomicAny(State(isCanceled = false, activeCounter = 0)) - private[this] case class State( + private val state = AtomicAny(State(isCanceled = false, activeCounter = 0)) + private case class State( isCanceled: Boolean, activeCounter: Int ) diff --git a/monix-execution/shared/src/main/scala/monix/execution/cancelables/SerialCancelable.scala b/monix-execution/shared/src/main/scala/monix/execution/cancelables/SerialCancelable.scala index fbcfb365b..26d14a0c5 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/cancelables/SerialCancelable.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/cancelables/SerialCancelable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.execution.cancelables import monix.execution.Cancelable -import monix.execution.atomic.{AtomicAny, PaddingStrategy} +import monix.execution.atomic.{ AtomicAny, PaddingStrategy } import scala.annotation.tailrec /** Represents a [[monix.execution.Cancelable]] whose underlying cancelable @@ -41,7 +41,7 @@ import scala.annotation.tailrec */ final class SerialCancelable private (initial: Cancelable) extends AssignableCancelable.Multi { - private[this] val state = { + private val state = { AtomicAny.withPadding(initial, PaddingStrategy.LeftRight128) } diff --git a/monix-execution/shared/src/main/scala/monix/execution/cancelables/SingleAssignCancelable.scala b/monix-execution/shared/src/main/scala/monix/execution/cancelables/SingleAssignCancelable.scala index 070e98680..ee1d398f5 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/cancelables/SingleAssignCancelable.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/cancelables/SingleAssignCancelable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -110,10 +110,11 @@ final class SingleAssignCancelable private (extra: Cancelable) extends Assignabl private def raiseError(): Nothing = { throw new IllegalStateException( "Cannot assign to SingleAssignmentCancelable, " + - "as it was already assigned once") + "as it was already assigned once" + ) } - private[this] val state = AtomicAny(Empty: State) + private val state = AtomicAny(Empty: State) } object SingleAssignCancelable { @@ -128,7 +129,7 @@ object SingleAssignCancelable { * {{{ * val c = { * val extra = Cancelable(() => println("extra canceled") - * SingleAssignmentCancelable.withExtra(extra) + * SingleAssignmentCancelable.plusOne(extra) * } * * c := Cancelable(() => println("main canceled")) diff --git a/monix-execution/shared/src/main/scala/monix/execution/cancelables/StackedCancelable.scala b/monix-execution/shared/src/main/scala/monix/execution/cancelables/StackedCancelable.scala index 273518854..c15b143f0 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/cancelables/StackedCancelable.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/cancelables/StackedCancelable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.execution.cancelables import monix.execution.Cancelable -import monix.execution.atomic.{AtomicAny, PaddingStrategy} +import monix.execution.atomic.{ AtomicAny, PaddingStrategy } import scala.annotation.tailrec /** Represents a composite of cancelables that are stacked, @@ -123,10 +123,9 @@ object StackedCancelable { * in order to safe a `state.get` instruction before the * `compareAndSet` happens. */ - private[this] var cache = initial + private var cache = initial - private[this] val state = - AtomicAny.withPadding(initial, PaddingStrategy.LeftRight128) + private val state = AtomicAny.withPadding(initial, PaddingStrategy.LeftRight128) override def isCanceled: Boolean = state.get() == null diff --git a/monix-execution/shared/src/main/scala/monix/execution/cancelables/package.scala b/monix-execution/shared/src/main/scala/monix/execution/cancelables/package.scala index 604d70c27..5d469b5d3 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/cancelables/package.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/cancelables/package.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/exceptions/APIContractViolationException.scala b/monix-execution/shared/src/main/scala/monix/execution/exceptions/APIContractViolationException.scala index 5025e39ef..96196ea4e 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/exceptions/APIContractViolationException.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/exceptions/APIContractViolationException.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.execution.exceptions import scala.runtime.AbstractFunction1 -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } /** Generic exception thrown on API contract violations. */ class APIContractViolationException(val message: String, cause: Throwable) @@ -56,10 +56,10 @@ object CallbackCalledMultipleTimesException extends AbstractFunction1[String, Ca def unapply(arg: CallbackCalledMultipleTimesException): Option[(String, Throwable)] = Some((arg.message, arg.getCause)) - def forResult[E](r: Try[_]): CallbackCalledMultipleTimesException = + def forResult[E](r: Try[Any]): CallbackCalledMultipleTimesException = forResult(r match { case Success(a) => Right(a); case Failure(e) => Left(e) }) - def forResult[E](r: Either[E, _]): CallbackCalledMultipleTimesException = { + def forResult[E](r: Either[E, Any]): CallbackCalledMultipleTimesException = { val (msg, cause) = r match { case Left(e) => ("onError", UncaughtErrorException.wrap(e)) case Right(_) => ("onSuccess", null) diff --git a/monix-execution/shared/src/main/scala/monix/execution/exceptions/BufferOverflowException.scala b/monix-execution/shared/src/main/scala/monix/execution/exceptions/BufferOverflowException.scala index 815976184..3c3c47759 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/exceptions/BufferOverflowException.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/exceptions/BufferOverflowException.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/exceptions/CompositeException.scala b/monix-execution/shared/src/main/scala/monix/execution/exceptions/CompositeException.scala index b0d3d1908..fbed0b54c 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/exceptions/CompositeException.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/exceptions/CompositeException.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/exceptions/DownstreamTimeoutException.scala b/monix-execution/shared/src/main/scala/monix/execution/exceptions/DownstreamTimeoutException.scala index 3537f6221..acaf89c42 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/exceptions/DownstreamTimeoutException.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/exceptions/DownstreamTimeoutException.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/exceptions/DummyException.scala b/monix-execution/shared/src/main/scala/monix/execution/exceptions/DummyException.scala index c4ba1aab9..e94225aab 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/exceptions/DummyException.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/exceptions/DummyException.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/exceptions/ExecutionRejectedException.scala b/monix-execution/shared/src/main/scala/monix/execution/exceptions/ExecutionRejectedException.scala index 305206cb3..8fd812dfb 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/exceptions/ExecutionRejectedException.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/exceptions/ExecutionRejectedException.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/exceptions/UncaughtErrorException.scala b/monix-execution/shared/src/main/scala/monix/execution/exceptions/UncaughtErrorException.scala index 164cd5225..72b8d3241 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/exceptions/UncaughtErrorException.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/exceptions/UncaughtErrorException.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/exceptions/UpstreamTimeoutException.scala b/monix-execution/shared/src/main/scala/monix/execution/exceptions/UpstreamTimeoutException.scala index 5fbd621d4..48601c417 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/exceptions/UpstreamTimeoutException.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/exceptions/UpstreamTimeoutException.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/AttemptCallback.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/AttemptCallback.scala index d14172d5c..731bb064d 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/AttemptCallback.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/AttemptCallback.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.execution.internal import monix.execution.UncaughtExceptionReporter -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } /** Internal API — some utilities for working with cats-effect * callbacks. diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/Constants.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/Constants.scala index c2e0828b6..a00f78336 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/Constants.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/Constants.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.execution.internal -import scala.util.{Success, Try} +import scala.util.{ Success, Try } /** * Reusable references used in Monix's implementation. diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/GenericSemaphore.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/GenericSemaphore.scala index 7714891e9..50d9d2160 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/GenericSemaphore.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/GenericSemaphore.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,8 +29,7 @@ private[monix] abstract class GenericSemaphore[CancelToken] protected (provision import GenericSemaphore.State require(provisioned >= 0, "provisioned >= 0") - private[this] val stateRef = - AtomicAny.withPadding(GenericSemaphore.initialState(provisioned), ps) + private val stateRef = AtomicAny.withPadding(GenericSemaphore.initialState(provisioned), ps) protected def emptyCancelable: CancelToken protected def makeCancelable(f: Listener[Unit] => Unit, p: Listener[Unit]): CancelToken @@ -187,7 +186,7 @@ private[monix] abstract class GenericSemaphore[CancelToken] protected (provision while (cursor.hasNext) cursor.next().apply(Constants.eitherOfUnit) } - private[this] val cancelAwaitRelease: (Listener[Unit] => Unit) = { + private val cancelAwaitRelease: (Listener[Unit] => Unit) = { @tailrec def loop(p: Listener[Unit]): Unit = { val current: State = stateRef.get() val update = current.removeAwaitReleaseRef(p) @@ -197,7 +196,7 @@ private[monix] abstract class GenericSemaphore[CancelToken] protected (provision loop } - private[this] def cancelAcquisition(n: Long, isAsync: Boolean): (Listener[Unit] => Unit) = { + private def cancelAcquisition(n: Long, isAsync: Boolean): (Listener[Unit] => Unit) = { @tailrec def loop(permit: Listener[Unit]): Unit = { val current: State = stateRef.get() @@ -230,7 +229,8 @@ private[monix] object GenericSemaphore { private final case class State( available: Long, awaitPermits: Queue[(Long, Listener[Unit])], - awaitReleases: List[(Long, Listener[Unit])]) { + awaitReleases: List[(Long, Listener[Unit])] + ) { def count: Long = { if (available > 0) available diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/GenericVar.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/GenericVar.scala index 9dc869a35..03be498aa 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/GenericVar.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/GenericVar.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.execution.internal -import monix.execution.atomic.{AtomicAny, PaddingStrategy} +import monix.execution.atomic.{ AtomicAny, PaddingStrategy } import monix.execution.internal.collection.LinkedMap import scala.annotation.tailrec @@ -30,7 +30,7 @@ import scala.annotation.tailrec private[monix] abstract class GenericVar[A, CancelToken] protected (initial: Option[A], ps: PaddingStrategy) { import GenericVar._ - private[this] val stateRef: AtomicAny[State[A]] = + private val stateRef: AtomicAny[State[A]] = AtomicAny.withPadding( initial match { case None => State.empty[A]; case Some(a) => State(a) }, ps @@ -264,7 +264,7 @@ private[monix] object GenericVar { /** Private [[State]] builders.*/ private object State { - private[this] val ref = WaitForPut[Any](LinkedMap.empty, LinkedMap.empty) + private val ref = WaitForPut[Any](LinkedMap.empty, LinkedMap.empty) def apply[A](a: A): State[A] = WaitForTake(a, LinkedMap.empty) /** `Empty` state, reusing the same instance. */ def empty[A]: State[A] = ref.asInstanceOf[State[A]] @@ -276,8 +276,8 @@ private[monix] object GenericVar { */ private final case class WaitForPut[A]( reads: LinkedMap[Id, Either[Nothing, A] => Unit], - takes: LinkedMap[Id, Either[Nothing, A] => Unit]) - extends State[A] + takes: LinkedMap[Id, Either[Nothing, A] => Unit] + ) extends State[A] /** `AsyncVar` state signaling it has one or more values enqueued, * to be signaled on the next `take`. diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/InterceptRunnable.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/InterceptRunnable.scala index 549d999ce..161ef3aaf 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/InterceptRunnable.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/InterceptRunnable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/Newtype1.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/Newtype1.scala index 717bf203c..480bcf4ae 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/Newtype1.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/Newtype1.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,7 +31,7 @@ package monix.execution.internal private[monix] abstract class Newtype1[F[_]] { self => type Base trait Tag extends Any - type Type[+A] <: Base with Tag + type Type[+A] <: Base def apply[A](fa: F[A]): Type[A] = fa.asInstanceOf[Type[A]] diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/RingBuffer.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/RingBuffer.scala index 5367c46f7..a4ed0e805 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/RingBuffer.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/RingBuffer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,11 +25,11 @@ package monix.execution.internal final private[monix] class RingBuffer[A <: AnyRef](logSize: Int) { // These two probably don't need to be allocated every single time, maybe in Java? - private[this] val length = 1 << logSize - private[this] val mask = length - 1 + private val length = 1 << logSize + private val mask = length - 1 - private[this] val array: Array[AnyRef] = new Array(length) - private[this] var index: Int = 0 + private val array: Array[AnyRef] = new Array(length) + private var index: Int = 0 def push(a: A): A = { val wi = index & mask diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/RunnableAction.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/RunnableAction.scala index 28c687bad..2d0bc56a4 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/RunnableAction.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/RunnableAction.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/Trampoline.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/Trampoline.scala index 9e7351bf0..8996d104b 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/Trampoline.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/Trampoline.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,18 +17,18 @@ package monix.execution.internal -import monix.execution.internal.Trampoline.{ForkingTrampolineEC, ImmediateTrampolineEC, ResumeRun, TrampolineEC} +import monix.execution.internal.Trampoline.{ ForkingTrampolineEC, ImmediateTrampolineEC, ResumeRun, TrampolineEC } import monix.execution.internal.collection.ChunkedArrayQueue import scala.annotation.tailrec -import scala.concurrent.{BlockContext, CanAwait, ExecutionContext} +import scala.concurrent.{ BlockContext, CanAwait, ExecutionContext } import scala.util.control.NonFatal private[execution] class Trampoline( - private[this] val fallbackTrampoline: Option[() => Trampoline] = None, + private val fallbackTrampoline: Option[() => Trampoline] = None, ) { - private[this] var immediateQueue: ChunkedArrayQueue[Runnable] = Trampoline.makeQueue() - private[this] var withinLoop: Boolean = false + private var immediateQueue: ChunkedArrayQueue[Runnable] = Trampoline.makeQueue() + private var withinLoop: Boolean = false def startLoop(runnable: Runnable, ec: TrampolineEC): Unit = { withinLoop = true @@ -115,8 +115,8 @@ private[execution] object Trampoline { def reportFailure(e: Throwable): Unit } - /** - * Trampoline backed by ForkingTrampolineEC handles problematic situations (unexpected exceptions or blocking + /** + * Trampoline backed by ForkingTrampolineEC handles problematic situations (unexpected exceptions or blocking * operations) by scheduling the remaining tasks to be executed on this execution context. */ final class ForkingTrampolineEC(ec: ExecutionContext) extends TrampolineEC { @@ -127,7 +127,7 @@ private[execution] object Trampoline { /** * Trampoline backed by ImmediateTrampolineEC executes everything on the current thread. * Used for optimization of the run loop. - * + * * WARNING: Using this ExecutionContext can lead to stack overflow errors if too many trampolined tasks throw * an exception or too many blocking operations are chained. */ diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/collection/Buffer.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/collection/Buffer.scala index 88a3e79d9..5e4975573 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/collection/Buffer.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/collection/Buffer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/collection/ChunkedArrayQueue.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/collection/ChunkedArrayQueue.scala index 55b79ce08..48009ca15 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/collection/ChunkedArrayQueue.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/collection/ChunkedArrayQueue.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,16 +23,16 @@ private[monix] final class ChunkedArrayQueue[A] private ( initialTailIndex: Int, initialHeadArray: Array[AnyRef], initialHeadIndex: Int, - chunkSize: Int) - extends Serializable { self => + chunkSize: Int +) extends Serializable { self => assert(chunkSize > 1, "chunkSize > 1") - private[this] val modulo = chunkSize - 1 - private[this] var tailArray = initialTailArray - private[this] var tailIndex = initialTailIndex - private[this] var headArray = initialHeadArray - private[this] var headIndex = initialHeadIndex + private val modulo = chunkSize - 1 + private var tailArray = initialTailArray + private var tailIndex = initialTailIndex + private var headArray = initialHeadArray + private var headIndex = initialHeadIndex /** * Returns `true` if the queue is empty, `false` otherwise. @@ -87,10 +87,10 @@ private[monix] final class ChunkedArrayQueue[A] private ( /** Builds an iterator out of this queue. */ def iterator: Iterator[A] = new Iterator[A] { - private[this] var headArray = self.headArray - private[this] var headIndex = self.headIndex - private[this] val tailArray = self.tailArray - private[this] val tailIndex = self.tailIndex + private var headArray = self.headArray + private var headIndex = self.headIndex + private val tailArray = self.tailArray + private val tailIndex = self.tailIndex def hasNext: Boolean = { (headArray ne tailArray) || headIndex < tailIndex diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/collection/ChunkedArrayStack.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/collection/ChunkedArrayStack.scala index d5ba04948..1f180f84f 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/collection/ChunkedArrayStack.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/collection/ChunkedArrayStack.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,9 +27,9 @@ private[monix] final class ChunkedArrayStack[A] private (initialArray: Array[Any assert(chunkSize > 1, "chunkSize > 1") - private[this] val modulo = chunkSize - 1 - private[this] var array = initialArray - private[this] var index = initialIndex + private val modulo = chunkSize - 1 + private var array = initialArray + private var index = initialIndex /** Returns `true` if the stack is empty. */ def isEmpty: Boolean = @@ -86,8 +86,8 @@ private[monix] final class ChunkedArrayStack[A] private (initialArray: Array[Any /** Builds an iterator out of this stack. */ def iteratorReversed: Iterator[A] = new Iterator[A] { - private[this] var array = self.array - private[this] var index = self.index + private var array = self.array + private var index = self.index def hasNext: Boolean = { index > 0 || (array(0) ne null) diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/collection/DropAllOnOverflowQueue.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/collection/DropAllOnOverflowQueue.scala index 5369118ea..04a6bca9a 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/collection/DropAllOnOverflowQueue.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/collection/DropAllOnOverflowQueue.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,19 +31,19 @@ private[monix] final class DropAllOnOverflowQueue[A: ClassTag] private (_recomme extends EvictingQueue[A] { self => require(_recommendedCapacity > 0, "recommendedCapacity must be positive") - private[this] val maxSize = { + private val maxSize = { val v = nextPowerOf2(_recommendedCapacity + 1) if (v <= 1) 2 else v } - private[this] val modulus = maxSize - 1 + private val modulus = maxSize - 1 def capacity: Int = modulus - private[this] val array = new Array[A](maxSize) + private val array = new Array[A](maxSize) // head is incremented by `poll()`, or by `offer()` on overflow - private[this] var headIdx = 0 + private var headIdx = 0 // tail is incremented by `offer()` - private[this] var tailIdx = 0 + private var tailIdx = 0 override def isAtCapacity: Boolean = size >= modulus @@ -138,12 +138,12 @@ private[monix] final class DropAllOnOverflowQueue[A: ClassTag] private (_recomme */ def iterator(exactSize: Boolean): Iterator[A] = { new Iterator[A] { - private[this] var isStarted = false - private[this] val initialTailIdx = self.tailIdx - private[this] var tailIdx = 0 - private[this] var headIdx = 0 + private var isStarted = false + private val initialTailIdx = self.tailIdx + private var tailIdx = 0 + private var headIdx = 0 - private[this] val initialHeadIdx = { + private val initialHeadIdx = { if (!exactSize) self.headIdx else { // Dropping extra elements @@ -170,7 +170,7 @@ private[monix] final class DropAllOnOverflowQueue[A: ClassTag] private (_recomme } } - private[this] def init(): Unit = { + private def init(): Unit = { isStarted = true if (self.headIdx != self.tailIdx) { headIdx = initialHeadIdx diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/collection/DropHeadOnOverflowQueue.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/collection/DropHeadOnOverflowQueue.scala index ec3999279..f3cf7241f 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/collection/DropHeadOnOverflowQueue.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/collection/DropHeadOnOverflowQueue.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,19 +32,19 @@ private[monix] final class DropHeadOnOverflowQueue[A: ClassTag] private (_recomm extends EvictingQueue[A] { self => require(_recommendedCapacity > 0, "recommendedCapacity must be positive") - private[this] val maxSize = { + private val maxSize = { val v = nextPowerOf2(_recommendedCapacity + 1) if (v <= 1) 2 else v } - private[this] val modulus = maxSize - 1 + private val modulus = maxSize - 1 def capacity: Int = modulus - private[this] val array = new Array[A](maxSize) + private val array = new Array[A](maxSize) // head is incremented by `poll()`, or by `offer()` on overflow - private[this] var headIdx = 0 + private var headIdx = 0 // tail is incremented by `offer()` - private[this] var tailIdx = 0 + private var tailIdx = 0 override def isEmpty: Boolean = headIdx == tailIdx @@ -142,10 +142,10 @@ private[monix] final class DropHeadOnOverflowQueue[A: ClassTag] private (_recomm */ def iterator(exactSize: Boolean): Iterator[A] = { new Iterator[A] { - private[this] var isStarted = false + private var isStarted = false - private[this] val initialTailIdx = self.tailIdx - private[this] val initialHeadIdx = { + private val initialTailIdx = self.tailIdx + private val initialHeadIdx = { if (!exactSize) self.headIdx else { // Dropping extra elements @@ -155,8 +155,8 @@ private[monix] final class DropHeadOnOverflowQueue[A: ClassTag] private (_recomm } } - private[this] var tailIdx = 0 - private[this] var headIdx = 0 + private var tailIdx = 0 + private var headIdx = 0 def hasNext: Boolean = { if (!isStarted) init() @@ -175,7 +175,7 @@ private[monix] final class DropHeadOnOverflowQueue[A: ClassTag] private (_recomm } } - private[this] def init(): Unit = { + private def init(): Unit = { isStarted = true if (self.headIdx != self.tailIdx) { headIdx = initialHeadIdx diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/collection/EvictingQueue.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/collection/EvictingQueue.scala index 18a300e3e..4d59a71ef 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/collection/EvictingQueue.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/collection/EvictingQueue.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/collection/LinkedMap.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/collection/LinkedMap.scala index 47f940197..e38201dd5 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/collection/LinkedMap.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/collection/LinkedMap.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,8 +26,9 @@ import scala.collection.immutable.LongMap */ private[monix] class LinkedMap[K, +V]( val entries: Map[K, (V, Long)], - private[this] val insertionOrder: LongMap[K], - private[this] val nextId: Long) { + private val insertionOrder: LongMap[K], + private val nextId: Long +) { /** Returns `true` if this map is empty, or `false` otherwise. */ def isEmpty: Boolean = @@ -47,7 +48,8 @@ private[monix] class LinkedMap[K, +V]( .get(k) .map { case (_, id) => insertionOrder - id } .getOrElse(insertionOrder), - nextId) + nextId + ) /** The keys in this map, in the order they were added. */ def keys: Iterable[K] = insertionOrder.values diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/collection/LowLevelConcurrentQueue.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/collection/LowLevelConcurrentQueue.scala index d0e54a569..07d4d520a 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/collection/LowLevelConcurrentQueue.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/collection/LowLevelConcurrentQueue.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/exceptions.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/exceptions.scala index a2515bd82..101ebe2b0 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/exceptions.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/exceptions.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ private[monix] object exceptions { /** * To use in `case _ =>` branches that are absurd, but needed * due to the compiler complaining. - */ + */ def matchError[A](received: A): Nothing = throw new scala.MatchError(received) } diff --git a/monix-execution/shared/src/main/scala/monix/execution/internal/math.scala b/monix-execution/shared/src/main/scala/monix/execution/internal/math.scala index 15d8885bb..200955a4e 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/internal/math.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/internal/math.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.execution.internal -import scala.math.{ceil, round} +import scala.math.{ ceil, round } private[monix] object math { /** Natural log of 2 */ diff --git a/monix-execution/shared/src/main/scala/monix/execution/misc/CanBindLocals.scala b/monix-execution/shared/src/main/scala/monix/execution/misc/CanBindLocals.scala index b10c73721..e83a059c6 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/misc/CanBindLocals.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/misc/CanBindLocals.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,11 +18,12 @@ package monix.execution.misc import implicitbox.Not -import monix.execution.{CancelableFuture, FutureUtils} +import monix.execution.{ CancelableFuture, FutureUtils } import monix.execution.schedulers.TrampolineExecutionContext import scala.annotation.implicitNotFound import scala.concurrent.Future +import scala.annotation.unused /** * Type class describing how [[Local]] binding works for specific data types. @@ -72,7 +73,7 @@ private[misc] abstract class CanIsolateInstancesLevel1 extends CanIsolateInstanc * Needs to be imported explicitly in scope. Will NOT override * other `CanBindLocals` implicits that are already visible. */ - @inline implicit def synchronousAsDefault[R](implicit ev: Not[CanBindLocals[R]]): CanBindLocals[R] = + @inline implicit def synchronousAsDefault[R](implicit @unused ev: Not[CanBindLocals[R]]): CanBindLocals[R] = CanBindLocals.synchronous[R] } } @@ -142,10 +143,13 @@ private[misc] abstract class CanIsolateInstancesLevel0 { try { FutureUtils - .transform[Any, Any](f, result => { - Local.setContext(prev) - result - })(TrampolineExecutionContext.immediate) + .transform[Any, Any]( + f, + result => { + Local.setContext(prev) + result + } + )(TrampolineExecutionContext.immediate) } finally { Local.setContext(prev) } diff --git a/monix-execution/shared/src/main/scala/monix/execution/misc/LocalDeprecated.scala b/monix-execution/shared/src/main/scala/monix/execution/misc/LocalDeprecated.scala index 5dc932311..4d403e472 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/misc/LocalDeprecated.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/misc/LocalDeprecated.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/misc/package.scala b/monix-execution/shared/src/main/scala/monix/execution/misc/package.scala index 16efdde65..ba091b148 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/misc/package.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/misc/package.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/rstreams/ReactivePullStrategy.scala b/monix-execution/shared/src/main/scala/monix/execution/rstreams/ReactivePullStrategy.scala index ddae90dad..5f935cf4b 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/rstreams/ReactivePullStrategy.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/rstreams/ReactivePullStrategy.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/rstreams/SingleAssignSubscription.scala b/monix-execution/shared/src/main/scala/monix/execution/rstreams/SingleAssignSubscription.scala index 0367799d1..6f141944a 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/rstreams/SingleAssignSubscription.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/rstreams/SingleAssignSubscription.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,7 +35,7 @@ final class SingleAssignSubscription private () extends Subscription { import SingleAssignSubscription.State import SingleAssignSubscription.State._ - private[this] val state = AtomicAny(Empty: State) + private val state = AtomicAny(Empty: State) def :=(s: org.reactivestreams.Subscription): Unit = set(s) diff --git a/monix-execution/shared/src/main/scala/monix/execution/rstreams/Subscription.scala b/monix-execution/shared/src/main/scala/monix/execution/rstreams/Subscription.scala index 6f779f21f..dbc2fcfee 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/rstreams/Subscription.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/rstreams/Subscription.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/rstreams/package.scala b/monix-execution/shared/src/main/scala/monix/execution/rstreams/package.scala index 3aeb9b617..ba73c4ffe 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/rstreams/package.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/rstreams/package.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/schedulers/BatchingScheduler.scala b/monix-execution/shared/src/main/scala/monix/execution/schedulers/BatchingScheduler.scala index b2247cf19..224f3ba9e 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/schedulers/BatchingScheduler.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/schedulers/BatchingScheduler.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -36,13 +36,12 @@ import scala.concurrent.ExecutionContext trait BatchingScheduler extends Scheduler { self => protected def executeAsync(r: Runnable): Unit - private[this] val trampoline = - TrampolineExecutionContext(new ExecutionContext { - def execute(runnable: Runnable): Unit = - self.executeAsync(runnable) - def reportFailure(cause: Throwable): Unit = - self.reportFailure(cause) - }) + private val trampoline = TrampolineExecutionContext(new ExecutionContext { + def execute(runnable: Runnable): Unit = + self.executeAsync(runnable) + def reportFailure(cause: Throwable): Unit = + self.reportFailure(cause) + }) override final def execute(runnable: Runnable): Unit = runnable match { diff --git a/monix-execution/shared/src/main/scala/monix/execution/schedulers/ExecuteExtensions.scala b/monix-execution/shared/src/main/scala/monix/execution/schedulers/ExecuteExtensions.scala index df78e496a..e3597809d 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/schedulers/ExecuteExtensions.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/schedulers/ExecuteExtensions.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/schedulers/ReferenceScheduler.scala b/monix-execution/shared/src/main/scala/monix/execution/schedulers/ReferenceScheduler.scala index 12041af74..c704f24c9 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/schedulers/ReferenceScheduler.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/schedulers/ReferenceScheduler.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,11 +19,11 @@ package monix.execution.schedulers import monix.execution.cancelables.OrderedCancelable import monix.execution.schedulers.ReferenceScheduler.WrappedScheduler -import monix.execution.{Cancelable, Features, Scheduler, UncaughtExceptionReporter} -import scala.concurrent.duration.{MILLISECONDS, NANOSECONDS, TimeUnit} +import monix.execution.{ Cancelable, Features, Scheduler, UncaughtExceptionReporter } +import scala.concurrent.duration.{ MILLISECONDS, NANOSECONDS, TimeUnit } import monix.execution.internal.InterceptRunnable // Prevents conflict with the deprecated symbol -import monix.execution.{ExecutionModel => ExecModel} +import monix.execution.{ ExecutionModel => ExecModel } /** Helper for building a [[Scheduler]]. * @@ -46,12 +46,11 @@ trait ReferenceScheduler extends Scheduler { sub := scheduleOnce( initialDelay, unit, - new Runnable { - def run(): Unit = { - r.run() - loop(delay, delay) - } - }) + () => { + r.run() + loop(delay, delay) + } + ) () } } @@ -71,19 +70,17 @@ trait ReferenceScheduler extends Scheduler { sub := scheduleOnce( initialDelayMs, MILLISECONDS, - new Runnable { - def run(): Unit = { - r.run() - - val delay = { - val durationMillis = clockMonotonic(MILLISECONDS) - startedAtMillis - val d = periodMs - durationMillis - if (d >= 0) d else 0 - } - - // Recursive call - loop(delay, periodMs) + () => { + r.run() + + val delay = { + val durationMillis = clockMonotonic(MILLISECONDS) - startedAtMillis + val d = periodMs - durationMillis + if (d >= 0) d else 0 } + + // Recursive call + loop(delay, periodMs) } ) () @@ -112,7 +109,7 @@ object ReferenceScheduler { override val executionModel: ExecModel, reporter: UncaughtExceptionReporter = null ) extends Scheduler { - private[this] val reporterRef = if (reporter eq null) s else reporter + private val reporterRef = if (reporter eq null) s else reporter override def execute(runnable: Runnable): Unit = s.execute(InterceptRunnable(runnable, reporter)) diff --git a/monix-execution/shared/src/main/scala/monix/execution/schedulers/SchedulerService.scala b/monix-execution/shared/src/main/scala/monix/execution/schedulers/SchedulerService.scala index 831c63693..58792a87c 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/schedulers/SchedulerService.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/schedulers/SchedulerService.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,11 @@ package monix.execution.schedulers -import monix.execution.{Scheduler, UncaughtExceptionReporter, ExecutionModel => ExecModel} +import monix.execution.{ ExecutionModel => ExecModel, Scheduler, UncaughtExceptionReporter } import monix.execution.internal.Platform import monix.execution.schedulers.TrampolineExecutionContext.immediate -import scala.concurrent.{ExecutionContext, Future} -import scala.concurrent.duration.{FiniteDuration, TimeUnit} +import scala.concurrent.{ ExecutionContext, Future } +import scala.concurrent.duration.{ FiniteDuration, TimeUnit } /** A [[monix.execution.Scheduler Scheduler]] type that provides * methods for managing termination. diff --git a/monix-execution/shared/src/main/scala/monix/execution/schedulers/ShiftedRunnable.scala b/monix-execution/shared/src/main/scala/monix/execution/schedulers/ShiftedRunnable.scala index 74f474837..897f023e5 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/schedulers/ShiftedRunnable.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/schedulers/ShiftedRunnable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/schedulers/StartAsyncBatchRunnable.scala b/monix-execution/shared/src/main/scala/monix/execution/schedulers/StartAsyncBatchRunnable.scala index bfaa11da3..603646729 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/schedulers/StartAsyncBatchRunnable.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/schedulers/StartAsyncBatchRunnable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/schedulers/TestScheduler.scala b/monix-execution/shared/src/main/scala/monix/execution/schedulers/TestScheduler.scala index 60a8cec5a..760ce528a 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/schedulers/TestScheduler.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/schedulers/TestScheduler.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,13 +19,12 @@ package monix.execution package schedulers import monix.execution.atomic.AtomicAny -import monix.execution.cancelables.SingleAssignCancelable import scala.util.control.NonFatal import monix.execution.schedulers.TestScheduler._ import scala.annotation.tailrec import scala.collection.immutable.SortedSet -import scala.concurrent.duration.{Duration, FiniteDuration, TimeUnit} +import scala.concurrent.duration.{ Duration, FiniteDuration, TimeUnit } import scala.util.Random /** [[Scheduler]] and a provider of `cats.effect.Timer` instances, @@ -126,9 +125,9 @@ import scala.util.Random * }}} */ final class TestScheduler private ( - private[this] val stateRef: AtomicAny[State], - override val executionModel: ExecutionModel) - extends ReferenceScheduler with BatchingScheduler { + private val stateRef: AtomicAny[State], + override val executionModel: ExecutionModel +) extends ReferenceScheduler with BatchingScheduler { /** * Returns the internal state of the `TestScheduler`, useful for testing @@ -338,7 +337,8 @@ object TestScheduler { clock = Duration.Zero, tasks = SortedSet.empty[Task], lastReportedError = null - )) + ) + ) new TestScheduler(state, executionModel) } @@ -387,13 +387,13 @@ object TestScheduler { state: State, delay: FiniteDuration, r: Runnable, - cancelTask: Task => Unit): (Cancelable, State) = { + cancelTask: Task => Unit + ): (Cancelable, State) = { // $COVERAGE-OFF$ require(delay >= Duration.Zero, "The given delay must be positive") // $COVERAGE-ON$ val newID = state.lastID + 1 - SingleAssignCancelable() val task = Task(newID, r, state.clock + delay) val cancelable = new Cancelable { def cancel(): Unit = cancelTask(task) @@ -409,6 +409,7 @@ object TestScheduler { state.copy( lastID = newID, tasks = state.tasks + task - )) + ) + ) } } diff --git a/monix-execution/shared/src/main/scala/monix/execution/schedulers/TracingRunnable.scala b/monix-execution/shared/src/main/scala/monix/execution/schedulers/TracingRunnable.scala index 84ad773b1..d8d625c63 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/schedulers/TracingRunnable.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/schedulers/TracingRunnable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/main/scala/monix/execution/schedulers/TracingScheduler.scala b/monix-execution/shared/src/main/scala/monix/execution/schedulers/TracingScheduler.scala index c95e6e76e..2d45e014b 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/schedulers/TracingScheduler.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/schedulers/TracingScheduler.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.execution.schedulers import scala.concurrent.duration.TimeUnit -import monix.execution.{Cancelable, Features, Scheduler, UncaughtExceptionReporter, ExecutionModel => ExecModel} +import monix.execution.{ Cancelable, ExecutionModel => ExecModel, Features, Scheduler, UncaughtExceptionReporter } import scala.concurrent.ExecutionContext /** The `TracingScheduler` is a [[monix.execution.Scheduler Scheduler]] diff --git a/monix-execution/shared/src/main/scala/monix/execution/schedulers/TracingSchedulerService.scala b/monix-execution/shared/src/main/scala/monix/execution/schedulers/TracingSchedulerService.scala index f2e292bf4..67f7f547e 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/schedulers/TracingSchedulerService.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/schedulers/TracingSchedulerService.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,9 @@ package monix.execution.schedulers -import monix.execution.{ExecutionModel, UncaughtExceptionReporter} +import monix.execution.{ ExecutionModel, UncaughtExceptionReporter } import scala.concurrent.duration.TimeUnit -import scala.concurrent.{ExecutionContext, Future} +import scala.concurrent.{ ExecutionContext, Future } /** The `TracingScheduler` is a [[monix.execution.Scheduler Scheduler]] * implementation that wraps another diff --git a/monix-execution/shared/src/main/scala/monix/execution/schedulers/TrampolineScheduler.scala b/monix-execution/shared/src/main/scala/monix/execution/schedulers/TrampolineScheduler.scala index f25673999..14c5cffb8 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/schedulers/TrampolineScheduler.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/schedulers/TrampolineScheduler.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,9 +18,9 @@ package monix.execution.schedulers import java.util.concurrent.TimeUnit -import monix.execution.{Cancelable, Features, Scheduler, UncaughtExceptionReporter} +import monix.execution.{ Cancelable, Features, Scheduler, UncaughtExceptionReporter } // Prevents conflict with the deprecated symbol -import monix.execution.{ExecutionModel => ExecModel} +import monix.execution.{ ExecutionModel => ExecModel } /** A [[monix.execution.Scheduler Scheduler]] implementation * that executes runnables immediately, on the current thread, @@ -56,8 +56,7 @@ import monix.execution.{ExecutionModel => ExecModel} final class TrampolineScheduler(underlying: Scheduler, override val executionModel: ExecModel) extends Scheduler { self => - private[this] val trampoline = - TrampolineExecutionContext(underlying) + private val trampoline = TrampolineExecutionContext(underlying) override def execute(runnable: Runnable): Unit = trampoline.execute(runnable) diff --git a/monix-execution/shared/src/main/scala/monix/execution/schedulers/TrampolinedRunnable.scala b/monix-execution/shared/src/main/scala/monix/execution/schedulers/TrampolinedRunnable.scala index 9c04fe07d..522a2f979 100644 --- a/monix-execution/shared/src/main/scala/monix/execution/schedulers/TrampolinedRunnable.scala +++ b/monix-execution/shared/src/main/scala/monix/execution/schedulers/TrampolinedRunnable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/test/scala/monix/execution/AckSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/AckSuite.scala index a3af5d289..8ed528de7 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/AckSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/AckSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,13 +18,13 @@ package monix.execution import minitest.TestSuite -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler import monix.execution.internal.Platform -import scala.concurrent.{Future, Promise} -import scala.util.{Failure, Success, Try} +import scala.concurrent.{ Future, Promise } +import scala.util.{ Failure, Success, Try } object AckSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() @@ -46,7 +46,7 @@ object AckSuite extends TestSuite[TestScheduler] { test("syncOnContinue(Continue) should execute synchronously #1") { implicit s => var triggered = false - Continue.syncOnContinue { triggered = true } + val _ = Continue.syncOnContinue { triggered = true } assert(triggered, "triggered") } @@ -58,26 +58,26 @@ object AckSuite extends TestSuite[TestScheduler] { () => triggered = value } - continue.syncOnContinue(trigger()) + val _ = continue.syncOnContinue(trigger()) assert(triggered, "triggered") } test("syncOnContinue(Future.successful(Continue)) should execute trampolined") { implicit s => def loop(source: Future[Ack], n: Int): Future[Ack] = source.syncOnContinue { - if (n > 0) { loop(source, n - 1); () } + if (n > 0) { val _ = loop(source, n - 1); () } } var triggered = false val continue: Future[Ack] = Future.successful(Continue) - loop(continue, stackSafeLoopN).syncOnContinue { triggered = true } + val _ = loop(continue, stackSafeLoopN).syncOnContinue { triggered = true } assert(triggered, "triggered") } test("syncOnContinue(Future(Continue)) should execute async") { implicit s => var triggered = false val continue: Future[Ack] = Future(Continue) - continue.syncOnContinue { triggered = true } + val _ = continue.syncOnContinue { triggered = true } assert(!triggered, "!triggered") s.tick() @@ -86,7 +86,7 @@ object AckSuite extends TestSuite[TestScheduler] { test("syncOnContinue(Stop) should execute synchronously #1") { implicit s => var triggered = false - (Stop: Future[Ack]).syncOnContinue { triggered = true } + val _ = (Stop: Future[Ack]).syncOnContinue { triggered = true } assert(!triggered, "!triggered") assert(s.state.tasks.isEmpty, "there should be no async task registered") } @@ -99,7 +99,7 @@ object AckSuite extends TestSuite[TestScheduler] { () => triggered = value } - cancel.syncOnContinue(trigger()) + val _ = cancel.syncOnContinue(trigger()) assert(!triggered, "!triggered") assert(s.state.tasks.isEmpty, "there should be no async task registered") } @@ -107,14 +107,14 @@ object AckSuite extends TestSuite[TestScheduler] { test("syncOnContinue(Future.successful(Stop)) should execute trampolined") { implicit s => var triggered = false val stop = Future.successful(Stop: Ack) - stop.syncOnContinue { triggered = true } + val _ = stop.syncOnContinue { triggered = true } assert(!triggered, "!triggered") assert(s.state.tasks.isEmpty, "tasks.isEmpty") } test("syncOnContinue(Future(Stop)) should execute async") { implicit s => var triggered = false - Future(Stop: Ack).syncOnContinue { triggered = true } + val _ = Future(Stop: Ack).syncOnContinue { triggered = true } assert(s.state.tasks.nonEmpty, "async tasks should be registered") s.tick() assert(!triggered, "!triggered") @@ -122,19 +122,19 @@ object AckSuite extends TestSuite[TestScheduler] { test("syncOnContinue(Continue) should protect against user errors") { implicit s => val ex = new RuntimeException("dummy") - Continue.syncOnContinue { throw ex } + val _ = Continue.syncOnContinue { throw ex } assertEquals(s.state.lastReportedError, ex) } test("syncOnContinue(Future.successful(Continue)) should protect against user errors") { implicit s => val ex = new RuntimeException("dummy") - Future.successful(Continue).syncOnContinue { throw ex } + val _ = Future.successful(Continue).syncOnContinue { throw ex } assertEquals(s.state.lastReportedError, ex) } test("syncOnStopOrFailure(Stop) should execute synchronously") { implicit s => var triggered = false - Stop.syncOnStopOrFailure { ex => + val _ = Stop.syncOnStopOrFailure { ex => if (ex.isEmpty) triggered = true } assert(triggered, "triggered") @@ -143,7 +143,7 @@ object AckSuite extends TestSuite[TestScheduler] { test("syncOnStopOrFailure(Future(Stop)) should execute asynchronously") { implicit s => var triggered = false - Future(Stop).syncOnStopOrFailure { ex => + val _ = Future(Stop).syncOnStopOrFailure { ex => if (ex.isEmpty) triggered = true } assert(!triggered, "!triggered") @@ -156,11 +156,11 @@ object AckSuite extends TestSuite[TestScheduler] { test("syncOnStopOrFailure(Future.successful(Stop)) should execute trampolined") { implicit s => def loop(source: Future[Ack], n: Int): Future[Ack] = source.syncOnStopOrFailure { _ => - if (n > 0) { loop(source, n - 1); () } + if (n > 0) { val _ = loop(source, n - 1); () } } var triggered = false - loop(Future.successful(Stop), stackSafeLoopN).syncOnStopOrFailure { ex => + val _ = loop(Future.successful(Stop), stackSafeLoopN).syncOnStopOrFailure { ex => triggered = ex.isEmpty } assert(triggered, "triggered") @@ -168,7 +168,7 @@ object AckSuite extends TestSuite[TestScheduler] { test("syncOnStopOrFailure(Continue) should execute synchronously") { implicit s => var triggered = false - (Continue: Ack).syncOnStopOrFailure { ex => + val _ = (Continue: Ack).syncOnStopOrFailure { ex => if (ex.isEmpty) triggered = true } assert(!triggered, "!triggered") @@ -177,7 +177,7 @@ object AckSuite extends TestSuite[TestScheduler] { test("syncOnStopOrFailure(Future.successful(Continue)) should execute trampolined") { implicit s => var triggered = false - (Future.successful(Continue): Future[Ack]).syncOnStopOrFailure { ex => + val _ = (Future.successful(Continue): Future[Ack]).syncOnStopOrFailure { ex => triggered = ex.isEmpty } assert(!triggered, "!triggered") @@ -186,7 +186,7 @@ object AckSuite extends TestSuite[TestScheduler] { test("syncOnStopOrFailure(Future(Continue)) should execute asynchronously") { implicit s => var triggered = false - (Future(Continue): Future[Ack]).syncOnStopOrFailure { ex => + val _ = (Future(Continue): Future[Ack]).syncOnStopOrFailure { ex => if (ex.isEmpty) triggered = true } assert(s.state.tasks.nonEmpty, "there should be async tasks registered") @@ -200,7 +200,7 @@ object AckSuite extends TestSuite[TestScheduler] { var triggered = false val ex = new RuntimeException("dummy") val ack: Future[Ack] = Future.failed(ex) - ack.syncOnStopOrFailure { p => + val _ = ack.syncOnStopOrFailure { p => triggered = p.fold(triggered)(_ == ex) } assertEquals(triggered, true) @@ -210,7 +210,7 @@ object AckSuite extends TestSuite[TestScheduler] { var triggered = false val ex = new RuntimeException("dummy") val ack: Future[Ack] = Future { throw ex } - ack.syncOnStopOrFailure { p => + val _ = ack.syncOnStopOrFailure { p => triggered = p.fold(triggered)(_ == ex) } @@ -222,7 +222,7 @@ object AckSuite extends TestSuite[TestScheduler] { test("syncOnStopOrFailure(Stop) should protect against user errors") { implicit s => val ex = new RuntimeException("dummy") - Stop.syncOnStopOrFailure { _ => + val _ = Stop.syncOnStopOrFailure { _ => throw ex } assertEquals(s.state.lastReportedError, ex) @@ -230,7 +230,7 @@ object AckSuite extends TestSuite[TestScheduler] { test("syncOnStopOrFailure(Future(Stop)) should protect against user errors") { implicit s => val ex = new RuntimeException("dummy") - Future(Stop).syncOnStopOrFailure { _ => + val _ = Future(Stop).syncOnStopOrFailure { _ => throw ex } s.tick() @@ -240,7 +240,7 @@ object AckSuite extends TestSuite[TestScheduler] { test("syncOnStopOrFailure(Future.failed(ex)) should protect against user errors") { implicit s => val ex = new RuntimeException("dummy") val source = Future.failed[Ack](new RuntimeException("first")) - source.syncOnStopOrFailure { _ => + val _ = source.syncOnStopOrFailure { _ => throw ex } assertEquals(s.state.lastReportedError, ex) @@ -249,7 +249,7 @@ object AckSuite extends TestSuite[TestScheduler] { test("syncOnStopOrFailure(Future(throw ex)) should protect against user errors") { implicit s => val ex = new RuntimeException("dummy") val source = Future[Ack](throw new RuntimeException("first")) - source.syncOnStopOrFailure { _ => + val _ = source.syncOnStopOrFailure { _ => throw ex } s.tick() @@ -531,52 +531,52 @@ object AckSuite extends TestSuite[TestScheduler] { s.tick() } - test("isSynchronous(Future(Continue)) == false") { implicit s => + test("isSynchronous(Future(Continue)) == false") { _ => val f: Future[Ack] = Future.successful(Continue) assert(!f.isSynchronous) } - test("isSynchronous(Continue) == true") { implicit s => + test("isSynchronous(Continue) == true") { _ => val f: Future[Ack] = Continue assert(f.isSynchronous) } - test("isSynchronous(Future(Stop)) == false") { implicit s => + test("isSynchronous(Future(Stop)) == false") { _ => val f: Future[Ack] = Future.successful(Stop) assert(!f.isSynchronous) } - test("isSynchronous(Stop) == true") { implicit s => + test("isSynchronous(Stop) == true") { _ => val f: Future[Ack] = Stop assert(f.isSynchronous) } - test("isSynchronous(failure) == false") { implicit s => + test("isSynchronous(failure) == false") { _ => val f: Future[Ack] = Future.failed(new RuntimeException) assert(!f.isSynchronous) } - test("isSynchronous(impure Future(Continue)) == false") { implicit s => + test("isSynchronous(impure Future(Continue)) == false") { _ => def f: Future[Ack] = Future.successful(Continue) assert(!f.isSynchronous) } - test("isSynchronous(impure Continue) == true") { implicit s => + test("isSynchronous(impure Continue) == true") { _ => def f: Future[Ack] = Continue assert(f.isSynchronous) } - test("isSynchronous(impure Future(Stop)) == false") { implicit s => + test("isSynchronous(impure Future(Stop)) == false") { _ => def f: Future[Ack] = Future.successful(Stop) assert(!f.isSynchronous) } - test("isSynchronous(impure Stop) == true") { implicit s => + test("isSynchronous(impure Stop) == true") { _ => def f: Future[Ack] = Stop assert(f.isSynchronous) } - test("isSynchronous(impure failure) == false") { implicit s => + test("isSynchronous(impure failure) == false") { _ => def f: Future[Ack] = Future.failed(new RuntimeException) assert(!f.isSynchronous) } @@ -712,11 +712,11 @@ object AckSuite extends TestSuite[TestScheduler] { assertEquals(s.state.lastReportedError, dummy) } - test("Continue.syncOnContinueFollow") { implicit s => + test("Continue.syncOnContinueFollow") { _ => val ack: Future[Ack] = Continue val p = Promise[Int]() - ack.syncOnContinueFollow(p, 1) + val _ = ack.syncOnContinueFollow(p, 1) // should be immediate assertEquals(p.future.value, Some(Success(1))) } @@ -725,7 +725,7 @@ object AckSuite extends TestSuite[TestScheduler] { val ack: Future[Ack] = Stop val p = Promise[Int]() - ack.syncOnContinueFollow(p, 1) + val _ = ack.syncOnContinueFollow(p, 1) s.tick() assertEquals(p.future.value, None) } @@ -734,7 +734,7 @@ object AckSuite extends TestSuite[TestScheduler] { val ack: Future[Ack] = Future(Continue) val p = Promise[Int]() - ack.syncOnContinueFollow(p, 1) + val _ = ack.syncOnContinueFollow(p, 1) assertEquals(p.future.value, None) // should be async @@ -746,7 +746,7 @@ object AckSuite extends TestSuite[TestScheduler] { val ack: Future[Ack] = Future(Stop) val p = Promise[Int]() - ack.syncOnContinueFollow(p, 1) + val _ = ack.syncOnContinueFollow(p, 1) s.tick() assertEquals(p.future.value, None) } @@ -755,16 +755,16 @@ object AckSuite extends TestSuite[TestScheduler] { val ack: Future[Ack] = Continue val p = Promise[Int]() - ack.syncOnStopFollow(p, 1) + val _ = ack.syncOnStopFollow(p, 1) s.tick() assertEquals(p.future.value, None) } - test("Stop.syncOnStopFollow") { implicit s => + test("Stop.syncOnStopFollow") { _ => val ack: Future[Ack] = Stop val p = Promise[Int]() - ack.syncOnStopFollow(p, 1) + val _ = ack.syncOnStopFollow(p, 1) // should be immediate assertEquals(p.future.value, Some(Success(1))) } @@ -773,7 +773,7 @@ object AckSuite extends TestSuite[TestScheduler] { val ack: Future[Ack] = Future(Continue) val p = Promise[Int]() - ack.syncOnStopFollow(p, 1) + val _ = ack.syncOnStopFollow(p, 1) s.tick() assertEquals(p.future.value, None) } @@ -782,7 +782,7 @@ object AckSuite extends TestSuite[TestScheduler] { val ack: Future[Ack] = Future(Stop) val p = Promise[Int]() - ack.syncOnStopFollow(p, 1) + val _ = ack.syncOnStopFollow(p, 1) s.tick() assertEquals(p.future.value, Some(Success(1))) } diff --git a/monix-execution/shared/src/test/scala/monix/execution/AsyncQueueSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/AsyncQueueSuite.scala index b89aef39c..dc0097e87 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/AsyncQueueSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/AsyncQueueSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,8 +19,8 @@ package monix.execution import java.util.concurrent.atomic.AtomicLong import minitest.TestSuite -import monix.execution.BufferCapacity.{Bounded, Unbounded} -import monix.execution.ChannelType.{MPMC, MPSC, SPMC, SPSC} +import monix.execution.BufferCapacity.{ Bounded, Unbounded } +import monix.execution.ChannelType.{ MPMC, MPSC, SPMC, SPSC } import monix.execution.internal.Platform import monix.execution.schedulers.TestScheduler import scala.collection.immutable.Queue @@ -41,7 +41,7 @@ object AsyncQueueFakeSuite extends BaseAsyncQueueSuite[TestScheduler] { Future.successful(()) test(name) { implicit ec => - repeatTest(f(ec), times) + val _ = repeatTest(f(ec), times) ec.tick(1.day) } } @@ -120,7 +120,8 @@ abstract class BaseAsyncQueueSuite[S <: Scheduler] extends TestSuite[S] { if (n > 0) queue.poll().flatMap { a => consumer(n - 1, acc.enqueue(a)) - } else + } + else Future.successful(acc.foldLeft(0L)(_ + _)) val p = producer(count) diff --git a/monix-execution/shared/src/test/scala/monix/execution/AsyncSemaphoreSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/AsyncSemaphoreSuite.scala index 9da2e8ada..666983728 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/AsyncSemaphoreSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/AsyncSemaphoreSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,8 +20,8 @@ package monix.execution import minitest.TestSuite import monix.execution.schedulers.TestScheduler import monix.execution.internal.Platform -import scala.concurrent.{ExecutionContext, Future, Promise} -import scala.util.{Random, Success} +import scala.concurrent.{ ExecutionContext, Future, Promise } +import scala.util.{ Random, Success } object AsyncSemaphoreSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() @@ -218,7 +218,7 @@ object AsyncSemaphoreSuite extends TestSuite[TestScheduler] { assertEquals(r, count) assertEquals(semaphore.available(), available) } - } + } } def repeatTest(n: Int)(f: () => Future[Unit])(implicit ec: ExecutionContext): Future[Unit] = diff --git a/monix-execution/shared/src/test/scala/monix/execution/AsyncVarSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/AsyncVarSuite.scala index 0710eda91..de0a9fa28 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/AsyncVarSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/AsyncVarSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/test/scala/monix/execution/BaseLawsSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/BaseLawsSuite.scala index a83207a5c..e634cedfa 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/BaseLawsSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/BaseLawsSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,14 +27,12 @@ import monix.execution.exceptions.DummyException import org.scalacheck.Test.Parameters import monix.execution.internal.Platform import monix.execution.schedulers.TestScheduler -import org.scalacheck.{Arbitrary, Cogen, Gen, Prop} +import org.scalacheck.{ Arbitrary, Cogen, Gen, Prop } import org.typelevel.discipline.Laws import scala.concurrent.duration._ -import scala.concurrent.{ExecutionException, Future} -import scala.util.{Failure, Success, Try} - -import scala.language.implicitConversions +import scala.concurrent.{ ExecutionException, Future } +import scala.util.{ Failure, Success, Try } trait BaseLawsSuite extends SimpleTestSuite with Checkers with ArbitraryInstances { override lazy val checkConfig: Parameters = @@ -48,15 +46,14 @@ trait BaseLawsSuite extends SimpleTestSuite with Checkers with ArbitraryInstance .withMaxDiscardRatio(50.0f) .withMaxSize(6) - def checkAll(name: String, ruleSet: Laws#RuleSet, config: Parameters = checkConfig): Unit = { + def checkAll(name: String, ruleSet: Laws#RuleSet): Unit = { for ((id, prop: Prop) <- ruleSet.all.properties) test(name + "." + id) { check(prop) } } - def checkAllAsync(name: String, config: Parameters = checkConfig)(f: TestScheduler => Laws#RuleSet): Unit = { - + def checkAllAsync(name: String)(f: TestScheduler => Laws#RuleSet): Unit = { val s = TestScheduler() val ruleSet = f(s) @@ -157,7 +154,6 @@ trait ArbitraryInstancesBase extends cats.instances.AllInstances with TestUtils implicit def equalityTry[A: Eq]: Eq[Try[A]] = new Eq[Try[A]] { val optA = implicitly[Eq[Option[A]]] - val optT = implicitly[Eq[Option[Throwable]]] def eqv(x: Try[A], y: Try[A]): Boolean = if (x.isSuccess) optA.eqv(x.toOption, y.toOption) diff --git a/monix-execution/shared/src/test/scala/monix/execution/CallbackSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/CallbackSuite.scala index 40ef2ba53..59dddb184 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/CallbackSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/CallbackSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,11 +18,11 @@ package monix.execution import minitest.TestSuite -import monix.execution.exceptions.{CallbackCalledMultipleTimesException, DummyException} +import monix.execution.exceptions.{ CallbackCalledMultipleTimesException, DummyException } import monix.execution.schedulers.TestScheduler import scala.concurrent.Promise -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } object CallbackSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() @@ -46,25 +46,25 @@ object CallbackSuite extends TestSuite[TestScheduler] { } } - test("onValue should invoke onSuccess") { implicit s => + test("onValue should invoke onSuccess") { _ => val callback = TestCallback() callback.onSuccess(1) assert(callback.successCalled) } - test("apply Success(value) should invoke onSuccess") { implicit s => + test("apply Success(value) should invoke onSuccess") { _ => val callback = TestCallback() callback(Success(1)) assert(callback.successCalled) } - test("apply Failure(ex) should invoke onError") { implicit s => + test("apply Failure(ex) should invoke onError") { _ => val callback = TestCallback() callback(Failure(new IllegalStateException())) assert(callback.errorCalled) } - test("contramap should pipe onError") { implicit s => + test("contramap should pipe onError") { _ => var result = Option.empty[Try[Int]] val callback = TestCallback( { v => @@ -72,7 +72,8 @@ object CallbackSuite extends TestSuite[TestScheduler] { }, { e => result = Some(Failure(e)) - }) + } + ) val stringCallback = callback.contramap[String](_.toInt) val dummy = DummyException("dummy") @@ -81,7 +82,7 @@ object CallbackSuite extends TestSuite[TestScheduler] { assertEquals(result, Some(Failure(dummy))) } - test("contramap should invoke function before invoking callback") { implicit s => + test("contramap should invoke function before invoking callback") { _ => val callback = TestCallback() val stringCallback = callback.contramap[String](_.toInt) stringCallback.onSuccess("1") @@ -94,8 +95,8 @@ object CallbackSuite extends TestSuite[TestScheduler] { cb.onSuccess(1) assertEquals(p.future.value, Some(Success(1))) - intercept[IllegalStateException] { cb.onSuccess(2) } - intercept[CallbackCalledMultipleTimesException] { cb.onSuccess(2) } + val _ = intercept[IllegalStateException] { cb.onSuccess(2) } + val _ = intercept[CallbackCalledMultipleTimesException] { cb.onSuccess(2) } () } @@ -107,13 +108,13 @@ object CallbackSuite extends TestSuite[TestScheduler] { cb.onError(dummy) assertEquals(p.future.value, Some(Failure(dummy))) - intercept[IllegalStateException] { cb.onSuccess(1) } - intercept[CallbackCalledMultipleTimesException] { cb.onSuccess(1) } + val _ = intercept[IllegalStateException] { cb.onSuccess(1) } + val _ = intercept[CallbackCalledMultipleTimesException] { cb.onSuccess(1) } () } test("Callback.empty reports errors") { implicit s => - val empty = Callback[Throwable].empty[Int] + val empty = Callback.empty[Throwable, Int] val dummy = DummyException("dummy") empty.onError(dummy) @@ -133,7 +134,7 @@ object CallbackSuite extends TestSuite[TestScheduler] { throw new IllegalStateException("onError") } - val safe = Callback[Throwable].safe(cb) + val safe = Callback.safe(cb) assert(safe.tryOnSuccess(1), "safe.tryOnSuccess(1)") assertEquals(effect, 1) @@ -158,7 +159,7 @@ object CallbackSuite extends TestSuite[TestScheduler] { } } - val safe = Callback[Throwable].safe(cb) + val safe = Callback.safe(cb) assert(safe.tryOnError(dummy2), "safe.onError(dummy2)") assertEquals(effect, 1) @@ -187,7 +188,7 @@ object CallbackSuite extends TestSuite[TestScheduler] { test("fromAttempt success") { _ => val p = Promise[Int]() - val cb = Callback[Throwable].fromAttempt[Int] { + val cb = Callback.fromAttempt[Throwable, Int] { case Right(a) => p.success(a); () case Left(e) => p.failure(e); () } @@ -198,7 +199,7 @@ object CallbackSuite extends TestSuite[TestScheduler] { test("fromAttempt error") { _ => val p = Promise[Int]() - val cb = Callback[Throwable].fromAttempt[Int] { + val cb = Callback.fromAttempt[Throwable, Int] { case Right(a) => p.success(a); () case Left(e) => p.failure(e); () } diff --git a/monix-execution/shared/src/test/scala/monix/execution/CancelableFutureSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/CancelableFutureSuite.scala index 7914b5264..c289f927c 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/CancelableFutureSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/CancelableFutureSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,31 +18,31 @@ package monix.execution import minitest.TestSuite -import monix.execution.cancelables.{BooleanCancelable, ChainedCancelable} +import monix.execution.cancelables.{ BooleanCancelable, ChainedCancelable } import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler import scala.concurrent.duration._ -import scala.concurrent.{Future, Promise} -import scala.util.{Failure, Success, Try} +import scala.concurrent.{ Future, Promise } +import scala.util.{ Failure, Success, Try } object CancelableFutureSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() def tearDown(env: TestScheduler): Unit = assert(env.state.tasks.isEmpty, "should not have tasks left to execute") - test("CancelableFuture.fromTry(success)") { implicit s => + test("CancelableFuture.fromTry(success)") { _ => val f = CancelableFuture.fromTry(Success(1)) assertEquals(f.value, Some(Success(1))) } - test("CancelableFuture.fromTry(failure)") { implicit s => + test("CancelableFuture.fromTry(failure)") { _ => val ex = new RuntimeException("dummy") val f = CancelableFuture.fromTry(Failure(ex)) assertEquals(f.value, Some(Failure(ex))) } - test("CancelableFuture.successful is already completed") { implicit s => + test("CancelableFuture.successful is already completed") { _ => val f = CancelableFuture.successful(1) assertEquals(f.isCompleted, true) assertEquals(f.value, Some(Success(1))) @@ -73,7 +73,7 @@ object CancelableFutureSuite extends TestSuite[TestScheduler] { assertEquals(result, Some(Success(1))) } - test("now.failed") { implicit s => + test("now.failed") { _ => val dummy = new RuntimeException("dummy") val f = CancelableFuture.failed(dummy).failed assertEquals(f.value, Some(Success(dummy))) @@ -351,7 +351,7 @@ object CancelableFutureSuite extends TestSuite[TestScheduler] { assertEquals(f.value, Some(Success(4))) } - test("now.fallbackTo") { implicit s => + test("now.fallbackTo") { _ => val ex = new RuntimeException("dummy") val f = CancelableFuture .failed(ex) @@ -382,12 +382,12 @@ object CancelableFutureSuite extends TestSuite[TestScheduler] { assertEquals(f.value, Some(Success(1))) } - test("now.mapTo") { implicit s => + test("now.mapTo") { _ => val f = CancelableFuture.successful(1).mapTo[Int] assertEquals(f.value, Some(Success(1))) } - test("never.mapTo") { implicit s => + test("never.mapTo") { _ => val f = CancelableFuture.never[Int].mapTo[Int] assertEquals(f, CancelableFuture.never) } @@ -531,7 +531,8 @@ object CancelableFutureSuite extends TestSuite[TestScheduler] { CancelableFuture.never[Unit], Cancelable { () => c.cancel() - }) + } + ) } assert(first.isCompleted, "!first.isCompleted") diff --git a/monix-execution/shared/src/test/scala/monix/execution/CancelablePromiseSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/CancelablePromiseSuite.scala index 0190a8622..377c3b4b0 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/CancelablePromiseSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/CancelablePromiseSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import minitest.SimpleTestSuite import monix.execution.exceptions.DummyException import scala.concurrent.Promise -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object CancelablePromiseSuite extends SimpleTestSuite { test("completes in success") { @@ -31,7 +31,7 @@ object CancelablePromiseSuite extends SimpleTestSuite { val f1 = p.future val f2 = p.future val p3 = Promise[Int]() - p.subscribe { v => p3.complete(v); () } + val _ = p.subscribe { v => p3.complete(v); () } assert(f1 ne f2, "f1 != f2") @@ -44,7 +44,7 @@ object CancelablePromiseSuite extends SimpleTestSuite { assertEquals(p.future.value, Some(Success(99))) val p4 = Promise[Int]() - p.subscribe { v => p4.complete(v); () } + val _ = p.subscribe { v => p4.complete(v); () } assertEquals(p4.future.value, Some(Success(99))) } @@ -55,7 +55,7 @@ object CancelablePromiseSuite extends SimpleTestSuite { val f1 = p.future val f2 = p.future val p3 = Promise[Int]() - p.subscribe { v => p3.complete(v); () } + val _ = p.subscribe { v => p3.complete(v); () } assert(f1 ne f2, "f1 != f2") @@ -69,7 +69,7 @@ object CancelablePromiseSuite extends SimpleTestSuite { assertEquals(p.future.value, Some(Failure(dummy))) val p4 = Promise[Int]() - p.subscribe { v => p4.complete(v); () } + val _ = p.subscribe { v => p4.complete(v); () } assertEquals(p4.future.value, Some(Failure(dummy))) } @@ -96,7 +96,7 @@ object CancelablePromiseSuite extends SimpleTestSuite { val c1 = p.subscribe { v => p1.complete(v); () } val p2 = Promise[Int]() - p.subscribe { v => p2.complete(v); () } + val _ = p.subscribe { v => p2.complete(v); () } val p3 = Promise[Int]() val c3 = p.subscribe { v => p3.complete(v); () } @@ -116,7 +116,7 @@ object CancelablePromiseSuite extends SimpleTestSuite { assert(p.isCompleted) val p1 = Promise[Int]() - p.subscribe { v => p1.complete(v); () } + val _ = p.subscribe { v => p1.complete(v); () } assertEquals(p1.future.value, Some(Success(1))) val f = p.future @@ -134,7 +134,7 @@ object CancelablePromiseSuite extends SimpleTestSuite { assert(p.isCompleted) val p1 = Promise[Int]() - p.subscribe { v => p1.complete(v); () } + val _ = p.subscribe { v => p1.complete(v); () } assertEquals(p1.future.value, Some(Failure(dummy))) val f = p.future diff --git a/monix-execution/shared/src/test/scala/monix/execution/CancelableSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/CancelableSuite.scala index 7a390a0a2..9f9e78bfb 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/CancelableSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/CancelableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,13 +18,15 @@ package monix.execution import minitest.SimpleTestSuite -import monix.execution.exceptions.{CompositeException, DummyException} +import monix.execution.exceptions.{ CompositeException, DummyException } import monix.execution.schedulers.TestScheduler import monix.execution.internal.Platform +import scala.annotation.nowarn import scala.concurrent.Promise import scala.util.Failure import scala.util.control.NonFatal +@nowarn("msg=The syntax `x: _\\*` is no longer supported for vararg splices; use `x\\*` instead") object CancelableSuite extends SimpleTestSuite { test("Cancelable.empty") { val c = Cancelable() @@ -54,7 +56,7 @@ object CancelableSuite extends SimpleTestSuite { test("Cancelable.collection(refs)") { var effect = 0 - val c = Cancelable.collection((0 until 100).map(_ => Cancelable(() => effect += 1)): _*) + val c = Cancelable.collection((0 until 100).map(_ => Cancelable(() => effect += 1))*) assertEquals(effect, 0) c.cancel() @@ -79,8 +81,10 @@ object CancelableSuite extends SimpleTestSuite { assertEquals(e, dummy1) assertEquals(e.getSuppressed.toList, List(dummy2)) } else { - val CompositeException(errors) = e - assertEquals(errors.toList, List(dummy1, dummy2)) + e match { + case CompositeException(errors) => assertEquals(errors.toList, List(dummy1, dummy2)) + case other => assertEquals(other, dummy1) + } } } } @@ -98,7 +102,7 @@ object CancelableSuite extends SimpleTestSuite { test("Cancelable.trampolined(refs)") { implicit val sc = TestScheduler() var effect = 0 - val c = Cancelable.trampolined((0 until 100).map(_ => Cancelable(() => effect += 1)): _*) + val c = Cancelable.trampolined((0 until 100).map(_ => Cancelable(() => effect += 1))*) assertEquals(effect, 0) c.cancel() @@ -121,8 +125,10 @@ object CancelableSuite extends SimpleTestSuite { assertEquals(e, dummy1) assertEquals(e.getSuppressed.toList, List(dummy2)) } else { - val CompositeException(errors) = sc.state.lastReportedError - assertEquals(errors.toList, List(dummy1, dummy2)) + sc.state.lastReportedError match { + case CompositeException(errors) => assertEquals(errors.toList, List(dummy1, dummy2)) + case other => assertEquals(other, dummy1) + } } } diff --git a/monix-execution/shared/src/test/scala/monix/execution/FeaturesSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/FeaturesSuite.scala index b019c8d6a..da1a2a8d0 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/FeaturesSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/FeaturesSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.execution import cats.implicits._ import minitest.SimpleTestSuite import minitest.laws.Checkers -import monix.execution.Features.{Flag, Flags} +import monix.execution.Features.{ Flag, Flags } import org.scalacheck.Arbitrary object FeaturesSuite extends SimpleTestSuite with Checkers { @@ -31,7 +31,7 @@ object FeaturesSuite extends SimpleTestSuite with Checkers { test("Features.intersect") { check2 { (f1: Features, f2: Features) => - val r = f1 intersect f2 + val r = f1.intersect(f2) allFlags.forall { flag => (f1.contains(flag) && f2.contains(flag)) === r.contains(flag) } @@ -40,7 +40,7 @@ object FeaturesSuite extends SimpleTestSuite with Checkers { test("Features.union") { check2 { (f1: Features, f2: Features) => - val r = f1 union f2 + val r = f1.union(f2) allFlags.forall { flag => (f1.contains(flag) || f2.contains(flag)) === r.contains(flag) } @@ -49,7 +49,7 @@ object FeaturesSuite extends SimpleTestSuite with Checkers { test("Features.diff") { check2 { (f1: Features, f2: Features) => - val r = f1 diff f2 + val r = f1.diff(f2) allFlags.forall { flag => if (f2.contains(flag)) !r.contains(flag) diff --git a/monix-execution/shared/src/test/scala/monix/execution/FutureUtilsSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/FutureUtilsSuite.scala index 053402201..b731a7edf 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/FutureUtilsSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/FutureUtilsSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,8 +22,8 @@ import monix.execution.FutureUtils.extensions._ import monix.execution.schedulers.TestScheduler import scala.concurrent.duration._ -import scala.concurrent.{Future, TimeoutException} -import scala.util.{Failure, Success, Try} +import scala.concurrent.{ Future, TimeoutException } +import scala.util.{ Failure, Success, Try } object FutureUtilsSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() @@ -55,7 +55,7 @@ object FutureUtilsSuite extends TestSuite[TestScheduler] { val t = f.timeout(30.millis) s.tick(10.seconds) - intercept[TimeoutException] { t.value.get.get; () } + val _ = intercept[TimeoutException] { val _ = t.value.get.get; () } () } @@ -82,26 +82,19 @@ object FutureUtilsSuite extends TestSuite[TestScheduler] { val expected = 15 val f = Future .delayedResult(50.millis)(expected) - .timeoutTo(100.millis, { - called = true - Future.failed(new RuntimeException) - }) + .timeoutTo( + 100.millis, { + called = true + Future.failed(new RuntimeException) + } + ) s.tick(1.second) assertEquals(f.value, Some(Success(expected))) assertEquals(called, false) } - test("materialize synchronous") { implicit s => - val f1 = Future.successful(1).materialize - assertEquals(f1.value, Some(Success(Success(1)))) - - val dummy = new RuntimeException("dummy") - val f2 = (Future.failed(dummy): Future[Int]).materialize - assertEquals(f2.value, Some(Success(Failure(dummy)))) - } - - test("materialize asynchronous") { implicit s => + test("materialize") { implicit s => val f1 = Future(1).materialize; s.tick() assertEquals(f1.value, Some(Success(Success(1)))) @@ -110,19 +103,7 @@ object FutureUtilsSuite extends TestSuite[TestScheduler] { assertEquals(f2.value, Some(Success(Failure(dummy)))) } - test("dematerialize synchronous") { implicit s => - val f1 = Future.successful(Success(1)).dematerialize - assertEquals(f1.value, Some(Success(1))) - - val dummy = new RuntimeException("dummy") - val f2 = Future.successful(Failure(dummy)).dematerialize - assertEquals(f2.value, Some(Failure(dummy))) - - val f3 = (Future.failed(dummy): Future[Try[Int]]).dematerialize - assertEquals(f3.value, Some(Failure(dummy))) - } - - test("dematerialize asynchronous") { implicit s => + test("dematerialize") { implicit s => val f1 = Future(Success(1)).dematerialize; s.tick() assertEquals(f1.value, Some(Success(1))) diff --git a/monix-execution/shared/src/test/scala/monix/execution/TestUtils.scala b/monix-execution/shared/src/test/scala/monix/execution/TestUtils.scala index eeadf768f..071e343ab 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/TestUtils.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/TestUtils.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.execution import monix.execution.internal.Platform -import java.io.{ByteArrayOutputStream, PrintStream} +import java.io.{ ByteArrayOutputStream, PrintStream } import scala.util.control.NonFatal /** diff --git a/monix-execution/shared/src/test/scala/monix/execution/cancelables/AssignableCancelableSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/cancelables/AssignableCancelableSuite.scala index 1a3cf066f..be092127c 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/cancelables/AssignableCancelableSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/cancelables/AssignableCancelableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/test/scala/monix/execution/cancelables/BooleanCancelableSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/cancelables/BooleanCancelableSuite.scala index 0ef9121d6..0865f25f9 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/cancelables/BooleanCancelableSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/cancelables/BooleanCancelableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/test/scala/monix/execution/cancelables/ChainedCancelableSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/cancelables/ChainedCancelableSuite.scala index e422cae8e..1314e7f78 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/cancelables/ChainedCancelableSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/cancelables/ChainedCancelableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/test/scala/monix/execution/cancelables/CompositeCancelableSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/cancelables/CompositeCancelableSuite.scala index 3a7f01244..18123da90 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/cancelables/CompositeCancelableSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/cancelables/CompositeCancelableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,9 +21,11 @@ import minitest.SimpleTestSuite import minitest.laws.Checkers import monix.execution.Cancelable import monix.execution.atomic.PaddingStrategy.LeftRight256 +import scala.annotation.nowarn import scala.collection.mutable.ListBuffer +@nowarn("msg=The syntax `x: _\\*` is no longer supported for vararg splices; use `x\\*` instead") object CompositeCancelableSuite extends SimpleTestSuite with Checkers { test("simple cancel") { val s = CompositeCancelable() @@ -144,7 +146,7 @@ object CompositeCancelableSuite extends SimpleTestSuite with Checkers { test("reset") { val seq = for (_ <- 0 until 10) yield BooleanCancelable() - val cc = CompositeCancelable(seq: _*) + val cc = CompositeCancelable(seq*) cc.reset() cc.cancel() diff --git a/monix-execution/shared/src/test/scala/monix/execution/cancelables/MultiAssignCancelableSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/cancelables/MultiAssignCancelableSuite.scala index e710c0400..3dd6f78dd 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/cancelables/MultiAssignCancelableSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/cancelables/MultiAssignCancelableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -73,12 +73,12 @@ object MultiAssignCancelableSuite extends SimpleTestSuite { val sub = BooleanCancelable() mSub := sub - mSub.clear() + val _ = mSub.clear() mSub.cancel() assert(!sub.isCanceled, "!sub.isCanceled") - mSub.clear() + val _ = mSub.clear() mSub := sub assert(sub.isCanceled, "sub.isCanceled") } diff --git a/monix-execution/shared/src/test/scala/monix/execution/cancelables/OrderedCancelableSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/cancelables/OrderedCancelableSuite.scala index 623a164c4..9e9587dbd 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/cancelables/OrderedCancelableSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/cancelables/OrderedCancelableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/test/scala/monix/execution/cancelables/RefCountCancelableSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/cancelables/RefCountCancelableSuite.scala index fd24235fa..7ff5d6cf2 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/cancelables/RefCountCancelableSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/cancelables/RefCountCancelableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/test/scala/monix/execution/cancelables/SerialCancelableSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/cancelables/SerialCancelableSuite.scala index 26caa5397..09ff92a08 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/cancelables/SerialCancelableSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/cancelables/SerialCancelableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/test/scala/monix/execution/cancelables/SingleAssignCancelableSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/cancelables/SingleAssignCancelableSuite.scala index f5116c783..85bccdfb0 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/cancelables/SingleAssignCancelableSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/cancelables/SingleAssignCancelableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -109,7 +109,7 @@ object SingleAssignCancelableSuite extends SimpleTestSuite { val b1 = Cancelable() s := b1 - intercept[IllegalStateException] { + val _ = intercept[IllegalStateException] { val b2 = Cancelable() s := b2 () @@ -124,7 +124,7 @@ object SingleAssignCancelableSuite extends SimpleTestSuite { val b1 = Cancelable() s := b1 - intercept[IllegalStateException] { + val _ = intercept[IllegalStateException] { val b2 = Cancelable() s := b2 () diff --git a/monix-execution/shared/src/test/scala/monix/execution/cancelables/StackedCancelableSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/cancelables/StackedCancelableSuite.scala index 6f25ac363..81ae187f8 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/cancelables/StackedCancelableSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/cancelables/StackedCancelableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,7 +33,7 @@ object StackedCancelableSuite extends SimpleTestSuite { var effect = 0 val initial = Cancelable(() => effect += 1) val c = StackedCancelable() - c push initial + c.push(initial) c.cancel() assertEquals(effect, 1) } @@ -43,7 +43,7 @@ object StackedCancelableSuite extends SimpleTestSuite { val initial = Cancelable(() => effect += 1) val c = StackedCancelable() c.cancel() - c push initial + c.push(initial) assertEquals(effect, 1) } @@ -55,7 +55,7 @@ object StackedCancelableSuite extends SimpleTestSuite { val c = StackedCancelable() c.push(initial1) c.push(initial2) - c.pop() + val _ = c.pop() c.cancel() assertEquals(effect, 1) @@ -145,7 +145,7 @@ object StackedCancelableSuite extends SimpleTestSuite { val d4 = Cancelable(() => effect += 20) val c2 = StackedCancelable(d3) - c2 push d4 + c2.push(d4) assertEquals(c2.popAndPushList(List(d1, d2)), d4) c2.cancel() @@ -156,7 +156,7 @@ object StackedCancelableSuite extends SimpleTestSuite { val sc = StackedCancelable() val c = BooleanCancelable() - sc.popAndPushList(List(c)) + val _ = sc.popAndPushList(List(c)) assert(!sc.isCanceled, "!sc.isCanceled") assert(!c.isCanceled, "!c.isCanceled") @@ -170,7 +170,7 @@ object StackedCancelableSuite extends SimpleTestSuite { val c = BooleanCancelable() - sc.popAndPushList(List(c)) + val _ = sc.popAndPushList(List(c)) assert(sc.isCanceled, "sc.isCanceled") assert(c.isCanceled, "c.isCanceled") } diff --git a/monix-execution/shared/src/test/scala/monix/execution/internal/MathSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/internal/MathSuite.scala index d422d32b0..0aca92857 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/internal/MathSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/internal/MathSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/test/scala/monix/execution/internal/RingBufferSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/internal/RingBufferSuite.scala index 0871235ef..31ff43497 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/internal/RingBufferSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/internal/RingBufferSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,7 +30,7 @@ object RingBufferSuite extends SimpleTestSuite { test("non-empty ring buffer") { val buffer = new RingBuffer[Integer](2) - buffer.push(0) + val _ = buffer.push(0) assertEquals(buffer.isEmpty, false) } diff --git a/monix-execution/shared/src/test/scala/monix/execution/internal/collection/ChunkedArrayQueueSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/internal/collection/ChunkedArrayQueueSuite.scala index c4518b730..859402a7e 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/internal/collection/ChunkedArrayQueueSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/internal/collection/ChunkedArrayQueueSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/test/scala/monix/execution/internal/collection/ChunkedArrayStackSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/internal/collection/ChunkedArrayStackSuite.scala index 0e6f365a0..5203febfb 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/internal/collection/ChunkedArrayStackSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/internal/collection/ChunkedArrayStackSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/test/scala/monix/execution/internal/collection/DropAllOnOverflowQueueSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/internal/collection/DropAllOnOverflowQueueSuite.scala index 0132e649e..4e845309a 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/internal/collection/DropAllOnOverflowQueueSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/internal/collection/DropAllOnOverflowQueueSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,13 +18,15 @@ package monix.execution.internal.collection import minitest.SimpleTestSuite +import scala.annotation.nowarn import scala.collection.mutable.ListBuffer +@nowarn("msg=The syntax `x: _\\*` is no longer supported for vararg splices; use `x\\*` instead") object DropAllOnOverflowQueueSuite extends SimpleTestSuite { test("should not accept null values") { val q = DropAllOnOverflowQueue[String](100) - intercept[NullPointerException] { - q.offer(null) + val _ = intercept[NullPointerException] { + val _ = q.offer(null) () } () @@ -43,13 +45,13 @@ object DropAllOnOverflowQueueSuite extends SimpleTestSuite { val q4 = DropAllOnOverflowQueue[Int](1025) assertEquals(q4.capacity, 2047) - intercept[IllegalArgumentException] { - DropAllOnOverflowQueue[Int](0) + val _ = intercept[IllegalArgumentException] { + val _ = DropAllOnOverflowQueue[Int](0) () } - intercept[IllegalArgumentException] { - DropAllOnOverflowQueue[Int](-100) + val _ = intercept[IllegalArgumentException] { + val _ = DropAllOnOverflowQueue[Int](-100) () } () @@ -91,10 +93,10 @@ object DropAllOnOverflowQueueSuite extends SimpleTestSuite { assertEquals(q.offer(0), 0) assertEquals(q.poll(), 0) - assertEquals(q.offerMany(1 to 7: _*), 0) + assertEquals(q.offerMany((1 to 7)*), 0) assertEquals(q.offer(8), 7) - assertEquals(q.offerMany(9 to 14: _*), 0) + assertEquals(q.offerMany((9 to 14)*), 0) val buffer = ListBuffer.empty[Int] assertEquals(q.drainToBuffer(buffer, 3), 3) @@ -103,7 +105,7 @@ object DropAllOnOverflowQueueSuite extends SimpleTestSuite { assertEquals(q.drainToArray(array), 4) assertEquals(array.toList.take(4), List(11, 12, 13, 14)) - assertEquals(q.offerMany(15 until 29: _*), 7) + assertEquals(q.offerMany((15 until 29)*), 7) assertEquals(q.drainToArray(array), 7) assertEquals(array.toList, (22 until 29).toList) @@ -156,27 +158,27 @@ object DropAllOnOverflowQueueSuite extends SimpleTestSuite { assert(q.isEmpty) assert(!q.nonEmpty) - intercept[NoSuchElementException] { q.head; () } + val _ = intercept[NoSuchElementException] { val _ = q.head; () } assertEquals(q.headOption, None) - q.offer(1) + val _ = q.offer(1) assert(!q.isEmpty) assert(q.nonEmpty) assertEquals(q.head, 1) assertEquals(q.headOption, Some(1)) - q.poll() + val _ = q.poll() assert(q.isEmpty) assert(!q.nonEmpty) - intercept[NoSuchElementException] { q.head; () } + val _ = intercept[NoSuchElementException] { val _ = q.head; () } assertEquals(q.headOption, None) } test("iterable") { val q = DropAllOnOverflowQueue[Int](127) - q.offerMany(0 until 200: _*) + val _ = q.offerMany((0 until 200)*) assertEquals(q.toList, 127 until 200) } @@ -184,15 +186,15 @@ object DropAllOnOverflowQueueSuite extends SimpleTestSuite { val q = DropAllOnOverflowQueue[Int](1) assert(q.isEmpty) - q.offerMany(0 until 10: _*) + val _ = q.offerMany((0 until 10)*) assertEquals(q.head, 9) assertEquals(q.length, 1) - q.offerMany(10 until 20: _*) + val _ = q.offerMany((10 until 20)*) assertEquals(q.head, 19) assertEquals(q.length, 1) - q.offerMany(20 until 30: _*) + val _ = q.offerMany((20 until 30)*) assertEquals(q.head, 29) assertEquals(q.length, 1) assertEquals(q.poll(), 29) @@ -201,7 +203,7 @@ object DropAllOnOverflowQueueSuite extends SimpleTestSuite { test("should iterate with fixed capacity") { val q = DropAllOnOverflowQueue[Int](10) - q.offerMany(0 until 15: _*) + val _ = q.offerMany((0 until 15)*) val list1 = q.iterator(exactSize = false).toList assertEquals(list1.length, 15) @@ -224,7 +226,7 @@ object DropAllOnOverflowQueueSuite extends SimpleTestSuite { test("should box") { val q = DropAllOnOverflowQueue.boxed[Int](10) - q.offerMany(0 until 15: _*) + val _ = q.offerMany((0 until 15)*) assertEquals(q.toList, (0 until 15).toList) } } diff --git a/monix-execution/shared/src/test/scala/monix/execution/internal/collection/DropHeadOnOverflowQueueSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/internal/collection/DropHeadOnOverflowQueueSuite.scala index f913308b8..d3eb8c1e4 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/internal/collection/DropHeadOnOverflowQueueSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/internal/collection/DropHeadOnOverflowQueueSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,13 +18,15 @@ package monix.execution.internal.collection import minitest.SimpleTestSuite +import scala.annotation.nowarn import scala.collection.mutable.ListBuffer +@nowarn("msg=The syntax `x: _\\*` is no longer supported for vararg splices; use `x\\*` instead") object DropHeadOnOverflowQueueSuite extends SimpleTestSuite { test("should not accept null values") { val q = DropAllOnOverflowQueue[String](100) - intercept[NullPointerException] { - q.offer(null) + val _ = intercept[NullPointerException] { + val _ = q.offer(null) () } () @@ -43,13 +45,13 @@ object DropHeadOnOverflowQueueSuite extends SimpleTestSuite { val q4 = DropHeadOnOverflowQueue[Int](1025) assertEquals(q4.capacity, 2047) - intercept[IllegalArgumentException] { - DropHeadOnOverflowQueue[Int](0) + val _ = intercept[IllegalArgumentException] { + val _ = DropHeadOnOverflowQueue[Int](0) () } - intercept[IllegalArgumentException] { - DropHeadOnOverflowQueue[Int](-100) + val _ = intercept[IllegalArgumentException] { + val _ = DropHeadOnOverflowQueue[Int](-100) () } () @@ -86,12 +88,12 @@ object DropHeadOnOverflowQueueSuite extends SimpleTestSuite { val q = DropHeadOnOverflowQueue[Int](7) assertEquals(q.capacity, 7) - assertEquals(q.poll(), null) + assertEquals(q.poll(): Any, null) assertEquals(q.offer(0), 0) assertEquals(q.poll(), 0) - assertEquals(q.offerMany(1 to 7: _*), 0) + assertEquals(q.offerMany((1 to 7)*), 0) assertEquals(q.offer(8), 1) assertEquals(q.offer(9), 1) @@ -108,7 +110,7 @@ object DropHeadOnOverflowQueueSuite extends SimpleTestSuite { assertEquals(q.drainToArray(array), 4) assertEquals(array.toList.take(4), List(11, 12, 13, 14)) - assertEquals(q.offerMany(15 until 29: _*), 7) + assertEquals(q.offerMany((15 until 29)*), 7) assertEquals(q.drainToArray(array), 7) assertEquals(array.toList, (22 until 29).toList) @@ -155,21 +157,21 @@ object DropHeadOnOverflowQueueSuite extends SimpleTestSuite { assert(q.isEmpty) assert(!q.nonEmpty) - intercept[NoSuchElementException] { q.head; () } + val _ = intercept[NoSuchElementException] { val _ = q.head; () } assertEquals(q.headOption, None) - q.offer(1) + val _ = q.offer(1) assert(!q.isEmpty) assert(q.nonEmpty) assertEquals(q.head, 1) assertEquals(q.headOption, Some(1)) - q.poll() + val _ = q.poll() assert(q.isEmpty) assert(!q.nonEmpty) - intercept[NoSuchElementException] { q.head; () } + val _ = intercept[NoSuchElementException] { val _ = q.head; () } assertEquals(q.headOption, None) } @@ -177,7 +179,7 @@ object DropHeadOnOverflowQueueSuite extends SimpleTestSuite { val q = DropHeadOnOverflowQueue[Int](127) assertEquals(q.capacity, 127) - q.offerMany(0 until 200: _*) + val _ = q.offerMany((0 until 200)*) assertEquals(q.toList, 73 until 200) } @@ -185,15 +187,15 @@ object DropHeadOnOverflowQueueSuite extends SimpleTestSuite { val q = DropHeadOnOverflowQueue[Int](1) assert(q.isEmpty) - q.offerMany(0 until 10: _*) + val _ = q.offerMany((0 until 10)*) assertEquals(q.head, 9) assertEquals(q.length, 1) - q.offerMany(10 until 20: _*) + val _ = q.offerMany((10 until 20)*) assertEquals(q.head, 19) assertEquals(q.length, 1) - q.offerMany(20 until 30: _*) + val _ = q.offerMany((20 until 30)*) assertEquals(q.head, 29) assertEquals(q.length, 1) assertEquals(q.poll(), 29) @@ -202,7 +204,7 @@ object DropHeadOnOverflowQueueSuite extends SimpleTestSuite { test("should iterate with fixed capacity") { val q = DropHeadOnOverflowQueue[Int](10) - q.offerMany(0 to 200: _*) + val _ = q.offerMany((0 to 200)*) val list1 = q.iterator(exactSize = false).toList assertEquals(list1.length, 15) @@ -225,7 +227,7 @@ object DropHeadOnOverflowQueueSuite extends SimpleTestSuite { test("should box") { val q = DropHeadOnOverflowQueue.boxed[Int](10) - q.offerMany(0 until 15: _*) + val _ = q.offerMany((0 until 15)*) assertEquals(q.toList, (0 until 15).toList) } } diff --git a/monix-execution/shared/src/test/scala/monix/execution/misc/CanBindLocalsSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/misc/CanBindLocalsSuite.scala index 4a2f1ce42..3e4cc0604 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/misc/CanBindLocalsSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/misc/CanBindLocalsSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/test/scala/monix/execution/misc/LocalSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/misc/LocalSuite.scala index 4c64f4557..91ff35b19 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/misc/LocalSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/misc/LocalSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.execution.misc import cats.Eval import minitest.SimpleTestSuite -import monix.execution.schedulers.{TestScheduler, TracingScheduler} +import monix.execution.schedulers.{ TestScheduler, TracingScheduler } import monix.execution.misc.CanBindLocals.Implicits.synchronousAsDefault import scala.concurrent.Future import scala.util.Success diff --git a/monix-execution/shared/src/test/scala/monix/execution/misc/ThreadLocalSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/misc/ThreadLocalSuite.scala index 6b567a286..88400952f 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/misc/ThreadLocalSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/misc/ThreadLocalSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/test/scala/monix/execution/rstreams/SingleAssignSubscriptionSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/rstreams/SingleAssignSubscriptionSuite.scala index 685891a7c..a55281575 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/rstreams/SingleAssignSubscriptionSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/rstreams/SingleAssignSubscriptionSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-execution/shared/src/test/scala/monix/execution/rstreams/SubscriptionSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/rstreams/SubscriptionSuite.scala index 151ba5ba0..59825ba31 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/rstreams/SubscriptionSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/rstreams/SubscriptionSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.execution.rstreams import minitest.SimpleTestSuite -import org.reactivestreams.{Subscription => RSubscription} +import org.reactivestreams.{ Subscription => RSubscription } object SubscriptionSuite extends SimpleTestSuite { test("wraps any subscription reference") { diff --git a/monix-execution/shared/src/test/scala/monix/execution/schedulers/ExecutionModelSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/schedulers/ExecutionModelSuite.scala index 786069d17..44ab88110 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/schedulers/ExecutionModelSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/schedulers/ExecutionModelSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.execution.schedulers import minitest.SimpleTestSuite -import monix.execution.ExecutionModel.{AlwaysAsyncExecution, BatchedExecution, SynchronousExecution} +import monix.execution.ExecutionModel.{ AlwaysAsyncExecution, BatchedExecution, SynchronousExecution } object ExecutionModelSuite extends SimpleTestSuite { test("SynchronousExecution") { @@ -59,7 +59,7 @@ object ExecutionModelSuite extends SimpleTestSuite { assert(em.recommendedBatchSize >= i) var index = 1 - for (j <- 1 until em.recommendedBatchSize * 3) { + for (_ <- 1 until em.recommendedBatchSize * 3) { index = em.nextFrameIndex(index) assert(index >= 0 && index < em.recommendedBatchSize) } diff --git a/monix-execution/shared/src/test/scala/monix/execution/schedulers/ReferenceSchedulerSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/schedulers/ReferenceSchedulerSuite.scala index 2eee90bd2..f7f59e978 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/schedulers/ReferenceSchedulerSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/schedulers/ReferenceSchedulerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,8 +19,8 @@ package monix.execution.schedulers import java.util.concurrent.TimeUnit import minitest.SimpleTestSuite -import monix.execution.{Cancelable, Features} -import monix.execution.ExecutionModel.{AlwaysAsyncExecution, SynchronousExecution} +import monix.execution.{ Cancelable, Features } +import monix.execution.ExecutionModel.{ AlwaysAsyncExecution, SynchronousExecution } import scala.concurrent.duration._ object ReferenceSchedulerSuite extends SimpleTestSuite { @@ -126,7 +126,7 @@ object ReferenceSchedulerSuite extends SimpleTestSuite { val ws = s.withExecutionModel(AlwaysAsyncExecution) var effect = 0 - ws.scheduleOnce(1.second) { effect += 1 } + val _ = ws.scheduleOnce(1.second) { effect += 1 } assertEquals(effect, 0) s.tick(1.second) diff --git a/monix-execution/shared/src/test/scala/monix/execution/schedulers/TestSchedulerSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/schedulers/TestSchedulerSuite.scala index f2ab77b28..a5c69d04a 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/schedulers/TestSchedulerSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/schedulers/TestSchedulerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.execution.schedulers -import java.util.concurrent.{TimeUnit, TimeoutException} +import java.util.concurrent.{ TimeUnit, TimeoutException } import minitest.TestSuite import monix.execution.Scheduler @@ -25,8 +25,8 @@ import monix.execution.exceptions.DummyException import monix.execution.internal.Platform import scala.concurrent.duration._ -import scala.concurrent.{Future, Promise} -import scala.util.{Success, Try} +import scala.concurrent.{ Future, Promise } +import scala.util.{ Success, Try } object TestSchedulerSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() @@ -76,35 +76,39 @@ object TestSchedulerSuite extends TestSuite[TestScheduler] { var firstBatch = 0 var secondBatch = 0 - s.scheduleOnce( + val _ = s.scheduleOnce( 10, TimeUnit.SECONDS, action { firstBatch += 1 s.execute(action { firstBatch += 1 }) - s.scheduleOnce( + val _ = s.scheduleOnce( 10, TimeUnit.SECONDS, action { firstBatch += 1 - }) + } + ) () - }) + } + ) - s.scheduleOnce( + val _ = s.scheduleOnce( 20, TimeUnit.SECONDS, action { secondBatch += 1 s.execute(action { secondBatch += 1 }) - s.scheduleOnce( + val _ = s.scheduleOnce( 10, TimeUnit.SECONDS, action { secondBatch += 1 - }) + } + ) () - }) + } + ) s.tick() assert(firstBatch == 0 && secondBatch == 0) @@ -135,7 +139,7 @@ object TestSchedulerSuite extends TestSuite[TestScheduler] { assertEquals(f.value, None) s.tick(10.seconds) - intercept[TimeoutException] { f.value.get.get; () } + val _ = intercept[TimeoutException] { val _ = f.value.get.get; () } () } @@ -163,7 +167,7 @@ object TestSchedulerSuite extends TestSuite[TestScheduler] { test("complicated scheduling, test 1") { implicit s => var counter = 0 - delayedResult(50.millis, 300.millis) { + val _ = delayedResult(50.millis, 300.millis) { counter += 1 delayedResult(50.millis, 300.millis) { @@ -192,7 +196,7 @@ object TestSchedulerSuite extends TestSuite[TestScheduler] { test("complicated scheduling, test 2") { implicit s => var counter = 0 - delayedResult(50.millis, 300.millis) { + val _ = delayedResult(50.millis, 300.millis) { counter += 1 delayedResult(50.millis, 300.millis) { @@ -275,7 +279,7 @@ object TestSchedulerSuite extends TestSuite[TestScheduler] { assertEquals(s.state.lastReportedError, ex) // Other runnables have been rescheduled async - s.tickOne() + val _ = s.tickOne() assertEquals(effect, 1 + 2 + 3) } @@ -306,7 +310,7 @@ object TestSchedulerSuite extends TestSuite[TestScheduler] { } assertEquals(effect, 0) - s.tickOne() + val _ = s.tickOne() assertEquals(effect, 3) } @@ -329,19 +333,19 @@ object TestSchedulerSuite extends TestSuite[TestScheduler] { } def action(f: => Unit): Runnable = - new Runnable { def run() = f } + () => f def delayedResult[A](delay: FiniteDuration, timeout: FiniteDuration)(r: => A)(implicit s: Scheduler) = { val f1 = { val p = Promise[A]() - s.scheduleOnce(delay.length, delay.unit, action { p.success(r); () }) + val _ = s.scheduleOnce(delay.length, delay.unit, action { p.success(r); () }) p.future } // catching the exception here, for non-useless stack traces val err = Try(throw new TimeoutException) val promise = Promise[A]() - val task = s.scheduleOnce(timeout.length, timeout.unit, action { promise.tryComplete(err); () }) + val task = s.scheduleOnce(timeout.length, timeout.unit, action { val _ = promise.tryComplete(err); () }) f1.onComplete { result => // canceling task to prevent waisted CPU resources and memory leaks diff --git a/monix-execution/shared/src/test/scala/monix/execution/schedulers/TracingSchedulerSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/schedulers/TracingSchedulerSuite.scala index aa6de2214..52e83b570 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/schedulers/TracingSchedulerSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/schedulers/TracingSchedulerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,11 +23,11 @@ import minitest.SimpleTestSuite import monix.execution.ExecutionModel.AlwaysAsyncExecution import monix.execution.misc.Local import monix.execution.FutureUtils.extensions._ -import monix.execution.{Cancelable, Scheduler} +import monix.execution.{ Cancelable, Scheduler } import monix.execution.cancelables.SingleAssignCancelable import monix.execution.exceptions.DummyException -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.concurrent.duration._ import scala.util.Success @@ -128,8 +128,12 @@ object TracingSchedulerSuite extends SimpleTestSuite { val p = Promise[Int]() val sub = SingleAssignCancelable() - sub := schedule(traced, 1, 1, TimeUnit.SECONDS, new Runnable { - def run(): Unit = { + sub := schedule( + traced, + 1, + 1, + TimeUnit.SECONDS, + () => { sum += local1.get + local2.get count += 1 if (count >= 3) { @@ -137,7 +141,7 @@ object TracingSchedulerSuite extends SimpleTestSuite { sub.cancel() } } - }) + ) p.future } diff --git a/monix-execution/shared/src/test/scala/monix/execution/schedulers/TrampolineSchedulerSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/schedulers/TrampolineSchedulerSuite.scala index b2c4b801a..1d5591901 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/schedulers/TrampolineSchedulerSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/schedulers/TrampolineSchedulerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.execution.schedulers import minitest.TestSuite import monix.execution.ExecutionModel.AlwaysAsyncExecution -import monix.execution.ExecutionModel.{Default => DefaultExecModel} +import monix.execution.ExecutionModel.{ Default => DefaultExecModel } import monix.execution.Scheduler import monix.execution.internal.Platform import scala.concurrent.Promise @@ -78,7 +78,7 @@ object TrampolineSchedulerSuite extends TestSuite[(Scheduler, TestScheduler)] { import concurrent.duration._ val p = Promise[Unit]() val startAt = s.clockRealTime(MILLISECONDS) - s.scheduleOnce(100.millis) { p.success(()); () } + val _ = s.scheduleOnce(100.millis) { p.success(()); () } u.tick(100.millis) val duration = s.clockRealTime(MILLISECONDS) - startAt @@ -156,7 +156,7 @@ object TrampolineSchedulerSuite extends TestSuite[(Scheduler, TestScheduler)] { } assertEquals(effect, 16) - u.tickOne() + val _ = u.tickOne() assertEquals(effect, 56) } } diff --git a/monix-execution/shared/src/test/scala/monix/execution/schedulers/UncaughtExceptionReporterSuite.scala b/monix-execution/shared/src/test/scala/monix/execution/schedulers/UncaughtExceptionReporterSuite.scala index 5def437c8..cad338cb2 100644 --- a/monix-execution/shared/src/test/scala/monix/execution/schedulers/UncaughtExceptionReporterSuite.scala +++ b/monix-execution/shared/src/test/scala/monix/execution/schedulers/UncaughtExceptionReporterSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,23 +17,21 @@ package monix.execution.schedulers -import scala.concurrent.{ExecutionContext, Promise} +import scala.concurrent.{ ExecutionContext, Promise } import scala.concurrent.duration._ import minitest.TestSuite -import monix.execution.{ExecutionModel, FutureUtils, Scheduler, UncaughtExceptionReporter} +import monix.execution.{ ExecutionModel, FutureUtils, Scheduler, UncaughtExceptionReporter } class UncaughtExceptionReporterBaseSuite extends TestSuite[Promise[Throwable]] { protected val immediateEC = TrampolineExecutionContext.immediate object Dummy extends Throwable - private[this] val throwRunnable: Runnable = new Runnable { - def run(): Unit = throw Dummy - } + private val throwRunnable: Runnable = () => throw Dummy def setup() = Promise[Throwable]() def tearDown(env: Promise[Throwable]): Unit = () - private[this] def reporter(p: Promise[Throwable]) = UncaughtExceptionReporter { t => + private def reporter(p: Promise[Throwable]) = UncaughtExceptionReporter { t => p.success(t) () } diff --git a/monix-java/src/main/scala/monix/java8/eval/package.scala b/monix-java/src/main/scala/monix/java8/eval/package.scala index 848e3639b..4fb2a4ee2 100644 --- a/monix-java/src/main/scala/monix/java8/eval/package.scala +++ b/monix-java/src/main/scala/monix/java8/eval/package.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,11 @@ package monix.java8 -import java.util.concurrent.{CancellationException, CompletableFuture, CompletionException} +import java.util.concurrent.{ CancellationException, CompletableFuture, CompletionException } import java.util.function.BiFunction import monix.eval.Task -import monix.execution.{Cancelable, Scheduler} -import scala.util.{Failure, Success} +import monix.execution.{ Cancelable, Scheduler } +import scala.util.{ Failure, Success } /** * DEPRECATED — switch to Scala 2.12+ and [[monix.eval.Task.from Task.from]]. @@ -34,7 +34,7 @@ package object eval { /** * DEPRECATED — switch to Scala 2.12+ and [[monix.eval.Task.from Task.from]]. */ - @deprecated("Switch to Scala 2.12+ and Task.from", "3.0.0") + @deprecated("Switch to Scala 2.12+ and Task.from", "3.0.2") def fromCompletableFuture[A](cf: CompletableFuture[A]): Task[A] = { // $COVERAGE-OFF$ convert(cf) @@ -44,7 +44,7 @@ package object eval { /** * DEPRECATED — switch to Scala 2.12+ and [[monix.eval.Task.from Task.from]]. */ - @deprecated("Switch to Scala 2.12+ and Task.from", "3.0.0") + @deprecated("Switch to Scala 2.12+ and Task.from", "3.0.2") def deferCompletableFutureAction[A](f: Scheduler => CompletableFuture[A]): Task[A] = { // $COVERAGE-OFF$ Task.deferAction { sc => diff --git a/monix-java/src/main/scala/monix/java8/execution/package.scala b/monix-java/src/main/scala/monix/java8/execution/package.scala index 0699d4dd6..4b019f10f 100644 --- a/monix-java/src/main/scala/monix/java8/execution/package.scala +++ b/monix-java/src/main/scala/monix/java8/execution/package.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,11 @@ package monix.java8 -import java.util.concurrent.{CancellationException, CompletableFuture, CompletionException} +import java.util.concurrent.{ CancellationException, CompletableFuture, CompletionException } import java.util.function.BiFunction -import monix.execution.{Cancelable, CancelableFuture} -import scala.concurrent.{ExecutionContext, Future} -import scala.util.{Failure, Success} +import monix.execution.{ Cancelable, CancelableFuture } +import scala.concurrent.{ ExecutionContext, Future } +import scala.util.{ Failure, Success } /** * DEPRECATED — switch to Scala 2.12+ and [[monix.execution.FutureUtils]]. @@ -36,7 +36,7 @@ package object execution { * DEPRECATED — switch to Scala 2.12+ and * [[monix.execution.CancelableFuture.fromJavaCompletable CancelableFuture.fromJavaCompletable]]. */ - @deprecated("Switch to Scala 2.12+ and CancelableFuture.fromJavaCompletable", "3.0.0") + @deprecated("Switch to Scala 2.12+ and CancelableFuture.fromJavaCompletable", "3.0.2") def asScala(implicit ec: ExecutionContext): CancelableFuture[A] = { // $COVERAGE-OFF$ CancelableFuture.async(cb => { @@ -69,7 +69,7 @@ package object execution { * DEPRECATED — switch to Scala 2.12+ and * [[monix.execution.FutureUtils.toJavaCompletable FutureUtils.toJavaCompletable]]. */ - @deprecated("Switch to Scala 2.12+ and FutureUtils.toJavaCompletable", "3.0.0") + @deprecated("Switch to Scala 2.12+ and FutureUtils.toJavaCompletable", "3.0.2") def asJava(implicit ec: ExecutionContext): CompletableFuture[A] = { // $COVERAGE-OFF$ val cf = new CompletableFuture[A]() diff --git a/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/AbstractBackPressuredBufferedSubscriber.scala b/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/AbstractBackPressuredBufferedSubscriber.scala index 4f75fa5dd..71ff76b2f 100644 --- a/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/AbstractBackPressuredBufferedSubscriber.scala +++ b/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/AbstractBackPressuredBufferedSubscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,16 +17,17 @@ package monix.reactive.observers.buffers -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import monix.execution.internal.collection.JSArrayQueue import monix.execution.internal.math.nextPowerOf2 import scala.util.control.NonFatal -import monix.reactive.observers.{BufferedSubscriber, Subscriber} +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } -import scala.concurrent.{Future, Promise} -import scala.util.{Failure, Success} +import scala.concurrent.{ Future, Promise } +import scala.util.{ Failure, Success } /** Shared internals between [[BackPressuredBufferedSubscriber]] and * [[BatchedBufferedSubscriber]]. @@ -35,17 +36,17 @@ private[observers] abstract class AbstractBackPressuredBufferedSubscriber[A, R]( extends BufferedSubscriber[A] { require(_size > 0, "bufferSize must be a strictly positive number") - private[this] val bufferSize = nextPowerOf2(_size) + private val bufferSize = nextPowerOf2(_size) - private[this] val em = out.scheduler.executionModel + private val em = out.scheduler.executionModel implicit final val scheduler: Scheduler = out.scheduler - private[this] var upstreamIsComplete = false - private[this] var downstreamIsComplete = false - private[this] var errorThrown: Throwable = null - private[this] var isLoopActive = false - private[this] var backPressured: Promise[Ack] = null - private[this] var lastIterationAck: Future[Ack] = Continue + private var upstreamIsComplete = false + private var downstreamIsComplete = false + private var errorThrown: Throwable = null + private var isLoopActive = false + private var backPressured: Promise[Ack] = null + private var lastIterationAck: Future[Ack] = Continue protected val queue = JSArrayQueue.unbounded[A] final def onNext(elem: A): Future[Ack] = { @@ -58,17 +59,17 @@ private[observers] abstract class AbstractBackPressuredBufferedSubscriber[A, R]( backPressured match { case null => if (queue.length < bufferSize) { - queue.offer(elem) + val _ = queue.offer(elem) pushToConsumer() Continue } else { backPressured = Promise[Ack]() - queue.offer(elem) + val _ = queue.offer(elem) pushToConsumer() backPressured.future } case promise => - queue.offer(elem) + val _ = queue.offer(elem) pushToConsumer() promise.future } @@ -97,7 +98,7 @@ private[observers] abstract class AbstractBackPressuredBufferedSubscriber[A, R]( protected def fetchNext(): R - private[this] val consumerRunLoop = new Runnable { + private val consumerRunLoop = new Runnable { def run(): Unit = fastLoop(lastIterationAck, 0) private final def signalNext(next: R): Future[Ack] = @@ -123,7 +124,7 @@ private[observers] abstract class AbstractBackPressuredBufferedSubscriber[A, R]( Stop } - private def downstreamSignalComplete(ex: Throwable = null): Unit = { + private def downstreamSignalComplete(ex: Throwable /* | Null*/ ): Unit = { downstreamIsComplete = true try { if (ex != null) out.onError(ex) @@ -169,51 +170,52 @@ private[observers] abstract class AbstractBackPressuredBufferedSubscriber[A, R]( var streamErrors = true try while (isLoopActive && !downstreamIsComplete) { - val next = fetchNext() - - if (next != null) { - if (nextIndex > 0 || isFirstIteration) { - isFirstIteration = false - - ack match { - case Continue => - ack = signalNext(next) - if (ack == Stop) { + val next = fetchNext() + + if (next != null) { + if (nextIndex > 0 || isFirstIteration) { + isFirstIteration = false + + ack match { + case Continue => + ack = signalNext(next) + if (ack == Stop) { + stopStreaming() + return + } else { + val isSync = ack == Continue + nextIndex = if (isSync) em.nextFrameIndex(nextIndex) else 0 + } + + case Stop => stopStreaming() return - } else { - val isSync = ack == Continue - nextIndex = if (isSync) em.nextFrameIndex(nextIndex) else 0 - } - - case Stop => - stopStreaming() - return - - case _ => - goAsync(next, ack) - return + + case _ => + goAsync(next, ack) + return + } + } else { + goAsync(next, ack) + return } } else { - goAsync(next, ack) - return - } - } else { - // Ending loop - if (backPressured != null) { - backPressured.success(if (upstreamIsComplete) Stop else Continue) - backPressured = null - } + // Ending loop + if (backPressured != null) { + backPressured.success(if (upstreamIsComplete) Stop else Continue) + backPressured = null + } - streamErrors = false - if (upstreamIsComplete) - downstreamSignalComplete(errorThrown) + streamErrors = false + if (upstreamIsComplete) + downstreamSignalComplete(errorThrown) - lastIterationAck = ack - isLoopActive = false - return + lastIterationAck = ack + isLoopActive = false + return + } } - } catch { + catch { case ex if NonFatal(ex) => if (streamErrors) downstreamSignalComplete(ex) else scheduler.reportFailure(ex) diff --git a/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/BackPressuredBufferedSubscriber.scala b/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/BackPressuredBufferedSubscriber.scala index 4d8f31914..cb3247bf7 100644 --- a/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/BackPressuredBufferedSubscriber.scala +++ b/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/BackPressuredBufferedSubscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/BatchedBufferedSubscriber.scala b/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/BatchedBufferedSubscriber.scala index ea6ee5dc8..b34b59102 100644 --- a/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/BatchedBufferedSubscriber.scala +++ b/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/BatchedBufferedSubscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,7 +32,7 @@ private[monix] final class BatchedBufferedSubscriber[A] private (out: Subscriber if (queue.isEmpty) null else { val buffer = ListBuffer.empty[A] - queue.drainToBuffer(buffer, Platform.recommendedBatchSize) + val _ = queue.drainToBuffer(buffer, Platform.recommendedBatchSize) buffer.toList } } diff --git a/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/BuildersImpl.scala b/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/BuildersImpl.scala index 6597572b1..991e12360 100644 --- a/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/BuildersImpl.scala +++ b/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/BuildersImpl.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,13 +21,15 @@ import monix.execution.ChannelType import monix.execution.ChannelType.MultiProducer import monix.reactive.OverflowStrategy import monix.reactive.OverflowStrategy._ -import monix.reactive.observers.{BufferedSubscriber, Subscriber} +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } +import scala.annotation.unused private[observers] trait BuildersImpl { self: BufferedSubscriber.type => def apply[A]( subscriber: Subscriber[A], bufferPolicy: OverflowStrategy[A], - producerType: ChannelType.ProducerSide = MultiProducer): Subscriber[A] = { + @unused producerType: ChannelType.ProducerSide = MultiProducer + ): Subscriber[A] = { bufferPolicy match { case Unbounded => SyncBufferedSubscriber.unbounded(subscriber) @@ -56,7 +58,8 @@ private[observers] trait BuildersImpl { self: BufferedSubscriber.type => def synchronous[A]( subscriber: Subscriber[A], bufferPolicy: OverflowStrategy.Synchronous[A], - producerType: ChannelType.ProducerSide = MultiProducer): Subscriber.Sync[A] = { + @unused producerType: ChannelType.ProducerSide = MultiProducer + ): Subscriber.Sync[A] = { bufferPolicy match { case Unbounded => SyncBufferedSubscriber.unbounded(subscriber) @@ -83,6 +86,7 @@ private[observers] trait BuildersImpl { self: BufferedSubscriber.type => def batched[A]( underlying: Subscriber[List[A]], bufferSize: Int, - producerType: ChannelType.ProducerSide = MultiProducer): Subscriber[A] = + @unused producerType: ChannelType.ProducerSide = MultiProducer + ): Subscriber[A] = BatchedBufferedSubscriber(underlying, bufferSize) } diff --git a/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/SyncBufferedSubscriber.scala b/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/SyncBufferedSubscriber.scala index abdcb06e3..2f8e5f407 100644 --- a/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/SyncBufferedSubscriber.scala +++ b/monix-reactive/js/src/main/scala/monix/reactive/observers/buffers/SyncBufferedSubscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,16 +18,17 @@ package monix.reactive.observers.buffers import monix.eval.Coeval -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} -import monix.execution.internal.collection.{JSArrayQueue, _} +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler +import monix.execution.internal.collection.{ JSArrayQueue, _ } import scala.util.control.NonFatal import monix.execution.exceptions.BufferOverflowException -import monix.reactive.observers.{BufferedSubscriber, Subscriber} +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } import scala.concurrent.Future -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } /** A [[BufferedSubscriber]] implementation for the * [[monix.reactive.OverflowStrategy.DropNew DropNew]] overflow strategy. @@ -35,24 +36,24 @@ import scala.util.{Failure, Success} private[observers] final class SyncBufferedSubscriber[-A] private ( out: Subscriber[A], queue: EvictingQueue[A], - onOverflow: Long => Coeval[Option[A]] = null) - extends BufferedSubscriber[A] with Subscriber.Sync[A] { + onOverflow: Long => Coeval[Option[A]] /*| Null*/, +) extends BufferedSubscriber[A] with Subscriber.Sync[A] { implicit val scheduler: Scheduler = out.scheduler // to be modified only in onError, before upstreamIsComplete - private[this] var errorThrown: Throwable = _ + private var errorThrown: Throwable = null.asInstanceOf[Throwable] // to be modified only in onError / onComplete - private[this] var upstreamIsComplete = false + private var upstreamIsComplete = false // to be modified only by consumer - private[this] var downstreamIsComplete = false + private var downstreamIsComplete = false // represents an indicator that there's a loop in progress - private[this] var isLoopActive = false + private var isLoopActive = false // events being dropped - private[this] var droppedCount = 0L + private var droppedCount = 0L // last acknowledgement received by consumer loop - private[this] var lastIterationAck: Future[Ack] = Continue + private var lastIterationAck: Future[Ack] = Continue // Used on the consumer side to split big synchronous workloads in batches - private[this] val em = scheduler.executionModel + private val em = scheduler.executionModel def onNext(elem: A): Ack = { if (!upstreamIsComplete && !downstreamIsComplete) { @@ -94,7 +95,7 @@ private[observers] final class SyncBufferedSubscriber[-A] private ( scheduler.execute(consumerRunLoop) } - private[this] val consumerRunLoop = new Runnable { + private val consumerRunLoop = new Runnable { def run(): Unit = { fastLoop(lastIterationAck, 0) } @@ -122,7 +123,7 @@ private[observers] final class SyncBufferedSubscriber[-A] private ( Stop } - private def downstreamSignalComplete(ex: Throwable = null): Unit = { + private def downstreamSignalComplete(ex: Throwable /* | Null*/ ): Unit = { downstreamIsComplete = true try { if (ex != null) out.onError(ex) @@ -257,11 +258,15 @@ private[monix] object SyncBufferedSubscriber { */ def bounded[A](underlying: Subscriber[A], bufferSize: Int): Subscriber.Sync[A] = { require(bufferSize > 1, "bufferSize must be strictly higher than 1") - val buffer = JSArrayQueue.bounded[A](bufferSize, _ => { - BufferOverflowException( - s"Downstream observer is too slow, buffer over capacity with a " + - s"specified buffer size of $bufferSize") - }) + val buffer = JSArrayQueue.bounded[A]( + bufferSize, + _ => { + BufferOverflowException( + s"Downstream observer is too slow, buffer over capacity with a " + + s"specified buffer size of $bufferSize" + ) + } + ) new SyncBufferedSubscriber[A](underlying, buffer, null) } @@ -285,7 +290,8 @@ private[monix] object SyncBufferedSubscriber { def dropNewAndSignal[A]( underlying: Subscriber[A], bufferSize: Int, - onOverflow: Long => Coeval[Option[A]]): Subscriber.Sync[A] = { + onOverflow: Long => Coeval[Option[A]] + ): Subscriber.Sync[A] = { require(bufferSize > 1, "bufferSize must be strictly higher than 1") val buffer = JSArrayQueue.bounded[A](bufferSize) new SyncBufferedSubscriber[A](underlying, buffer, onOverflow) @@ -311,7 +317,8 @@ private[monix] object SyncBufferedSubscriber { def dropOldAndSignal[A]( underlying: Subscriber[A], bufferSize: Int, - onOverflow: Long => Coeval[Option[A]]): Subscriber.Sync[A] = { + onOverflow: Long => Coeval[Option[A]] + ): Subscriber.Sync[A] = { require(bufferSize > 1, "bufferSize must be strictly higher than 1") val buffer = DropHeadOnOverflowQueue[AnyRef](bufferSize).asInstanceOf[EvictingQueue[A]] new SyncBufferedSubscriber[A](underlying, buffer, onOverflow) @@ -337,7 +344,8 @@ private[monix] object SyncBufferedSubscriber { def clearBufferAndSignal[A]( underlying: Subscriber[A], bufferSize: Int, - onOverflow: Long => Coeval[Option[A]]): Subscriber.Sync[A] = { + onOverflow: Long => Coeval[Option[A]] + ): Subscriber.Sync[A] = { require(bufferSize > 1, "bufferSize must be strictly higher than 1") val buffer = DropAllOnOverflowQueue[AnyRef](bufferSize).asInstanceOf[EvictingQueue[A]] new SyncBufferedSubscriber[A](underlying, buffer, onOverflow) diff --git a/monix-reactive/jvm/src/main/java/monix/reactive/observers/buffers/CommonBufferMembers.java b/monix-reactive/jvm/src/main/java/monix/reactive/observers/buffers/CommonBufferMembers.java index bafe7ce25..3d448e702 100644 --- a/monix-reactive/jvm/src/main/java/monix/reactive/observers/buffers/CommonBufferMembers.java +++ b/monix-reactive/jvm/src/main/java/monix/reactive/observers/buffers/CommonBufferMembers.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/jvm/src/main/scala/monix/reactive/compression/CompressionException.scala b/monix-reactive/jvm/src/main/scala/monix/reactive/compression/CompressionException.scala index ff56034e6..28a574658 100644 --- a/monix-reactive/jvm/src/main/scala/monix/reactive/compression/CompressionException.scala +++ b/monix-reactive/jvm/src/main/scala/monix/reactive/compression/CompressionException.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/jvm/src/main/scala/monix/reactive/compression/CompressionParameters.scala b/monix-reactive/jvm/src/main/scala/monix/reactive/compression/CompressionParameters.scala index 6d0947560..a53fb13bc 100644 --- a/monix-reactive/jvm/src/main/scala/monix/reactive/compression/CompressionParameters.scala +++ b/monix-reactive/jvm/src/main/scala/monix/reactive/compression/CompressionParameters.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/Deflate.scala b/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/Deflate.scala index ec03961ef..88e3e63ce 100644 --- a/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/Deflate.scala +++ b/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/Deflate.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.reactive.compression.internal.operators import java.util.zip.Deflater -import java.{util => ju} +import java.{ util => ju } import monix.reactive.compression.FlushMode diff --git a/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/DeflateOperator.scala b/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/DeflateOperator.scala index a4a964786..3f809671b 100644 --- a/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/DeflateOperator.scala +++ b/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/DeflateOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,17 +17,20 @@ package monix.reactive.compression.internal.operators +import scala.annotation.nowarn import java.util.zip.Deflater import monix.execution.{Ack, Scheduler} import monix.execution.Ack.Continue +import monix.execution.Scheduler import monix.reactive.Observable.Operator -import monix.reactive.compression.{CompressionLevel, CompressionParameters, CompressionStrategy, FlushMode} +import monix.reactive.compression.{ CompressionLevel, CompressionParameters, CompressionStrategy, FlushMode } import monix.reactive.observers.Subscriber import scala.concurrent.Future import scala.util.Success import scala.util.control.NonFatal +@nowarn("msg=unused value of type") private[compression] final class DeflateOperator( bufferSize: Int, params: CompressionParameters, @@ -37,8 +40,8 @@ private[compression] final class DeflateOperator( new Subscriber[Array[Byte]] { implicit val scheduler: Scheduler = out.scheduler - private[this] var ack: Future[Ack] = Continue - private[this] val deflate = + private var ack: Future[Ack] = Continue + private val deflate = new DeflateAdapter( bufferSize, params.level, diff --git a/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/GunzipOperator.scala b/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/GunzipOperator.scala index d3d423273..adb60bc7d 100644 --- a/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/GunzipOperator.scala +++ b/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/GunzipOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,10 +17,13 @@ package monix.reactive.compression.internal.operators -import java.util.zip.{CRC32, DataFormatException, Inflater} -import java.{util => ju} -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import scala.annotation.nowarn +import java.util.zip.{ CRC32, DataFormatException, Inflater } +import java.{ util => ju } + +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.compression.internal.operators.Gunzipper._ import monix.reactive.compression.{CompressionException, gzipCompressionMethod, gzipFlag, gzipMagicFirstByte, gzipMagicSecondByte} @@ -31,15 +34,16 @@ import scala.concurrent.Future import scala.util.Success import scala.util.control.NonFatal +@nowarn("msg=unused value of type") private[compression] final class GunzipOperator(bufferSize: Int) extends Operator[Array[Byte], Array[Byte]] { def apply(out: Subscriber[Array[Byte]]): Subscriber[Array[Byte]] = new Subscriber[Array[Byte]] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false - private[this] var ack: Future[Ack] = _ - private[this] val gunzipper = new Gunzipper(bufferSize) + private var isDone = false + private var ack: Future[Ack] = null.asInstanceOf[Future[Ack]] + private val gunzipper = new Gunzipper(bufferSize) def onNext(elem: Array[Byte]): Future[Ack] = { if (isDone) { @@ -229,7 +233,7 @@ private final class Gunzipper(bufferSize: Int) { private class CheckCrc16Step(pastCrc16Bytes: Array[Byte], crcValue: Long) extends State { override def feed(chunkBytes: Array[Byte]): (State, Array[Byte]) = { val (crc16Bytes, leftover) = (pastCrc16Bytes ++ chunkBytes).splitAt(2) - //Unlikely but possible that chunk was 1 byte only, leftover is empty. + // Unlikely but possible that chunk was 1 byte only, leftover is empty. if (crc16Bytes.length < 2) { (new CheckCrc16Step(crc16Bytes, crcValue), Array.emptyByteArray) } else { diff --git a/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/GzipOperator.scala b/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/GzipOperator.scala index e3d04cc93..b60d67256 100644 --- a/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/GzipOperator.scala +++ b/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/GzipOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,14 @@ package monix.reactive.compression.internal.operators +import scala.annotation.nowarn import java.nio.charset.StandardCharsets import java.time.Instant -import java.util.zip.{CRC32, Deflater} -import monix.execution.{Ack, Scheduler} +import java.util.zip.{ CRC32, Deflater } + +import monix.execution.Ack import monix.execution.Ack.Continue +import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.compression.internal.operators.Gzipper.gzipOperatingSystem import monix.reactive.compression.{CompressionLevel, CompressionParameters, CompressionStrategy, FlushMode, gzipCompressionMethod, gzipExtraFlag, gzipFlag, gzipMagicFirstByte, gzipMagicSecondByte, zeroByte} @@ -31,6 +34,7 @@ import scala.concurrent.Future import scala.util.Success import scala.util.control.NonFatal +@nowarn("msg=unused value of type") private[compression] final class GzipOperator( fileName: Option[String], modificationTime: Option[Instant], @@ -42,8 +46,8 @@ private[compression] final class GzipOperator( new Subscriber[Array[Byte]] { implicit val scheduler: Scheduler = out.scheduler - private[this] var ack: Future[Ack] = _ - private[this] val gzipper = + private var ack: Future[Ack] = null.asInstanceOf[Future[Ack]] + private val gzipper = new Gzipper( bufferSize, params.level, diff --git a/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/InflateOperator.scala b/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/InflateOperator.scala index 87d9a9a24..d7a83386f 100644 --- a/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/InflateOperator.scala +++ b/monix-reactive/jvm/src/main/scala/monix/reactive/compression/internal/operators/InflateOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,10 +17,13 @@ package monix.reactive.compression.internal.operators -import java.util.zip.{DataFormatException, Inflater} -import java.{util => ju} -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import scala.annotation.nowarn +import java.util.zip.{ DataFormatException, Inflater } +import java.{ util => ju } + +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.compression.CompressionException import monix.reactive.observers.Subscriber @@ -30,6 +33,7 @@ import scala.concurrent.Future import scala.util.Success import scala.util.control.NonFatal +@nowarn("msg=unused value of type") private[compression] final class InflateOperator(bufferSize: Int, noWrap: Boolean) extends Operator[Array[Byte], Array[Byte]] { @@ -37,9 +41,9 @@ private[compression] final class InflateOperator(bufferSize: Int, noWrap: Boolea new Subscriber[Array[Byte]] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false - private[this] var ack: Future[Ack] = _ - private[this] val inflater = new InflateAdapter(bufferSize, noWrap) + private var isDone = false + private var ack: Future[Ack] = null.asInstanceOf[Future[Ack]] + private val inflater = new InflateAdapter(bufferSize, noWrap) def onNext(elem: Array[Byte]): Future[Ack] = { if (isDone) { diff --git a/monix-reactive/jvm/src/main/scala/monix/reactive/compression/package.scala b/monix-reactive/jvm/src/main/scala/monix/reactive/compression/package.scala index 925a660c0..e7de4e909 100644 --- a/monix-reactive/jvm/src/main/scala/monix/reactive/compression/package.scala +++ b/monix-reactive/jvm/src/main/scala/monix/reactive/compression/package.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive import java.time.Instant import java.util.zip.Deflater -import monix.reactive.compression.internal.operators.{DeflateOperator, GunzipOperator, GzipOperator, InflateOperator} +import monix.reactive.compression.internal.operators.{ DeflateOperator, GunzipOperator, GzipOperator, InflateOperator } // From https://github.com/typelevel/fs2/blob/main/core/jvm/src/main/scala/fs2/compression.scala package object compression { diff --git a/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/AbstractBackPressuredBufferedSubscriber.scala b/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/AbstractBackPressuredBufferedSubscriber.scala index ff797a625..54d087a18 100644 --- a/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/AbstractBackPressuredBufferedSubscriber.scala +++ b/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/AbstractBackPressuredBufferedSubscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,35 +17,38 @@ package monix.reactive.observers.buffers -import monix.execution.{Ack, ChannelType, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import scala.annotation.nowarn +import monix.execution.{ Ack, ChannelType } +import monix.execution.Ack.{ Continue, Stop } import monix.execution.BufferCapacity.Unbounded import monix.execution.ChannelType._ +import monix.execution.Scheduler import monix.execution.atomic.Atomic import monix.execution.atomic.PaddingStrategy.LeftRight256 import monix.execution.internal.collection.LowLevelConcurrentQueue -import monix.execution.internal.{Platform, math} +import monix.execution.internal.{ math, Platform } import scala.util.control.NonFatal -import monix.reactive.observers.{BufferedSubscriber, Subscriber} +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } import scala.annotation.tailrec -import scala.concurrent.{Future, Promise} -import scala.util.{Failure, Success} +import scala.concurrent.{ Future, Promise } +import scala.util.{ Failure, Success } /** Shared internals between [[BackPressuredBufferedSubscriber]] and * [[BatchedBufferedSubscriber]]. */ +@nowarn("msg=unused value of type") private[observers] abstract class AbstractBackPressuredBufferedSubscriber[A, R]( out: Subscriber[R], _bufferSize: Int, - pt: ChannelType.ProducerSide) - extends CommonBufferMembers with BufferedSubscriber[A] { + pt: ChannelType.ProducerSide +) extends CommonBufferMembers with BufferedSubscriber[A] { require(_bufferSize > 0, "bufferSize must be a strictly positive number") - private[this] val bufferSize = math.nextPowerOf2(_bufferSize) - private[this] val em = out.scheduler.executionModel + private val bufferSize = math.nextPowerOf2(_bufferSize) + private val em = out.scheduler.executionModel implicit final val scheduler: Scheduler = out.scheduler protected final val queue: LowLevelConcurrentQueue[A] = @@ -55,9 +58,9 @@ private[observers] abstract class AbstractBackPressuredBufferedSubscriber[A, R]( fenced = false ) - private[this] val itemsToPush = + private val itemsToPush = Atomic.withPadding(0, LeftRight256) - private[this] val backPressured = + private val backPressured = Atomic.withPadding(null: Promise[Ack], LeftRight256) @tailrec @@ -128,7 +131,7 @@ private[observers] abstract class AbstractBackPressuredBufferedSubscriber[A, R]( protected def fetchNext(): R protected def fetchSize(r: R): Int - private[this] val consumerRunLoop = new Runnable { + private val consumerRunLoop = new Runnable { def run(): Unit = { fastLoop(lastIterationAck, 0, 0) } diff --git a/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/BackPressuredBufferedSubscriber.scala b/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/BackPressuredBufferedSubscriber.scala index 3da6eb5d2..29773329c 100644 --- a/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/BackPressuredBufferedSubscriber.scala +++ b/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/BackPressuredBufferedSubscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,8 +27,8 @@ import monix.reactive.observers.Subscriber private[observers] final class BackPressuredBufferedSubscriber[A] private ( out: Subscriber[A], _bufferSize: Int, - pt: ChannelType.ProducerSide) - extends AbstractBackPressuredBufferedSubscriber[A, A](out, _bufferSize, pt) { + pt: ChannelType.ProducerSide +) extends AbstractBackPressuredBufferedSubscriber[A, A](out, _bufferSize, pt) { @volatile protected var p50, p51, p52, p53, p54, p55, p56, p57 = 5 @volatile protected var q50, q51, q52, q53, q54, q55, q56, q57 = 5 @@ -44,7 +44,8 @@ private[observers] object BackPressuredBufferedSubscriber { def apply[A]( underlying: Subscriber[A], bufferSize: Int, - producerType: ChannelType.ProducerSide): BackPressuredBufferedSubscriber[A] = { + producerType: ChannelType.ProducerSide + ): BackPressuredBufferedSubscriber[A] = { new BackPressuredBufferedSubscriber[A](underlying, bufferSize, producerType) } diff --git a/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/BatchedBufferedSubscriber.scala b/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/BatchedBufferedSubscriber.scala index 4b15a9620..b9e6663aa 100644 --- a/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/BatchedBufferedSubscriber.scala +++ b/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/BatchedBufferedSubscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,6 +17,7 @@ package monix.reactive.observers.buffers +import scala.annotation.nowarn import monix.execution.ChannelType import monix.execution.internal.Platform import monix.reactive.observers.Subscriber @@ -27,11 +28,12 @@ import scala.collection.mutable.ListBuffer * [[monix.reactive.OverflowStrategy.BackPressure BackPressured]] * buffer overflowStrategy that sends events in bundles. */ +@nowarn("msg=unused value of type") private[monix] final class BatchedBufferedSubscriber[A] private ( out: Subscriber[List[A]], _bufferSize: Int, - pt: ChannelType.ProducerSide) - extends AbstractBackPressuredBufferedSubscriber[A, ListBuffer[A]]( + pt: ChannelType.ProducerSide +) extends AbstractBackPressuredBufferedSubscriber[A, ListBuffer[A]]( subscriberBufferToList(out), _bufferSize, pt @@ -56,6 +58,7 @@ private[monix] object BatchedBufferedSubscriber { def apply[A]( underlying: Subscriber[List[A]], bufferSize: Int, - producerType: ChannelType.ProducerSide): BatchedBufferedSubscriber[A] = + producerType: ChannelType.ProducerSide + ): BatchedBufferedSubscriber[A] = new BatchedBufferedSubscriber[A](underlying, bufferSize, producerType) } diff --git a/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/BuildersImpl.scala b/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/BuildersImpl.scala index 4a9be3a89..86ff738fb 100644 --- a/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/BuildersImpl.scala +++ b/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/BuildersImpl.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,13 +22,14 @@ import monix.execution.ChannelType.MultiProducer import monix.execution.internal.Platform import monix.reactive.OverflowStrategy import monix.reactive.OverflowStrategy._ -import monix.reactive.observers.{BufferedSubscriber, Subscriber} +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } private[observers] trait BuildersImpl { self: BufferedSubscriber.type => def apply[A]( subscriber: Subscriber[A], bufferPolicy: OverflowStrategy[A], - producerType: ChannelType.ProducerSide = MultiProducer): Subscriber[A] = { + producerType: ChannelType.ProducerSide = MultiProducer + ): Subscriber[A] = { bufferPolicy match { case Unbounded => SimpleBufferedSubscriber.unbounded(subscriber, Some(Platform.recommendedBufferChunkSize), producerType) @@ -57,7 +58,8 @@ private[observers] trait BuildersImpl { self: BufferedSubscriber.type => def synchronous[A]( subscriber: Subscriber[A], bufferPolicy: OverflowStrategy.Synchronous[A], - producerType: ChannelType.ProducerSide = MultiProducer): Subscriber.Sync[A] = { + producerType: ChannelType.ProducerSide = MultiProducer + ): Subscriber.Sync[A] = { bufferPolicy match { case Unbounded => SimpleBufferedSubscriber.unbounded(subscriber, Some(Platform.recommendedBufferChunkSize), producerType) @@ -84,6 +86,7 @@ private[observers] trait BuildersImpl { self: BufferedSubscriber.type => def batched[A]( underlying: Subscriber[List[A]], bufferSize: Int, - producerType: ChannelType.ProducerSide = MultiProducer): Subscriber[A] = + producerType: ChannelType.ProducerSide = MultiProducer + ): Subscriber[A] = BatchedBufferedSubscriber(underlying, bufferSize, producerType) } diff --git a/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/ConcurrentQueue.scala b/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/ConcurrentQueue.scala index f47431443..34bb27f9b 100644 --- a/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/ConcurrentQueue.scala +++ b/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/ConcurrentQueue.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,11 +19,11 @@ package monix.reactive.observers.buffers import java.util import monix.execution.internal.Platform -import monix.execution.internal.atomic.UnsafeAccess +import monix.execution.atomic.internal.UnsafeAccess import monix.execution.internal.math.nextPowerOf2 import monix.execution.internal.jctools.queues._ import monix.execution.internal.jctools.queues.MessagePassingQueue.Consumer -import monix.execution.internal.jctools.queues.atomic.{MpscAtomicArrayQueue, MpscLinkedAtomicQueue} +import monix.execution.internal.jctools.queues.atomic.{ MpscAtomicArrayQueue, MpscLinkedAtomicQueue } import scala.collection.mutable /** A simple internal interface providing the needed commonality between diff --git a/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/DropNewBufferedSubscriber.scala b/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/DropNewBufferedSubscriber.scala index cc3ef4bae..eb98a5b4a 100644 --- a/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/DropNewBufferedSubscriber.scala +++ b/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/DropNewBufferedSubscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,16 +18,17 @@ package monix.reactive.observers.buffers import monix.eval.Coeval -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} -import monix.execution.atomic.PaddingStrategy.{LeftRight128, LeftRight256} -import monix.execution.atomic.{Atomic, AtomicInt} +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler +import monix.execution.atomic.PaddingStrategy.{ LeftRight128, LeftRight256 } +import monix.execution.atomic.{ Atomic, AtomicInt } import scala.util.control.NonFatal -import monix.reactive.observers.{BufferedSubscriber, Subscriber} +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } import scala.concurrent.Future -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } /** A high-performance and non-blocking [[BufferedSubscriber]] * implementation for the [[monix.reactive.OverflowStrategy.DropNew DropNew]] @@ -37,22 +38,22 @@ import scala.util.{Failure, Success} private[observers] final class DropNewBufferedSubscriber[A] private ( out: Subscriber[A], bufferSize: Int, - onOverflow: Long => Coeval[Option[A]] = null) - extends CommonBufferMembers with BufferedSubscriber[A] with Subscriber.Sync[A] { + onOverflow: Long => Coeval[Option[A]], +) extends CommonBufferMembers with BufferedSubscriber[A] with Subscriber.Sync[A] { require(bufferSize > 0, "bufferSize must be a strictly positive number") implicit val scheduler: Scheduler = out.scheduler - private[this] val em = out.scheduler.executionModel + private val em = out.scheduler.executionModel - private[this] val itemsToPush = + private val itemsToPush = Atomic.withPadding(0, LeftRight256) - private[this] val droppedCount: AtomicInt = + private val droppedCount: AtomicInt = if (onOverflow != null) AtomicInt.withPadding(0, LeftRight128) else null - private[this] val queue = + private val queue = ConcurrentQueue.limited[A](bufferSize) def onNext(elem: A): Ack = { @@ -84,7 +85,7 @@ private[observers] final class DropNewBufferedSubscriber[A] private ( } } - private[this] def pushToConsumer(): Unit = { + private def pushToConsumer(): Unit = { val currentNr = itemsToPush.getAndIncrement() // If a run-loop isn't started, then go, go, go! @@ -95,7 +96,7 @@ private[observers] final class DropNewBufferedSubscriber[A] private ( } } - private[this] val consumerRunLoop = new Runnable { + private val consumerRunLoop = new Runnable { def run(): Unit = { // This lastIterationAck is also being set by the consumer-loop, // but it's important for the write to happen before `itemsToPush`, @@ -279,6 +280,7 @@ private[observers] object DropNewBufferedSubscriber { def withSignal[A]( underlying: Subscriber[A], bufferSize: Int, - onOverflow: Long => Coeval[Option[A]]): DropNewBufferedSubscriber[A] = + onOverflow: Long => Coeval[Option[A]] + ): DropNewBufferedSubscriber[A] = new DropNewBufferedSubscriber[A](underlying, bufferSize, onOverflow) } diff --git a/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/EvictingBufferedSubscriber.scala b/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/EvictingBufferedSubscriber.scala index a69db54e3..9c7e9fad7 100644 --- a/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/EvictingBufferedSubscriber.scala +++ b/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/EvictingBufferedSubscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,21 +18,22 @@ package monix.reactive.observers.buffers import monix.eval.Coeval -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} -import monix.execution.atomic.PaddingStrategy.{LeftRight128, LeftRight256} -import monix.execution.atomic.{Atomic, AtomicAny, AtomicInt} +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler +import monix.execution.atomic.PaddingStrategy.{ LeftRight128, LeftRight256 } +import monix.execution.atomic.{ Atomic, AtomicAny, AtomicInt } import monix.execution.internal.math - import scala.util.control.NonFatal import monix.reactive.OverflowStrategy._ import monix.reactive.observers.buffers.AbstractEvictingBufferedSubscriber._ -import monix.reactive.observers.{BufferedSubscriber, Subscriber} +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } import scala.annotation.tailrec import scala.collection.immutable.Queue import scala.concurrent.Future -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } +import scala.annotation.unchecked.uncheckedVariance /** A [[BufferedSubscriber]] implementation for the * [[monix.reactive.OverflowStrategy.DropOld DropOld]] @@ -43,8 +44,8 @@ import scala.util.{Failure, Success} private[observers] final class EvictingBufferedSubscriber[-A] private ( out: Subscriber[A], strategy: Evicted[Nothing], - onOverflow: Long => Coeval[Option[A]]) - extends AbstractEvictingBufferedSubscriber(out, strategy, onOverflow) { + onOverflow: Long => Coeval[Option[A]] +) extends AbstractEvictingBufferedSubscriber(out, strategy, onOverflow) { @volatile protected var p50, p51, p52, p53, p54, p55, p56, p57 = 5 @volatile protected var q50, q51, q52, q53, q54, q55, q56, q57 = 5 @@ -69,7 +70,8 @@ private[observers] object EvictingBufferedSubscriber { def dropOldAndSignal[A]( underlying: Subscriber[A], bufferSize: Int, - onOverflow: Long => Coeval[Option[A]]): EvictingBufferedSubscriber[A] = { + onOverflow: Long => Coeval[Option[A]] + ): EvictingBufferedSubscriber[A] = { require(bufferSize > 1, "bufferSize must be a strictly positive number, bigger than 1") val maxCapacity = math.nextPowerOf2(bufferSize) @@ -96,7 +98,8 @@ private[observers] object EvictingBufferedSubscriber { def clearBufferAndSignal[A]( underlying: Subscriber[A], bufferSize: Int, - onOverflow: Long => Coeval[Option[A]]): EvictingBufferedSubscriber[A] = { + onOverflow: Long => Coeval[Option[A]] + ): EvictingBufferedSubscriber[A] = { require(bufferSize > 1, "bufferSize must be a strictly positive number, bigger than 1") val maxCapacity = math.nextPowerOf2(bufferSize) @@ -107,22 +110,22 @@ private[observers] object EvictingBufferedSubscriber { private[observers] abstract class AbstractEvictingBufferedSubscriber[-A]( out: Subscriber[A], strategy: Evicted[Nothing], - onOverflow: Long => Coeval[Option[A]]) - extends CommonBufferMembers with BufferedSubscriber[A] with Subscriber.Sync[A] { + onOverflow: Long => Coeval[Option[A]] +) extends CommonBufferMembers with BufferedSubscriber[A] with Subscriber.Sync[A] { require(strategy.bufferSize > 0, "bufferSize must be a strictly positive number") implicit val scheduler: Scheduler = out.scheduler - private[this] val em = out.scheduler.executionModel + private val em = out.scheduler.executionModel - private[this] val droppedCount: AtomicInt = + private val droppedCount: AtomicInt = if (onOverflow != null) AtomicInt.withPadding(0, LeftRight128) else null - private[this] val itemsToPush = + private val itemsToPush = Atomic.withPadding(0, LeftRight256) - private[this] val queue = - new ConcurrentBuffer[A](strategy) + private val queue: ConcurrentBuffer[A @uncheckedVariance] = + new ConcurrentBuffer(strategy) def onNext(elem: A): Ack = { if (upstreamIsComplete || downstreamIsComplete) Stop @@ -157,7 +160,7 @@ private[observers] abstract class AbstractEvictingBufferedSubscriber[-A]( } } - private[this] def pushToConsumer(increment: Int): Unit = { + private def pushToConsumer(increment: Int): Unit = { val currentNr = { if (increment != 0) itemsToPush.getAndIncrement(increment) @@ -173,7 +176,7 @@ private[observers] abstract class AbstractEvictingBufferedSubscriber[-A]( } } - private[this] val consumerLoop = new Runnable { + private val consumerLoop = new Runnable { def run(): Unit = { // This lastIterationAck is also being set by the consumer-loop, // but it's important for the write to happen before `itemsToPush`, @@ -354,7 +357,7 @@ private[observers] abstract class AbstractEvictingBufferedSubscriber[-A]( private[observers] object AbstractEvictingBufferedSubscriber { private final class ConcurrentBuffer[A](strategy: Evicted[Nothing]) { - private[this] val bufferRef: AtomicAny[Buffer[A]] = + private val bufferRef: AtomicAny[Buffer[A]] = AtomicAny.withPadding(emptyBuffer, LeftRight256) def drain(): Queue[A] = { diff --git a/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/SimpleBufferedSubscriber.scala b/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/SimpleBufferedSubscriber.scala index 50dafe4b5..598b2ce1c 100644 --- a/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/SimpleBufferedSubscriber.scala +++ b/monix-reactive/jvm/src/main/scala/monix/reactive/observers/buffers/SimpleBufferedSubscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,10 +17,11 @@ package monix.reactive.observers.buffers -import monix.execution.{Ack, ChannelType, Scheduler} -import monix.execution.Ack.{Continue, Stop} -import monix.execution.BufferCapacity.{Bounded, Unbounded} +import monix.execution.{ Ack, ChannelType } +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.BufferCapacity.{ Bounded, Unbounded } import monix.execution.ChannelType.SingleConsumer +import monix.execution.Scheduler import monix.execution.atomic.Atomic import monix.execution.atomic.PaddingStrategy.LeftRight256 import monix.execution.exceptions.BufferOverflowException @@ -28,10 +29,10 @@ import monix.execution.internal.collection.LowLevelConcurrentQueue import monix.execution.internal.math.nextPowerOf2 import scala.util.control.NonFatal -import monix.reactive.observers.{BufferedSubscriber, Subscriber} +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } import scala.concurrent.Future -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } /** A highly optimized [[BufferedSubscriber]] implementation. It supports 2 * [[monix.reactive.OverflowStrategy overflow strategies]]: @@ -47,8 +48,8 @@ import scala.util.{Failure, Success} private[observers] final class SimpleBufferedSubscriber[A] protected ( out: Subscriber[A], _qRef: LowLevelConcurrentQueue[A], - capacity: Int) - extends AbstractSimpleBufferedSubscriber[A](out, _qRef, capacity) { + capacity: Int +) extends AbstractSimpleBufferedSubscriber[A](out, _qRef, capacity) { @volatile protected var p50, p51, p52, p53, p54, p55, p56, p57 = 5 @volatile protected var q50, q51, q52, q53, q54, q55, q56, q57 = 5 @@ -57,13 +58,13 @@ private[observers] final class SimpleBufferedSubscriber[A] protected ( private[observers] abstract class AbstractSimpleBufferedSubscriber[A] protected ( out: Subscriber[A], _qRef: LowLevelConcurrentQueue[A], - capacity: Int) - extends CommonBufferMembers with BufferedSubscriber[A] with Subscriber.Sync[A] { + capacity: Int +) extends CommonBufferMembers with BufferedSubscriber[A] with Subscriber.Sync[A] { - private[this] val queue = _qRef - private[this] val em = out.scheduler.executionModel + private val queue = _qRef + private val em = out.scheduler.executionModel implicit val scheduler: Scheduler = out.scheduler - private[this] val itemsToPush = + private val itemsToPush = Atomic.withPadding(0, LeftRight256) def onNext(elem: A): Ack = { @@ -81,7 +82,8 @@ private[observers] abstract class AbstractSimpleBufferedSubscriber[A] protected BufferOverflowException( s"Downstream observer is too slow, buffer overflowed with a " + s"specified maximum capacity of $capacity" - )) + ) + ) Stop } @@ -109,7 +111,7 @@ private[observers] abstract class AbstractSimpleBufferedSubscriber[A] protected } } - private[this] def pushToConsumer(): Unit = { + private def pushToConsumer(): Unit = { val currentNr = itemsToPush.getAndIncrement() // If a run-loop isn't started, then go, go, go! @@ -121,7 +123,7 @@ private[observers] abstract class AbstractSimpleBufferedSubscriber[A] protected } } - private[this] val consumerLoop = new Runnable { + private val consumerLoop = new Runnable { def run(): Unit = { // This lastIterationAck is also being set by the consumer-loop, // but it's important for the write to happen before `itemsToPush`, @@ -258,7 +260,8 @@ private[observers] object SimpleBufferedSubscriber { def unbounded[A]( underlying: Subscriber[A], chunkSizeHint: Option[Int], - pt: ChannelType.ProducerSide): SimpleBufferedSubscriber[A] = { + pt: ChannelType.ProducerSide + ): SimpleBufferedSubscriber[A] = { val ct = ChannelType.assemble(pt, SingleConsumer) val queue = LowLevelConcurrentQueue[A](Unbounded(chunkSizeHint), ct, fenced = false) new SimpleBufferedSubscriber[A](underlying, queue, Int.MaxValue) @@ -267,7 +270,8 @@ private[observers] object SimpleBufferedSubscriber { def overflowTriggering[A]( underlying: Subscriber[A], bufferSize: Int, - pt: ChannelType.ProducerSide): SimpleBufferedSubscriber[A] = { + pt: ChannelType.ProducerSide + ): SimpleBufferedSubscriber[A] = { val maxCapacity = math.max(4, nextPowerOf2(bufferSize)) val ct = ChannelType.assemble(pt, SingleConsumer) val queue = LowLevelConcurrentQueue[A](Bounded(bufferSize), ct, fenced = false) diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/BaseConcurrencySuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/BaseConcurrencySuite.scala index 5f3d74fb2..82d0ccb34 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/BaseConcurrencySuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/BaseConcurrencySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,8 +25,8 @@ import monix.execution.Scheduler import monix.execution.schedulers.SchedulerService import scala.concurrent.duration._ -import scala.concurrent.{Await, Future} -import scala.util.{Failure, Success} +import scala.concurrent.{ Await, Future } +import scala.util.{ Failure, Success } trait BaseConcurrencySuite extends TestSuite[SchedulerService] with Checkers with ArbitraryInstancesBase { diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/SerializableSuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/SerializableSuite.scala index 5783ee5f1..26c540cd7 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/SerializableSuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/SerializableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,12 +17,12 @@ package monix.reactive -import java.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream} +import java.io.{ ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream } import cats.laws._ import cats.laws.discipline._ import monix.execution.Ack import monix.execution.Ack.Continue -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } object SerializableSuite extends BaseTestSuite { def serialize(obj: Serializable) = { diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/BaseDecompressionSuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/BaseDecompressionSuite.scala index 04a6dc6a9..7e9addacf 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/BaseDecompressionSuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/BaseDecompressionSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/CompressionIntegrationSuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/CompressionIntegrationSuite.scala index a590b993c..8f745ce52 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/CompressionIntegrationSuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/CompressionIntegrationSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/CompressionTestData.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/CompressionTestData.scala index d3f848427..a648ea9e5 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/CompressionTestData.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/CompressionTestData.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/DeflateIntegrationSuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/DeflateIntegrationSuite.scala index 48bf1e042..624777647 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/DeflateIntegrationSuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/DeflateIntegrationSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/DeflateOperatorSuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/DeflateOperatorSuite.scala index 4aee98d29..c1151d1af 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/DeflateOperatorSuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/DeflateOperatorSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -39,7 +39,8 @@ object DeflateOperatorSuite extends BaseOperatorSuite with DeflateTestUtils { assertEquals( list.flatten, jdkDeflate(Array.empty, new Deflater(-1, false)).toList - )) + ) + ) .runToFuture } testAsync("deflates same as JDK") { _ => @@ -95,7 +96,8 @@ object DeflateOperatorSuite extends BaseOperatorSuite with DeflateTestUtils { .take(sourceCount.toLong - 1) .transform(deflate()) .map(_ => 1L), - ex) + ex + ) Sample(o, sourceCount, sourceCount, Zero, Zero) } diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/DeflateTestUtils.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/DeflateTestUtils.scala index 20c1da3f6..0aef3c312 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/DeflateTestUtils.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/DeflateTestUtils.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.compression import java.io.ByteArrayInputStream import java.util.Arrays -import java.util.zip.{Deflater, DeflaterInputStream, Inflater, InflaterInputStream} +import java.util.zip.{ Deflater, DeflaterInputStream, Inflater, InflaterInputStream } import monix.reactive.Observable diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/GunzipOperatorSuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/GunzipOperatorSuite.scala index 5f9ce4ace..fe8122ac3 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/GunzipOperatorSuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/GunzipOperatorSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -98,7 +98,7 @@ object GunzipOperatorSuite extends BaseDecompressionSuite with GzipTestsUtils { .repeatEval(jdkGzip(longText, syncFlush = false)) .take(sourceCount.toLong) .transform(gunzip()) ++ Observable - .repeatEval(longText) //corrupted payload + .repeatEval(longText) // corrupted payload .transform(gunzip())) .map(_ => 1L) .onErrorFallbackTo(Observable.raiseError(ex)) @@ -113,7 +113,8 @@ object GunzipOperatorSuite extends BaseDecompressionSuite with GzipTestsUtils { .take(sourceCount.toLong - 1) .transform(gunzip(64)) .map(_ => 1L), - ex) + ex + ) Sample(o, sourceCount, sourceCount, Zero, Zero) } diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/GzipIntegrationTest.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/GzipIntegrationTest.scala index 220ce6b1e..0c7472d02 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/GzipIntegrationTest.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/GzipIntegrationTest.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,8 +17,8 @@ package monix.reactive.compression -import java.io.{ByteArrayInputStream, ByteArrayOutputStream, InputStream} -import java.util.zip.{GZIPInputStream, GZIPOutputStream} +import java.io.{ ByteArrayInputStream, ByteArrayOutputStream, InputStream } +import java.util.zip.{ GZIPInputStream, GZIPOutputStream } import monix.eval.Task import monix.reactive.Observable diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/GzipOperatorSuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/GzipOperatorSuite.scala index 98b457932..87e39789f 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/GzipOperatorSuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/GzipOperatorSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -99,7 +99,8 @@ object GzipOperatorSuite extends BaseOperatorSuite with GzipTestsUtils { .take(sourceCount.toLong - 1) .transform(gzip()) .map(_ => 1L), - ex) + ex + ) Sample(o, sourceCount, sourceCount, Zero, Zero) } diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/GzipTestsUtils.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/GzipTestsUtils.scala index e8d1f95f1..6215f454b 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/GzipTestsUtils.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/GzipTestsUtils.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,9 @@ package monix.reactive.compression -import java.io.{ByteArrayInputStream, ByteArrayOutputStream} +import java.io.{ ByteArrayInputStream, ByteArrayOutputStream } import java.nio.charset.StandardCharsets -import java.util.zip.{CRC32, GZIPInputStream, GZIPOutputStream} +import java.util.zip.{ CRC32, GZIPInputStream, GZIPOutputStream } import monix.reactive.Observable diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/InflateOperatorSuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/InflateOperatorSuite.scala index 92849dd7c..1807f2265 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/compression/InflateOperatorSuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/compression/InflateOperatorSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -68,7 +68,7 @@ object InflateOperatorSuite extends BaseDecompressionSuite with DeflateTestUtils .repeatEval(jdkDeflate(longText, new Deflater(-1, true))) .take(sourceCount.toLong) .transform(inflate(noWrap = true)) ++ Observable - .repeatEval(longText) //corrupted payload + .repeatEval(longText) // corrupted payload .transform(inflate(noWrap = true))) .map(_ => 1L) .onErrorFallbackTo(Observable.raiseError(ex)) diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/consumers/LoadBalanceConsumerConcurrencySuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/consumers/LoadBalanceConsumerConcurrencySuite.scala index b63d76283..366677777 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/consumers/LoadBalanceConsumerConcurrencySuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/consumers/LoadBalanceConsumerConcurrencySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.consumers import cats.laws._ import cats.laws.discipline._ -import monix.reactive.{BaseConcurrencySuite, Consumer, Observable} +import monix.reactive.{ BaseConcurrencySuite, Consumer, Observable } object LoadBalanceConsumerConcurrencySuite extends BaseConcurrencySuite { test("aggregate all events") { implicit s => @@ -53,7 +53,7 @@ object LoadBalanceConsumerConcurrencySuite extends BaseConcurrencySuite { val justOne = Consumer.headOption[Int].map(_.getOrElse(0).toLong) val allConsumers = for (i <- 0 until parallelism) yield if (i % 2 == 0) fold else justOne - val consumer = Consumer.loadBalance(allConsumers: _*) + val consumer = Consumer.loadBalance(allConsumers*) val task1 = source.foldLeft(0L)(_ + _).firstL val task2 = source.consumeWith(consumer).map(_.sum) task1 <-> task2 diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/ConcatMapConcurrencySuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/ConcatMapConcurrencySuite.scala index 645365c81..5e1ea5c00 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/ConcatMapConcurrencySuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/ConcatMapConcurrencySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,9 +20,9 @@ package monix.reactive.internal.operators import monix.eval.Task import monix.execution.Cancelable import monix.execution.cancelables.BooleanCancelable -import monix.reactive.{BaseConcurrencySuite, Observable} +import monix.reactive.{ BaseConcurrencySuite, Observable } import scala.concurrent.duration._ -import scala.concurrent.{Await, Future, Promise} +import scala.concurrent.{ Await, Future, Promise } object ConcatMapConcurrencySuite extends BaseConcurrencySuite { val cancelTimeout = 3.minutes diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/FlatScanConcurrencySuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/FlatScanConcurrencySuite.scala index f92f55d55..af10f5477 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/FlatScanConcurrencySuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/FlatScanConcurrencySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,10 +20,10 @@ package monix.reactive.internal.operators import monix.eval.Task import monix.execution.Cancelable import monix.execution.cancelables.BooleanCancelable -import monix.reactive.{BaseConcurrencySuite, Observable} +import monix.reactive.{ BaseConcurrencySuite, Observable } import scala.concurrent.duration._ -import scala.concurrent.{Await, Future, Promise} +import scala.concurrent.{ Await, Future, Promise } object FlatScanConcurrencySuite extends BaseConcurrencySuite { val cancelTimeout = 3.minutes diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/MapParallelOrderedConcurrencySuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/MapParallelOrderedConcurrencySuite.scala index ac3b81925..e3a365f5c 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/MapParallelOrderedConcurrencySuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/MapParallelOrderedConcurrencySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.internal.operators import cats.laws._ import cats.laws.discipline._ import monix.eval.Task -import monix.reactive.{BaseConcurrencySuite, Observable} +import monix.reactive.{ BaseConcurrencySuite, Observable } object MapParallelOrderedConcurrencySuite extends BaseConcurrencySuite { test("mapParallelOrdered works concurrently") { implicit s => diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/MapParallelUnorderedConcurrencySuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/MapParallelUnorderedConcurrencySuite.scala index 4aa3a1c63..5d80ebc43 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/MapParallelUnorderedConcurrencySuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/MapParallelUnorderedConcurrencySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import cats.laws._ import cats.laws.discipline._ import monix.eval.Task -import monix.reactive.{BaseConcurrencySuite, Observable} +import monix.reactive.{ BaseConcurrencySuite, Observable } object MapParallelUnorderedConcurrencySuite extends BaseConcurrencySuite { test("mapParallelUnordered works concurrently") { implicit s => diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/MapTaskConcurrencySuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/MapTaskConcurrencySuite.scala index bccea4b36..7eed839f9 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/MapTaskConcurrencySuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/MapTaskConcurrencySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,9 +19,9 @@ package monix.reactive.internal.operators import monix.eval.Task import monix.execution.Cancelable -import monix.reactive.{BaseConcurrencySuite, Observable} +import monix.reactive.{ BaseConcurrencySuite, Observable } import scala.concurrent.duration._ -import scala.concurrent.{Await, Future, Promise} +import scala.concurrent.{ Await, Future, Promise } object MapTaskConcurrencySuite extends BaseConcurrencySuite { val cancelTimeout = 30.seconds diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/ScanTaskConcurrencySuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/ScanTaskConcurrencySuite.scala index ed1afe4ea..c60799252 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/ScanTaskConcurrencySuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/internal/operators/ScanTaskConcurrencySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,10 +19,10 @@ package monix.reactive.internal.operators import monix.eval.Task import monix.execution.Cancelable -import monix.reactive.{BaseConcurrencySuite, Observable} +import monix.reactive.{ BaseConcurrencySuite, Observable } import scala.concurrent.duration._ -import scala.concurrent.{Await, Future, Promise} +import scala.concurrent.{ Await, Future, Promise } object ScanTaskConcurrencySuite extends BaseConcurrencySuite { val cancelTimeout = 30.seconds diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/issues/Issue1167Suite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/issues/Issue1167Suite.scala index e0163b92a..5f289592e 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/issues/Issue1167Suite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/issues/Issue1167Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.issues import monix.eval.Task import monix.execution.Scheduler import scala.concurrent.duration._ -import monix.reactive.{BaseTestSuite, Observable} +import monix.reactive.{ BaseTestSuite, Observable } object Issue1167Suite extends BaseTestSuite { @@ -33,7 +33,6 @@ object Issue1167Suite extends BaseTestSuite { assertEquals(received, Right(())) } - test("zip2 of different sizes should terminate [issue #1167]") { _ => val obs1 = Observable(1, 2, 3) val obs2 = Observable(1, 2, 3, 4) @@ -76,7 +75,6 @@ object Issue1167Suite extends BaseTestSuite { val obs5 = Observable(1, 2, 3, 4) val obs6 = Observable(1, 2, 3, 4) - testIssue1167(Observable.zip6(obs1, obs2, obs3, obs4, obs5, obs6)) } @@ -170,6 +168,9 @@ object Issue1167Suite extends BaseTestSuite { val received: List[Seq[Int]] = Observable.zipList(obs1, obs2, obs3, obs4, obs5, obs6).toListL.runSyncUnsafe() - assertEquals(received, List(List(0, 0, 0, 0, 0, 0), List(1, 1, 1, 1, 1, 1), List(2, 2, 2, 2, 2, 2), List(3, 3, 3, 3, 3, 3))) + assertEquals( + received, + List(List(0, 0, 0, 0, 0, 0), List(1, 1, 1, 1, 1, 1), List(2, 2, 2, 2, 2, 2), List(3, 3, 3, 3, 3, 3)) + ) } } diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/issues/Issue908Suite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/issues/Issue908Suite.scala index 0fc7fb29b..c6544384c 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/issues/Issue908Suite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/issues/Issue908Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,13 +20,13 @@ package issues import minitest.TestSuite import monix.eval.Task -import monix.execution.{Scheduler, UncaughtExceptionReporter} +import monix.execution.{ Scheduler, UncaughtExceptionReporter } import monix.execution.schedulers.SchedulerService -import monix.reactive.subjects.{AsyncSubject, Subject} +import monix.reactive.subjects.{ AsyncSubject, Subject } -import scala.concurrent.{Await, TimeoutException} +import scala.concurrent.{ Await, TimeoutException } import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object Issue908Suite extends TestSuite[SchedulerService] { val CONCURRENT_TASKS = 1000 @@ -37,7 +37,8 @@ object Issue908Suite extends TestSuite[SchedulerService] { parallelism = math.max(Runtime.getRuntime.availableProcessors(), 2), name = "issue908-suite", daemonic = true, - reporter = UncaughtExceptionReporter(_ => ())) + reporter = UncaughtExceptionReporter(_ => ()) + ) } def tearDown(env: SchedulerService): Unit = { diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyBackPressuredConcurrencySuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyBackPressuredConcurrencySuite.scala index 681931145..c07af9e58 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyBackPressuredConcurrencySuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyBackPressuredConcurrencySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,17 +17,17 @@ package monix.reactive.observers -import java.util.concurrent.{CountDownLatch, TimeUnit} +import java.util.concurrent.{ CountDownLatch, TimeUnit } import monix.execution.Ack -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.ExecutionModel.BatchedExecution import monix.execution.exceptions.DummyException import monix.reactive.OverflowStrategy.BackPressure -import monix.reactive.{BaseConcurrencySuite, Observable, Observer} +import monix.reactive.{ BaseConcurrencySuite, Observable, Observer } import scala.concurrent.duration._ -import scala.concurrent.{Await, Future, Promise} +import scala.concurrent.{ Await, Future, Promise } import scala.util.Random object OverflowStrategyBackPressuredConcurrencySuite extends BaseConcurrencySuite { @@ -153,8 +153,8 @@ object OverflowStrategyBackPressuredConcurrencySuite extends BaseConcurrencySuit val buffer = BufferedSubscriber[Int](Subscriber(underlying, s), BackPressure(totalCount)) def loop(n: Int): Unit = - if (n > 0) s.execute(new Runnable { - def run() = { buffer.onNext(n); loop(n - 1) } + if (n > 0) s.execute(() => { + buffer.onNext(n); loop(n - 1) }) else buffer.onComplete() diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyDropNewAndSignalConcurrencySuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyDropNewAndSignalConcurrencySuite.scala index 0afb1b5e3..48377b16c 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyDropNewAndSignalConcurrencySuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyDropNewAndSignalConcurrencySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,17 +17,17 @@ package monix.reactive.observers -import java.util.concurrent.{CountDownLatch, TimeUnit} +import java.util.concurrent.{ CountDownLatch, TimeUnit } import monix.eval.Coeval -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.exceptions.DummyException -import monix.execution.{Ack, Scheduler} +import monix.execution.{ Ack, Scheduler } import monix.reactive.OverflowStrategy.DropNewAndSignal -import monix.reactive.{BaseConcurrencySuite, Observable, Observer} +import monix.reactive.{ BaseConcurrencySuite, Observable, Observer } import scala.concurrent.duration._ -import scala.concurrent.{Await, Future, Promise} +import scala.concurrent.{ Await, Future, Promise } import scala.util.Random object OverflowStrategyDropNewAndSignalConcurrencySuite extends BaseConcurrencySuite { @@ -101,8 +101,8 @@ object OverflowStrategyDropNewAndSignalConcurrencySuite extends BaseConcurrencyS val buffer = buildNewForInt(100000, underlying) def loop(n: Int): Unit = - if (n > 0) s.execute(new Runnable { - def run() = { buffer.onNext(n); loop(n - 1) } + if (n > 0) s.execute(() => { + buffer.onNext(n); loop(n - 1) }) else buffer.onComplete() @@ -189,7 +189,8 @@ object OverflowStrategyDropNewAndSignalConcurrencySuite extends BaseConcurrencyS val buffer = BufferedSubscriber[Either[Int, Int]]( Subscriber(underlying, s), - DropNewAndSignal(8, nr => Coeval.pure(Some(Left(nr.toInt))))) + DropNewAndSignal(8, nr => Coeval.pure(Some(Left(nr.toInt)))) + ) for (i <- 1 to 100) buffer.onNext(Right(i)) @@ -289,11 +290,14 @@ object OverflowStrategyDropNewAndSignalConcurrencySuite extends BaseConcurrencyS test("should send onComplete when in flight") { implicit s => val latch = new CountDownLatch(1) val promise = Promise[Ack]() - val buffer = buildNewForInt(5, new Observer[Int] { - def onError(ex: Throwable) = throw new IllegalStateException() - def onNext(elem: Int) = promise.future - def onComplete() = latch.countDown() - }) + val buffer = buildNewForInt( + 5, + new Observer[Int] { + def onError(ex: Throwable) = throw new IllegalStateException() + def onNext(elem: Int) = promise.future + def onComplete() = latch.countDown() + } + ) buffer.onNext(1) buffer.onComplete() @@ -303,11 +307,14 @@ object OverflowStrategyDropNewAndSignalConcurrencySuite extends BaseConcurrencyS test("should send onComplete when at capacity") { implicit s => val latch = new CountDownLatch(1) val promise = Promise[Ack]() - val buffer = buildNewForInt(5, new Observer[Int] { - def onError(ex: Throwable) = throw new IllegalStateException() - def onNext(elem: Int) = promise.future - def onComplete() = latch.countDown() - }) + val buffer = buildNewForInt( + 5, + new Observer[Int] { + def onError(ex: Throwable) = throw new IllegalStateException() + def onNext(elem: Int) = promise.future + def onComplete() = latch.countDown() + } + ) buffer.onNext(1) buffer.onNext(2) @@ -326,14 +333,17 @@ object OverflowStrategyDropNewAndSignalConcurrencySuite extends BaseConcurrencyS val complete = new CountDownLatch(1) val startConsuming = Promise[Continue.type]() - val buffer = buildNewForLong(10000, new Observer[Long] { - def onNext(elem: Long) = { - sum += elem - startConsuming.future + val buffer = buildNewForLong( + 10000, + new Observer[Long] { + def onNext(elem: Long) = { + sum += elem + startConsuming.future + } + def onError(ex: Throwable) = throw ex + def onComplete() = complete.countDown() } - def onError(ex: Throwable) = throw ex - def onComplete() = complete.countDown() - }) + ) (0 until 9999).foreach { x => buffer.onNext(x.toLong); () } buffer.onComplete() @@ -347,14 +357,17 @@ object OverflowStrategyDropNewAndSignalConcurrencySuite extends BaseConcurrencyS var sum = 0L val complete = new CountDownLatch(1) - val buffer = buildNewForLong(10000, new Observer[Long] { - def onNext(elem: Long) = { - sum += elem - Continue + val buffer = buildNewForLong( + 10000, + new Observer[Long] { + def onNext(elem: Long) = { + sum += elem + Continue + } + def onError(ex: Throwable) = throw ex + def onComplete() = complete.countDown() } - def onError(ex: Throwable) = throw ex - def onComplete() = complete.countDown() - }) + ) (0 until 9999).foreach { x => buffer.onNext(x.toLong); () } buffer.onComplete() diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyDropNewConcurrencySuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyDropNewConcurrencySuite.scala index 5aecf1d82..1179ad01e 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyDropNewConcurrencySuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyDropNewConcurrencySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,15 +17,15 @@ package monix.reactive.observers -import java.util.concurrent.{CountDownLatch, TimeUnit} +import java.util.concurrent.{ CountDownLatch, TimeUnit } import monix.execution.Ack -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.exceptions.DummyException import monix.reactive.OverflowStrategy.DropNew import monix.reactive.observers.buffers.DropNewBufferedSubscriber -import monix.reactive.{BaseConcurrencySuite, Observable, Observer} +import monix.reactive.{ BaseConcurrencySuite, Observable, Observer } import scala.concurrent.duration._ -import scala.concurrent.{Await, Future, Promise} +import scala.concurrent.{ Await, Future, Promise } import scala.util.Random object OverflowStrategyDropNewConcurrencySuite extends BaseConcurrencySuite { @@ -95,8 +95,9 @@ object OverflowStrategyDropNewConcurrencySuite extends BaseConcurrencySuite { val buffer = BufferedSubscriber[Int](Subscriber(underlying, s), DropNew(100000)) def loop(n: Int): Unit = - if (n > 0) s.execute(new Runnable { - def run() = { buffer.onNext(n); loop(n - 1) } + if (n > 0) s.execute(() => { + buffer.onNext(n) + loop(n - 1) }) else buffer.onComplete() diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyFailConcurrencySuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyFailConcurrencySuite.scala index f5c519eca..4f6cc054c 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyFailConcurrencySuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyFailConcurrencySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,13 +17,13 @@ package monix.reactive.observers -import java.util.concurrent.{CountDownLatch, TimeUnit} +import java.util.concurrent.{ CountDownLatch, TimeUnit } import monix.execution.Ack -import monix.execution.Ack.{Continue, Stop} -import monix.execution.exceptions.{BufferOverflowException, DummyException} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.exceptions.{ BufferOverflowException, DummyException } import monix.reactive.OverflowStrategy.Fail -import monix.reactive.{BaseConcurrencySuite, Observer} -import scala.concurrent.{Future, Promise} +import monix.reactive.{ BaseConcurrencySuite, Observer } +import scala.concurrent.{ Future, Promise } import scala.util.Random object OverflowStrategyFailConcurrencySuite extends BaseConcurrencySuite { @@ -76,10 +76,10 @@ object OverflowStrategyFailConcurrencySuite extends BaseConcurrencySuite { val buffer = BufferedSubscriber[Int](Subscriber(underlying, s), Fail(100000)) def loop(n: Int): Unit = - if (n > 0) s.execute(new Runnable { - def run() = { buffer.onNext(n); loop(n - 1) } - }) - else buffer.onComplete() + if (n > 0) + s.execute(() => { buffer.onNext(n); loop(n - 1) }) + else + buffer.onComplete() loop(10000) assert(completed.await(15, TimeUnit.MINUTES), "completed.await should have succeeded") diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyUnboundedConcurrencySuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyUnboundedConcurrencySuite.scala index 52bb0592a..586ae8c40 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyUnboundedConcurrencySuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/observers/OverflowStrategyUnboundedConcurrencySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,17 +17,17 @@ package monix.reactive.observers -import java.util.concurrent.{CountDownLatch, TimeUnit} +import java.util.concurrent.{ CountDownLatch, TimeUnit } import minitest.TestSuite import monix.execution.Ack.Continue import monix.execution.schedulers.SchedulerService -import monix.execution.{Ack, Scheduler} +import monix.execution.{ Ack, Scheduler } import monix.reactive.OverflowStrategy.Unbounded -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration._ -import scala.concurrent.{blocking, Await, Future, Promise} +import scala.concurrent.{ blocking, Await, Future, Promise } import scala.util.Random object OverflowStrategyUnboundedConcurrencySuite extends TestSuite[SchedulerService] { @@ -110,10 +110,10 @@ object OverflowStrategyUnboundedConcurrencySuite extends TestSuite[SchedulerServ val buffer = BufferedSubscriber[Int](Subscriber(underlying, s), Unbounded) def loop(n: Int): Unit = - if (n > 0) s.execute(new Runnable { - def run() = { buffer.onNext(n); loop(n - 1) } - }) - else buffer.onComplete() + if (n > 0) + s.execute(() => { buffer.onNext(n); loop(n - 1) }) + else + buffer.onComplete() loop(10000) blocking { diff --git a/monix-reactive/jvm/src/test/scala/monix/reactive/subjects/ReplaySubjectConcurrencySuite.scala b/monix-reactive/jvm/src/test/scala/monix/reactive/subjects/ReplaySubjectConcurrencySuite.scala index a439cab4e..a0fad8126 100644 --- a/monix-reactive/jvm/src/test/scala/monix/reactive/subjects/ReplaySubjectConcurrencySuite.scala +++ b/monix-reactive/jvm/src/test/scala/monix/reactive/subjects/ReplaySubjectConcurrencySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,12 +17,12 @@ package monix.reactive.subjects -import java.util.concurrent.{CountDownLatch, TimeUnit} +import java.util.concurrent.{ CountDownLatch, TimeUnit } import minitest.TestSuite import monix.execution.Ack.Continue import monix.execution.Scheduler import monix.execution.internal.RunnableAction -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } object ReplaySubjectConcurrencySuite extends TestSuite[Scheduler] { def tearDown(env: Scheduler) = () diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/Consumer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/Consumer.scala index 6c3e3a820..a95a8b3ce 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/Consumer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/Consumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,9 +19,9 @@ package monix.reactive import cats.Contravariant import cats.arrow.Profunctor -import monix.eval.{Task, TaskLike} +import monix.eval.{ Task, TaskLike } import monix.execution.cancelables.AssignableCancelable -import monix.execution.{Callback, Cancelable, Scheduler} +import monix.execution.{ Callback, Cancelable, Scheduler } import monix.reactive.internal.consumers._ import monix.reactive.observers.Subscriber diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/MulticastStrategy.scala b/monix-reactive/shared/src/main/scala/monix/reactive/MulticastStrategy.scala index 27bebbe4b..89b821ad0 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/MulticastStrategy.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/MulticastStrategy.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/Notification.scala b/monix-reactive/shared/src/main/scala/monix/reactive/Notification.scala index 46f327b7b..a64930ed4 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/Notification.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/Notification.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/Observable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/Observable.scala index f5c3c92fc..2b7501dca 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/Observable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/Observable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,35 +17,48 @@ package monix.reactive -import java.io.{BufferedReader, InputStream, PrintStream, Reader} - -import cats.{Alternative, Applicative, Apply, CoflatMap, Eq, FlatMap, Functor, FunctorFilter, Monoid, NonEmptyParallel, Order, ~>} -import cats.effect.{Bracket, Effect, ExitCase, Resource} -import monix.eval.{Coeval, Task, TaskLift, TaskLike} +import java.io.{ BufferedReader, InputStream, PrintStream, Reader } + +import cats.{ + ~>, + Alternative, + Applicative, + Apply, + CoflatMap, + Eq, + FlatMap, + Functor, + FunctorFilter, + Monoid, + NonEmptyParallel, + Order +} +import cats.effect.{ Bracket, Effect, ExitCase, Resource } +import monix.eval.{ Coeval, Task, TaskLift, TaskLike } import monix.eval.Task.defaultOptions -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.ChannelType.MultiProducer import monix.execution._ -import monix.execution.annotations.{UnsafeBecauseImpure, UnsafeProtocol} -import monix.execution.cancelables.{BooleanCancelable, SingleAssignCancelable} -import monix.execution.exceptions.{DownstreamTimeoutException, UpstreamTimeoutException} -import monix.reactive.Observable.{Operator, Transformer} +import monix.execution.annotations.{ UnsafeBecauseImpure, UnsafeProtocol } +import monix.execution.cancelables.{ BooleanCancelable, SingleAssignCancelable } +import monix.execution.exceptions.{ DownstreamTimeoutException, UpstreamTimeoutException } +import monix.reactive.Observable.{ Operator, Transformer } import monix.reactive.OverflowStrategy.Synchronous import monix.reactive.internal.builders import monix.reactive.internal.builders._ -import monix.reactive.internal.deprecated.{ObservableDeprecatedBuilders, ObservableDeprecatedMethods} +import monix.reactive.internal.deprecated.{ ObservableDeprecatedBuilders, ObservableDeprecatedMethods } import monix.reactive.internal.operators._ import monix.reactive.internal.subscribers.ForeachSubscriber import monix.reactive.observables._ import monix.reactive.observers._ import monix.reactive.subjects._ -import org.reactivestreams.{Publisher => RPublisher, Subscriber => RSubscriber} +import org.reactivestreams.{ Publisher => RPublisher, Subscriber => RSubscriber } import scala.collection.mutable import scala.collection.immutable -import scala.concurrent.duration.{Duration, FiniteDuration} -import scala.concurrent.{Future, Promise} -import scala.util.{Failure, Success, Try} +import scala.concurrent.duration.{ Duration, FiniteDuration } +import scala.concurrent.{ Future, Promise } +import scala.util.{ Failure, Success, Try } /** The `Observable` type that implements the Reactive Pattern. * @@ -362,7 +375,8 @@ abstract class Observable[+A] extends Serializable { self => */ @UnsafeBecauseImpure final def subscribe(nextFn: A => Future[Ack], errorFn: Throwable => Unit, completedFn: () => Unit)(implicit - s: Scheduler): Cancelable = { + s: Scheduler + ): Cancelable = { subscribe(new Subscriber[A] { implicit val scheduler: Scheduler = s @@ -762,7 +776,8 @@ abstract class Observable[+A] extends Serializable { self => final def bufferTimedWithPressure[AA >: A]( period: FiniteDuration, maxSize: Int, - sizeOf: AA => Int = (_: AA) => 1): Observable[Seq[AA]] = { + sizeOf: AA => Int = (_: AA) => 1 + ): Observable[Seq[AA]] = { val sampler = Observable.intervalAtFixedRate(period, period) new BufferWithSelectorObservable(self, sampler, maxSize, sizeOf) } @@ -913,7 +928,8 @@ abstract class Observable[+A] extends Serializable { self => * - ... */ final def bracketCaseF[F[_], B](use: A => Observable[B])(release: (A, ExitCase[Throwable]) => F[Unit])(implicit - F: TaskLike[F]): Observable[B] = + F: TaskLike[F] + ): Observable[B] = bracketCase(use)((a, e) => F(release(a, e))) /** Applies the given partial function to the source @@ -1153,7 +1169,7 @@ abstract class Observable[+A] extends Serializable { self => * result of [[materialize]]) back to an Observable that emits `A`. */ final def dematerialize[B](implicit ev: A <:< Notification[B]): Observable[B] = - self.asInstanceOf[Observable[Notification[B]]].liftByOperator(new DematerializeOperator[B]) + self.map(ev).liftByOperator(new DematerializeOperator[B]) /** Suppress duplicate consecutive items emitted by the source. * @@ -2062,7 +2078,8 @@ abstract class Observable[+A] extends Serializable { self => * @param keySelector a function that extracts the key for each item */ final def groupBy[K](keySelector: A => K)(implicit - os: Synchronous[Nothing] = OverflowStrategy.Unbounded): Observable[GroupedObservable[K, A]] = + os: Synchronous[Nothing] = OverflowStrategy.Unbounded + ): Observable[GroupedObservable[K, A]] = self.liftByOperator(new GroupByOperator[A, K](os, keySelector)) /** Given a routine make sure to execute it whenever the current @@ -2280,7 +2297,8 @@ abstract class Observable[+A] extends Serializable { self => * @see [[mapEval]] for serial execution */ final def mapParallelOrdered[B](parallelism: Int)(f: A => Task[B])(implicit - os: OverflowStrategy[B] = OverflowStrategy.Default): Observable[B] = + os: OverflowStrategy[B] = OverflowStrategy.Default + ): Observable[B] = new MapParallelOrderedObservable[A, B](self, parallelism, f, os) /** Version of [[mapParallelOrderedF]] that can work with generic @@ -2307,7 +2325,8 @@ abstract class Observable[+A] extends Serializable { self => * @see [[mapEvalF]] for serial execution */ final def mapParallelOrderedF[F[_], B](parallelism: Int)( - f: A => F[B])(implicit os: OverflowStrategy[B] = OverflowStrategy.Default, F: TaskLike[F]): Observable[B] = + f: A => F[B] + )(implicit os: OverflowStrategy[B] = OverflowStrategy.Default, F: TaskLike[F]): Observable[B] = new MapParallelOrderedObservable[A, B](self, parallelism, f.andThen(F.apply), os) /** Given a mapping function that maps events to [[monix.eval.Task tasks]], @@ -2335,7 +2354,8 @@ abstract class Observable[+A] extends Serializable { self => * @see [[mapEval]] for serial execution */ final def mapParallelUnordered[B](parallelism: Int)(f: A => Task[B])(implicit - os: OverflowStrategy[B] = OverflowStrategy.Default): Observable[B] = + os: OverflowStrategy[B] = OverflowStrategy.Default + ): Observable[B] = new MapParallelUnorderedObservable[A, B](self, parallelism, f, os) /** Version of [[mapParallelUnordered]] that can work with generic @@ -2363,7 +2383,8 @@ abstract class Observable[+A] extends Serializable { self => * @see [[mapEval]] for serial execution */ final def mapParallelUnorderedF[F[_], B](parallelism: Int)( - f: A => F[B])(implicit os: OverflowStrategy[B] = OverflowStrategy.Default, F: TaskLike[F]): Observable[B] = + f: A => F[B] + )(implicit os: OverflowStrategy[B] = OverflowStrategy.Default, F: TaskLike[F]): Observable[B] = new MapParallelUnorderedObservable[A, B](self, parallelism, f.andThen(F.apply), os) /** Converts the source Observable that emits `A` into an Observable @@ -2398,7 +2419,8 @@ abstract class Observable[+A] extends Serializable { self => */ final def merge[B](implicit ev: A <:< Observable[B], - os: OverflowStrategy[B] = OverflowStrategy.Default[B]): Observable[B] = + os: OverflowStrategy[B] = OverflowStrategy.Default[B] + ): Observable[B] = self.mergeMap(x => x)(os) /** Concurrently merges the observables emitted by the source with @@ -2432,7 +2454,8 @@ abstract class Observable[+A] extends Serializable { self => * @return $mergeMapReturn */ final def mergeMap[B](f: A => Observable[B])(implicit - os: OverflowStrategy[B] = OverflowStrategy.Default): Observable[B] = + os: OverflowStrategy[B] = OverflowStrategy.Default + ): Observable[B] = new MergeMapObservable[A, B](self, f, os, delayErrors = false) /** $mergeDescription @@ -2444,7 +2467,8 @@ abstract class Observable[+A] extends Serializable { self => */ final def mergeDelayErrors[B](implicit ev: A <:< Observable[B], - os: OverflowStrategy[B] = OverflowStrategy.Default): Observable[B] = + os: OverflowStrategy[B] = OverflowStrategy.Default + ): Observable[B] = self.mergeMap(x => x)(os) /** $mergeMapDescription @@ -2455,7 +2479,8 @@ abstract class Observable[+A] extends Serializable { self => * @return $mergeMapReturn */ final def mergeMapDelayErrors[B](f: A => Observable[B])(implicit - os: OverflowStrategy[B] = OverflowStrategy.Default): Observable[B] = + os: OverflowStrategy[B] = OverflowStrategy.Default + ): Observable[B] = new MergeMapObservable[A, B](self, f, os, delayErrors = true) /** Overrides the default [[monix.execution.Scheduler Scheduler]], @@ -2690,7 +2715,7 @@ abstract class Observable[+A] extends Serializable { self => * throws an error. */ final def onErrorRecover[B >: A](pf: PartialFunction[Throwable, B]): Observable[B] = - onErrorHandleWith(ex => (pf.andThen(b => Observable.now(b)).applyOrElse(ex, Observable.raiseError _))) + onErrorHandleWith(ex => (pf.andThen(b => Observable.now(b)).applyOrElse(ex, Observable.raiseError))) /** Returns an Observable that mirrors the behavior of the source, * unless the source is terminated with an `onError`, in which case @@ -2709,7 +2734,7 @@ abstract class Observable[+A] extends Serializable { self => * throws an error. */ final def onErrorRecoverWith[B >: A](pf: PartialFunction[Throwable, Observable[B]]): Observable[B] = - onErrorHandleWith(ex => pf.applyOrElse(ex, Observable.raiseError _)) + onErrorHandleWith(ex => pf.applyOrElse(ex, Observable.raiseError)) /** Returns an Observable that mirrors the behavior of the source, * unless the source is terminated with an `onError`, in which case @@ -3050,7 +3075,8 @@ abstract class Observable[+A] extends Serializable { self => * similar to `scanLeft` on Scala collections */ final def scanEval0F[F[_], S](seed: F[S])( - op: (S, A) => F[S])(implicit F: TaskLike[F], A: Applicative[F]): Observable[S] = + op: (S, A) => F[S] + )(implicit F: TaskLike[F], A: Applicative[F]): Observable[S] = Observable.fromTaskLike(seed).flatMap(s => s +: scanEvalF(A.pure(s))(op)) /** Applies a binary operator to a start value and all elements of @@ -3243,7 +3269,7 @@ abstract class Observable[+A] extends Serializable { self => * * @param trigger task that will cancel the stream as soon as it completes. */ - final def takeUntilEval(trigger: Task[_]): Observable[A] = + final def takeUntilEval(trigger: Task[?]): Observable[A] = self.takeUntil(Observable.fromTask(trigger)) /** Version of [[takeUntil]] that can work with a trigger expressed by a generic `F[_]` @@ -3716,7 +3742,8 @@ abstract class Observable[+A] extends Serializable { self => * @param f is a mapping function over the generated pairs */ final def withLatestFrom3[B1, B2, B3, R](o1: Observable[B1], o2: Observable[B2], o3: Observable[B3])( - f: (A, B1, B2, B3) => R): Observable[R] = { + f: (A, B1, B2, B3) => R + ): Observable[R] = { self.withLatestFrom(Observable.combineLatest3(o1, o2, o3)) { (a, o) => f(a, o._1, o._2, o._3) @@ -3740,7 +3767,8 @@ abstract class Observable[+A] extends Serializable { self => o1: Observable[B1], o2: Observable[B2], o3: Observable[B3], - o4: Observable[B4])(f: (A, B1, B2, B3, B4) => R): Observable[R] = { + o4: Observable[B4] + )(f: (A, B1, B2, B3, B4) => R): Observable[R] = { self.withLatestFrom(Observable.combineLatest4(o1, o2, o3, o4)) { (a, o) => f(a, o._1, o._2, o._3, o._4) @@ -3766,7 +3794,8 @@ abstract class Observable[+A] extends Serializable { self => o2: Observable[B2], o3: Observable[B3], o4: Observable[B4], - o5: Observable[B5])(f: (A, B1, B2, B3, B4, B5) => R): Observable[R] = { + o5: Observable[B5] + )(f: (A, B1, B2, B3, B4, B5) => R): Observable[R] = { self.withLatestFrom(Observable.combineLatest5(o1, o2, o3, o4, o5)) { (a, o) => f(a, o._1, o._2, o._3, o._4, o._5) @@ -3794,7 +3823,8 @@ abstract class Observable[+A] extends Serializable { self => o3: Observable[B3], o4: Observable[B4], o5: Observable[B5], - o6: Observable[B6])(f: (A, B1, B2, B3, B4, B5, B6) => R): Observable[R] = { + o6: Observable[B6] + )(f: (A, B1, B2, B3, B4, B5, B6) => R): Observable[R] = { self.withLatestFrom(Observable.combineLatest6(o1, o2, o3, o4, o5, o6)) { (a, o) => f(a, o._1, o._2, o._3, o._4, o._5, o._6) @@ -3912,8 +3942,8 @@ abstract class Observable[+A] extends Serializable { self => * val sub = SingleAssignSubscription() * * source.subscribe(new Subscriber[Int] { - * private[this] var requested = 0L - * private[this] var sum = 0L + * private var requested = 0L + * private var sum = 0L * * def onSubscribe(s: Subscription): Unit = { * sub := s @@ -3953,12 +3983,13 @@ abstract class Observable[+A] extends Serializable { self => */ final def toReactivePublisher[B >: A](implicit s: Scheduler): RPublisher[B] = new RPublisher[B] { - def subscribe(subscriber: RSubscriber[_ >: B]): Unit = { + def subscribe(subscriber: RSubscriber[? >: B]): Unit = { val subscription = SingleAssignCancelable() subscription := unsafeSubscribeFn( SafeSubscriber( Subscriber.fromReactiveSubscriber(subscriber, subscription) - )) + ) + ) () } } @@ -3981,8 +4012,8 @@ abstract class Observable[+A] extends Serializable { self => Task.create { (s, cb) => unsafeSubscribeFn(new Subscriber.Sync[A] { implicit val scheduler: Scheduler = s - private[this] var value: A = _ - private[this] var isEmpty = true + private var value: A = null.asInstanceOf[A] + private var isEmpty = true def onNext(elem: A): Ack = { if (isEmpty) isEmpty = false @@ -4232,7 +4263,7 @@ abstract class Observable[+A] extends Serializable { self => Task.create { (s, cb) => unsafeSubscribeFn(new Subscriber.Sync[A] { implicit val scheduler: Scheduler = s - private[this] var isDone = false + private var isDone = false def onNext(elem: A): Ack = { cb.onSuccess(elem) @@ -4413,7 +4444,7 @@ abstract class Observable[+A] extends Serializable { self => Task.create { (s, cb) => unsafeSubscribeFn(new Subscriber.Sync[A] { implicit val scheduler: Scheduler = s - private[this] var isDone = false + private var isDone = false def onNext(elem: A): Ack = Continue @@ -4935,7 +4966,8 @@ object Observable extends ObservableDeprecatedBuilders { */ def create[A]( overflowStrategy: OverflowStrategy.Synchronous[A], - producerType: ChannelType.ProducerSide = MultiProducer)(f: Subscriber.Sync[A] => Cancelable): Observable[A] = + producerType: ChannelType.ProducerSide = MultiProducer + )(f: Subscriber.Sync[A] => Cancelable): Observable[A] = new builders.CreateObservable(overflowStrategy, producerType, f) /** $multicastDesc @@ -4958,7 +4990,8 @@ object Observable extends ObservableDeprecatedBuilders { * back-pressured) */ def multicast[A](multicast: MulticastStrategy[A], overflow: OverflowStrategy.Synchronous[A])(implicit - s: Scheduler): (Observer.Sync[A], Observable[A]) = { + s: Scheduler + ): (Observer.Sync[A], Observable[A]) = { val ref = ConcurrentSubject(multicast, overflow) (ref, ref) @@ -5205,7 +5238,8 @@ object Observable extends ObservableDeprecatedBuilders { * - ... */ def fromInputStreamF[F[_]](in: F[InputStream], chunkSize: Int = 4096)(implicit - F: TaskLike[F]): Observable[Array[Byte]] = + F: TaskLike[F] + ): Observable[Array[Byte]] = fromInputStream(F(in), chunkSize) /** Converts a `java.io.InputStream` into an observable that will @@ -5600,7 +5634,7 @@ object Observable extends ObservableDeprecatedBuilders { /** Creates an Observable that continuously emits the given ''item'' repeatedly. */ def repeat[A](elems: A*): Observable[A] = - new builders.RepeatObservable(elems: _*) + new builders.RepeatObservable(elems*) /** Repeats the execution of the given `task`, emitting * the results indefinitely. @@ -5816,7 +5850,8 @@ object Observable extends ObservableDeprecatedBuilders { * @param f is the mapping function applied over the generated pairs */ def zipMap3[A1, A2, A3, R](oa1: Observable[A1], oa2: Observable[A2], oa3: Observable[A3])( - f: (A1, A2, A3) => R): Observable[R] = + f: (A1, A2, A3) => R + ): Observable[R] = new builders.Zip3Observable(oa1, oa2, oa3)(f) /** Creates a new observable from four observable sequences @@ -5835,7 +5870,8 @@ object Observable extends ObservableDeprecatedBuilders { oa1: Observable[A1], oa2: Observable[A2], oa3: Observable[A3], - oa4: Observable[A4]): Observable[(A1, A2, A3, A4)] = + oa4: Observable[A4] + ): Observable[(A1, A2, A3, A4)] = new builders.Zip4Observable(oa1, oa2, oa3, oa4)((a1, a2, a3, a4) => (a1, a2, a3, a4)) /** Creates a new observable from four observable sequences @@ -5853,7 +5889,8 @@ object Observable extends ObservableDeprecatedBuilders { * @param f is the mapping function applied over the generated pairs */ def zipMap4[A1, A2, A3, A4, R](oa1: Observable[A1], oa2: Observable[A2], oa3: Observable[A3], oa4: Observable[A4])( - f: (A1, A2, A3, A4) => R): Observable[R] = + f: (A1, A2, A3, A4) => R + ): Observable[R] = new builders.Zip4Observable(oa1, oa2, oa3, oa4)(f) /** Creates a new observable from five observable sequences @@ -5873,7 +5910,8 @@ object Observable extends ObservableDeprecatedBuilders { oa2: Observable[A2], oa3: Observable[A3], oa4: Observable[A4], - oa5: Observable[A5]): Observable[(A1, A2, A3, A4, A5)] = + oa5: Observable[A5] + ): Observable[(A1, A2, A3, A4, A5)] = new builders.Zip5Observable(oa1, oa2, oa3, oa4, oa5)((a1, a2, a3, a4, a5) => (a1, a2, a3, a4, a5)) /** Creates a new observable from five observable sequences @@ -5895,7 +5933,8 @@ object Observable extends ObservableDeprecatedBuilders { oa2: Observable[A2], oa3: Observable[A3], oa4: Observable[A4], - oa5: Observable[A5])(f: (A1, A2, A3, A4, A5) => R): Observable[R] = + oa5: Observable[A5] + )(f: (A1, A2, A3, A4, A5) => R): Observable[R] = new builders.Zip5Observable(oa1, oa2, oa3, oa4, oa5)(f) /** Creates a new observable from five observable sequences @@ -5916,7 +5955,8 @@ object Observable extends ObservableDeprecatedBuilders { oa3: Observable[A3], oa4: Observable[A4], oa5: Observable[A5], - oa6: Observable[A6]): Observable[(A1, A2, A3, A4, A5, A6)] = + oa6: Observable[A6] + ): Observable[(A1, A2, A3, A4, A5, A6)] = new builders.Zip6Observable(oa1, oa2, oa3, oa4, oa5, oa6)((a1, a2, a3, a4, a5, a6) => (a1, a2, a3, a4, a5, a6)) /** Creates a new observable from five observable sequences @@ -5939,7 +5979,8 @@ object Observable extends ObservableDeprecatedBuilders { oa3: Observable[A3], oa4: Observable[A4], oa5: Observable[A5], - oa6: Observable[A6])(f: (A1, A2, A3, A4, A5, A6) => R): Observable[R] = + oa6: Observable[A6] + )(f: (A1, A2, A3, A4, A5, A6) => R): Observable[R] = new builders.Zip6Observable(oa1, oa2, oa3, oa4, oa5, oa6)(f) /** Given an observable sequence, it [[Observable!.zip zips]] them @@ -6063,7 +6104,8 @@ object Observable extends ObservableDeprecatedBuilders { * - ... */ def resourceCaseF[F[_], A](acquire: F[A])(release: (A, ExitCase[Throwable]) => F[Unit])(implicit - F: TaskLike[F]): Observable[A] = + F: TaskLike[F] + ): Observable[A] = resourceCase(F(acquire))((a, e) => F(release(a, e))) /** Creates a combined observable from 2 source observables. @@ -6120,7 +6162,8 @@ object Observable extends ObservableDeprecatedBuilders { def combineLatest3[A1, A2, A3]( oa1: Observable[A1], oa2: Observable[A2], - oa3: Observable[A3]): Observable[(A1, A2, A3)] = + oa3: Observable[A3] + ): Observable[(A1, A2, A3)] = new builders.CombineLatest3Observable(oa1, oa2, oa3)((a1, a2, a3) => (a1, a2, a3)) /** Creates a combined observable from 3 source observables. @@ -6133,7 +6176,8 @@ object Observable extends ObservableDeprecatedBuilders { * least one item). */ def combineLatestMap3[A1, A2, A3, R](a1: Observable[A1], a2: Observable[A2], a3: Observable[A3])( - f: (A1, A2, A3) => R): Observable[R] = + f: (A1, A2, A3) => R + ): Observable[R] = new builders.CombineLatest3Observable[A1, A2, A3, R](a1, a2, a3)(f) /** Creates a combined observable from 4 source observables. @@ -6149,7 +6193,8 @@ object Observable extends ObservableDeprecatedBuilders { oa1: Observable[A1], oa2: Observable[A2], oa3: Observable[A3], - oa4: Observable[A4]): Observable[(A1, A2, A3, A4)] = + oa4: Observable[A4] + ): Observable[(A1, A2, A3, A4)] = new builders.CombineLatest4Observable(oa1, oa2, oa3, oa4)((a1, a2, a3, a4) => (a1, a2, a3, a4)) /** Creates a combined observable from 4 source observables. @@ -6165,7 +6210,8 @@ object Observable extends ObservableDeprecatedBuilders { a1: Observable[A1], a2: Observable[A2], a3: Observable[A3], - a4: Observable[A4])(f: (A1, A2, A3, A4) => R): Observable[R] = + a4: Observable[A4] + )(f: (A1, A2, A3, A4) => R): Observable[R] = new builders.CombineLatest4Observable[A1, A2, A3, A4, R](a1, a2, a3, a4)(f) /** Creates a combined observable from 5 source observables. @@ -6182,7 +6228,8 @@ object Observable extends ObservableDeprecatedBuilders { oa2: Observable[A2], oa3: Observable[A3], oa4: Observable[A4], - oa5: Observable[A5]): Observable[(A1, A2, A3, A4, A5)] = + oa5: Observable[A5] + ): Observable[(A1, A2, A3, A4, A5)] = new builders.CombineLatest5Observable(oa1, oa2, oa3, oa4, oa5)((a1, a2, a3, a4, a5) => (a1, a2, a3, a4, a5)) /** Creates a combined observable from 5 source observables. @@ -6199,7 +6246,8 @@ object Observable extends ObservableDeprecatedBuilders { a2: Observable[A2], a3: Observable[A3], a4: Observable[A4], - a5: Observable[A5])(f: (A1, A2, A3, A4, A5) => R): Observable[R] = + a5: Observable[A5] + )(f: (A1, A2, A3, A4, A5) => R): Observable[R] = new builders.CombineLatest5Observable[A1, A2, A3, A4, A5, R](a1, a2, a3, a4, a5)(f) /** Creates a combined observable from 6 source observables. @@ -6217,9 +6265,11 @@ object Observable extends ObservableDeprecatedBuilders { oa3: Observable[A3], oa4: Observable[A4], oa5: Observable[A5], - oa6: Observable[A6]): Observable[(A1, A2, A3, A4, A5, A6)] = + oa6: Observable[A6] + ): Observable[(A1, A2, A3, A4, A5, A6)] = new builders.CombineLatest6Observable(oa1, oa2, oa3, oa4, oa5, oa6)((a1, a2, a3, a4, a5, a6) => - (a1, a2, a3, a4, a5, a6)) + (a1, a2, a3, a4, a5, a6) + ) /** Creates a combined observable from 6 source observables. * @@ -6236,7 +6286,8 @@ object Observable extends ObservableDeprecatedBuilders { a3: Observable[A3], a4: Observable[A4], a5: Observable[A5], - a6: Observable[A6])(f: (A1, A2, A3, A4, A5, A6) => R): Observable[R] = + a6: Observable[A6] + )(f: (A1, A2, A3, A4, A5, A6) => R): Observable[R] = new builders.CombineLatest6Observable[A1, A2, A3, A4, A5, A6, R](a1, a2, a3, a4, a5, a6)(f) /** Given an observable sequence, it combines them together @@ -6288,7 +6339,7 @@ object Observable extends ObservableDeprecatedBuilders { * */ def firstStartedOf[A](source: Observable[A]*): Observable[A] = - new builders.FirstStartedObservable(source: _*) + new builders.FirstStartedObservable(source*) /** Implicit type class instances for [[Observable]]. */ implicit val catsInstances: CatsInstances = @@ -6334,15 +6385,18 @@ object Observable extends ObservableDeprecatedBuilders { override def apply[A](task: Task[A]): Observable[A] = Observable.fromTask(task) override def bracketCase[A, B](acquire: Observable[A])(use: A => Observable[B])( - release: (A, ExitCase[Throwable]) => Observable[Unit]): Observable[B] = + release: (A, ExitCase[Throwable]) => Observable[Unit] + ): Observable[B] = acquire.bracketCase(use)((a, e) => release(a, e).completedL) override def bracket[A, B](acquire: Observable[A])(use: A => Observable[B])( - release: A => Observable[Unit]): Observable[B] = + release: A => Observable[Unit] + ): Observable[B] = acquire.bracket(use)(release.andThen(_.completedL)) override def guarantee[A](fa: Observable[A])(finalizer: Observable[Unit]): Observable[A] = fa.guarantee(finalizer.completedL) override def guaranteeCase[A](fa: Observable[A])( - finalizer: ExitCase[Throwable] => Observable[Unit]): Observable[A] = + finalizer: ExitCase[Throwable] => Observable[Unit] + ): Observable[A] = fa.guaranteeCase(e => finalizer(e).completedL) override def uncancelable[A](fa: Observable[A]): Observable[A] = fa.uncancelable @@ -6359,7 +6413,7 @@ object Observable extends ObservableDeprecatedBuilders { implicit val observableNonEmptyParallel: NonEmptyParallel.Aux[Observable, CombineObservable.Type] = new NonEmptyParallel[Observable] { import CombineObservable.unwrap - import CombineObservable.{apply => wrap} + import CombineObservable.{ apply => wrap } override type F[A] = CombineObservable.Type[A] diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/ObservableLike.scala b/monix-reactive/shared/src/main/scala/monix/reactive/ObservableLike.scala index 65d84bb0a..9d7b7984a 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/ObservableLike.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/ObservableLike.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,11 @@ package monix.reactive -import cats.{~>, Eval} -import cats.effect.{IO, SyncIO} -import monix.eval.{Coeval, Task, TaskLike} +import cats.{ ~>, Eval } +import cats.effect.{ IO, SyncIO } +import monix.eval.{ Coeval, Task, TaskLike } import monix.reactive.internal.builders.EvalAlwaysObservable -import org.reactivestreams.{Publisher => RPublisher} +import org.reactivestreams.{ Publisher => RPublisher } import scala.annotation.implicitNotFound import scala.concurrent.Future diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/Observer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/Observer.scala index 65dae4634..97422ea26 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/Observer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/Observer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,16 +18,17 @@ package monix.reactive import java.io.PrintStream -import monix.execution.Ack.{Continue, Stop} + +import monix.execution.Ack.{ Continue, Stop } import monix.execution._ import monix.execution.cancelables.BooleanCancelable import monix.execution.internal.Platform import monix.reactive.internal.rstreams._ import monix.reactive.observers.Subscriber -import org.reactivestreams.{Subscriber => RSubscriber} +import org.reactivestreams.{ Subscriber => RSubscriber } import scala.annotation.tailrec -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.util.Success import scala.util.control.NonFatal @@ -100,7 +101,7 @@ object Observer { def stopped[A]: Observer.Sync[A] = stoppedRef // Reusable reference - private[this] val stoppedRef: Observer.Sync[Any] = + private val stoppedRef: Observer.Sync[Any] = new Observer.Sync[Any] { def onNext(elem: Any): Ack = Stop def onError(ex: Throwable): Unit = () @@ -123,7 +124,8 @@ object Observer { * Monix Rx implementation. */ def fromReactiveSubscriber[A](subscriber: RSubscriber[A], subscription: Cancelable)( - implicit s: Scheduler): Observer[A] = + implicit s: Scheduler + ): Observer[A] = ReactiveSubscriberAsMonixSubscriber(subscriber, subscription) /** Transforms the source [[Observer]] into a `org.reactivestreams.Subscriber` @@ -164,7 +166,8 @@ object Observer { * @param iterable is the collection of items to push downstream */ def feed[A](target: Observer[A], subscription: BooleanCancelable, iterable: Iterable[A])( - implicit s: Scheduler): Future[Ack] = { + implicit s: Scheduler + ): Future[Ack] = { try feed(target, subscription, iterable.iterator) catch { @@ -189,11 +192,12 @@ object Observer { * @param iterator is the collection of items to push downstream */ def feed[A](target: Observer[A], subscription: BooleanCancelable, iterator: Iterator[A])( - implicit s: Scheduler): Future[Ack] = { + implicit s: Scheduler + ): Future[Ack] = { def scheduleFeedLoop(promise: Promise[Ack], iterator: Iterator[A]): Future[Ack] = { s.execute(new Runnable { - private[this] val em = s.executionModel + private val em = s.executionModel @tailrec def fastLoop(syncIndex: Int): Unit = { @@ -334,7 +338,7 @@ object Observer { private[reactive] class DumpObserver[-A](prefix: String, out: PrintStream) extends Observer.Sync[A] { - private[this] var pos = 0 + private var pos = 0 def onNext(elem: A): Ack = { out.println(s"$pos: $prefix --> $elem") @@ -353,9 +357,9 @@ object Observer { } } - private[this] final class ContravariantObserver[A, B](source: Observer[A])(f: B => A) extends Observer[B] { + private final class ContravariantObserver[A, B](source: Observer[A])(f: B => A) extends Observer[B] { // For protecting the contract - private[this] var isDone = false + private var isDone = false override def onNext(elem: B): Future[Ack] = { if (isDone) Stop diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/OverflowStrategy.scala b/monix-reactive/shared/src/main/scala/monix/reactive/OverflowStrategy.scala index 1afda71db..20c73c71b 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/OverflowStrategy.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/OverflowStrategy.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -196,6 +196,6 @@ object OverflowStrategy { final def Default[A]: OverflowStrategy[A] = defaultInstance - private[this] val defaultInstance: OverflowStrategy[Nothing] = + private val defaultInstance: OverflowStrategy[Nothing] = BackPressure(bufferSize = Platform.recommendedBatchSize * 2) } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/Pipe.scala b/monix-reactive/shared/src/main/scala/monix/reactive/Pipe.scala index dc125181a..977fb3b0e 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/Pipe.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/Pipe.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,13 +18,13 @@ package monix.reactive import monix.execution.ChannelType.MultiProducer -import monix.execution.{ChannelType, Scheduler} +import monix.execution.{ ChannelType, Scheduler } import scala.util.control.NonFatal import monix.reactive.Observable.Operator -import monix.reactive.OverflowStrategy.{Synchronous, Unbounded} -import monix.reactive.Pipe.{LiftedPipe, TransformedPipe} -import monix.reactive.observers.{BufferedSubscriber, Subscriber} +import monix.reactive.OverflowStrategy.{ Synchronous, Unbounded } +import monix.reactive.Pipe.{ LiftedPipe, TransformedPipe } +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } import monix.reactive.subjects._ /** Represents a factory for an input/output channel for @@ -48,7 +48,7 @@ abstract class Pipe[I, +O] extends Serializable { def multicast(implicit s: Scheduler): (Observer[I], Observable[O]) = { val (in, out) = unicast val proc = PublishSubject[O]() - out.unsafeSubscribeFn(Subscriber(proc, s)) + val _ = out.unsafeSubscribeFn(Subscriber(proc, s)) (in, proc) } @@ -82,7 +82,8 @@ abstract class Pipe[I, +O] extends Serializable { * can be multi producer (the default) or single producer */ def concurrent(strategy: Synchronous[I], producerType: ChannelType.ProducerSide)( - implicit s: Scheduler): (Observer.Sync[I], Observable[O]) = { + implicit s: Scheduler + ): (Observer.Sync[I], Observable[O]) = { val (in, out) = multicast(s) val buffer = BufferedSubscriber.synchronous[I](Subscriber(in, s), strategy, producerType) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/instances/CatsProfunctorForSubject.scala b/monix-reactive/shared/src/main/scala/monix/reactive/instances/CatsProfunctorForSubject.scala index c37e8fa90..6754fcdd0 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/instances/CatsProfunctorForSubject.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/instances/CatsProfunctorForSubject.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.instances import cats.arrow.Profunctor import monix.execution.Ack.Stop -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.observers.Subscriber import monix.reactive.subjects.Subject diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/AsyncStateActionObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/AsyncStateActionObservable.scala index 5a954339c..59a6abbf0 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/AsyncStateActionObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/AsyncStateActionObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.builders import monix.execution.Callback import monix.eval.Task -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.Cancelable import scala.util.control.NonFatal import monix.reactive.Observable @@ -47,17 +47,18 @@ private[reactive] final class AsyncStateActionObservable[S, A](seed: => S, f: S def loop(subscriber: Subscriber[A], state: S): Task[Unit] = try f(state).redeemWith( - { ex => - subscriber.onError(ex) - Task.unit - }, { - case (a, newState) => - Task.fromFuture(subscriber.onNext(a)).flatMap { - case Continue => loop(subscriber, newState) - case Stop => Task.unit - } - } - ) + { ex => + subscriber.onError(ex) + Task.unit + }, + { + case (a, newState) => + Task.fromFuture(subscriber.onNext(a)).flatMap { + case Continue => loop(subscriber, newState) + case Stop => Task.unit + } + } + ) catch { case ex if NonFatal(ex) => Task.raiseError(ex) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/BufferedIteratorAsObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/BufferedIteratorAsObservable.scala index 637f1f4f8..59cdac73a 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/BufferedIteratorAsObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/BufferedIteratorAsObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,25 +17,25 @@ package monix.reactive.internal.builders -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.atomic.Atomic import monix.execution.cancelables.BooleanCancelable import monix.execution.compat.internal.toSeq import monix.execution.exceptions.APIContractViolationException -import monix.execution.{Ack, Cancelable, ExecutionModel, Scheduler} +import monix.execution.{ Ack, Cancelable, ExecutionModel, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.annotation.tailrec import scala.concurrent.Future import scala.util.control.NonFatal -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } private[reactive] final class BufferedIteratorAsObservable[A](iterator: Iterator[A], bufferSize: Int) extends Observable[Seq[A]] { require(bufferSize > 0, "bufferSize must be strictly positive") - private[this] val wasSubscribed = Atomic(false) + private val wasSubscribed = Atomic(false) def unsafeSubscribeFn(out: Subscriber[Seq[A]]): Cancelable = { if (wasSubscribed.getAndSet(true)) { @@ -47,7 +47,7 @@ private[reactive] final class BufferedIteratorAsObservable[A](iterator: Iterator } private def startLoop(subscriber: Subscriber[Seq[A]]): Cancelable = { - import subscriber.{scheduler => s} + import subscriber.{ scheduler => s } // Protect against contract violations - we are only allowed to // call onError if no other terminal event has been called. var streamErrors = true @@ -92,7 +92,8 @@ private[reactive] final class BufferedIteratorAsObservable[A](iterator: Iterator iter: Iterator[A], out: Subscriber[Seq[A]], c: BooleanCancelable, - em: ExecutionModel)(implicit s: Scheduler): Unit = { + em: ExecutionModel + )(implicit s: Scheduler): Unit = { ack.onComplete { case Success(next) => @@ -127,7 +128,8 @@ private[reactive] final class BufferedIteratorAsObservable[A](iterator: Iterator out: Subscriber[Seq[A]], c: BooleanCancelable, em: ExecutionModel, - syncIndex: Int)(implicit s: Scheduler): Unit = { + syncIndex: Int + )(implicit s: Scheduler): Unit = { // The result of onNext calls, on which we must do back-pressure var ack: Future[Ack] = Continue // We do not want to catch errors from our interaction with our diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CharsReaderObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CharsReaderObservable.scala index 73362b941..905de3666 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CharsReaderObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CharsReaderObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.internal.builders import java.io.Reader import java.util -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.atomic.Atomic import monix.execution.cancelables.BooleanCancelable import monix.execution._ @@ -32,14 +32,14 @@ import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.annotation.tailrec -import scala.concurrent.{blocking, Future} -import scala.util.{Failure, Success} +import scala.concurrent.{ blocking, Future } +import scala.util.{ Failure, Success } private[reactive] final class CharsReaderObservable(in: Reader, chunkSize: Int) extends Observable[Array[Char]] { require(chunkSize > 0, "chunkSize > 0") - private[this] val wasSubscribed = Atomic(false) + private val wasSubscribed = Atomic(false) def unsafeSubscribeFn(out: Subscriber[Array[Char]]): Cancelable = { if (!wasSubscribed.compareAndSet(false, true)) { @@ -61,7 +61,8 @@ private[reactive] final class CharsReaderObservable(in: Reader, chunkSize: Int) b: Array[Char], out: Subscriber[Array[Char]], c: BooleanCancelable, - em: ExecutionModel)(implicit s: Scheduler): Unit = { + em: ExecutionModel + )(implicit s: Scheduler): Unit = { ack.onComplete { case Success(next) => @@ -82,7 +83,8 @@ private[reactive] final class CharsReaderObservable(in: Reader, chunkSize: Int) out: Subscriber[Array[Char]], c: BooleanCancelable, em: ExecutionModel, - syncIndex: Int)(implicit s: Scheduler): Unit = { + syncIndex: Int + )(implicit s: Scheduler): Unit = { // Dealing with mutable status in order to keep the // loop tail-recursive :-( diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest2Observable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest2Observable.scala index 180b3b190..aa46dbe12 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest2Observable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest2Observable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,8 +17,9 @@ package monix.reactive.internal.builders -import monix.execution.{Ack, Cancelable, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import monix.execution.{ Ack, Cancelable } +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import monix.execution.cancelables.CompositeCancelable import scala.util.control.NonFatal @@ -29,8 +30,8 @@ import scala.concurrent.Future import scala.util.Success private[reactive] final class CombineLatest2Observable[A1, A2, +R](obsA1: Observable[A1], obsA2: Observable[A2])( - f: (A1, A2) => R) - extends Observable[R] { + f: (A1, A2) => R +) extends Observable[R] { def unsafeSubscribeFn(out: Subscriber[R]): Cancelable = { import out.scheduler diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest3Observable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest3Observable.scala index a54a39c70..c7b4ac6aa 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest3Observable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest3Observable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,8 +17,9 @@ package monix.reactive.internal.builders -import monix.execution.{Ack, Cancelable, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import monix.execution.{ Ack, Cancelable } +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import monix.execution.cancelables.CompositeCancelable import scala.util.control.NonFatal @@ -31,7 +32,8 @@ import scala.util.Success private[reactive] final class CombineLatest3Observable[A1, A2, A3, +R]( obsA1: Observable[A1], obsA2: Observable[A2], - obsA3: Observable[A3])(f: (A1, A2, A3) => R) + obsA3: Observable[A3] +)(f: (A1, A2, A3) => R) extends Observable[R] { def unsafeSubscribeFn(out: Subscriber[R]): Cancelable = { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest4Observable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest4Observable.scala index 315bfa798..10517e87e 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest4Observable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest4Observable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,9 +18,9 @@ package monix.reactive.internal.builders import monix.execution.cancelables.CompositeCancelable -import monix.execution.{Ack, Cancelable, Scheduler} -import monix.execution.Ack.{Continue, Stop} - +import monix.execution.{ Ack, Cancelable } +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import scala.util.control.NonFatal import monix.reactive.Observable import monix.reactive.observers.Subscriber @@ -32,7 +32,8 @@ private[reactive] final class CombineLatest4Observable[A1, A2, A3, A4, +R]( obsA1: Observable[A1], obsA2: Observable[A2], obsA3: Observable[A3], - obsA4: Observable[A4])(f: (A1, A2, A3, A4) => R) + obsA4: Observable[A4] +)(f: (A1, A2, A3, A4) => R) extends Observable[R] { lock => def unsafeSubscribeFn(out: Subscriber[R]): Cancelable = { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest5Observable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest5Observable.scala index a60ebd8ae..37dd182b5 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest5Observable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest5Observable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,8 +17,9 @@ package monix.reactive.internal.builders -import monix.execution.{Ack, Cancelable, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import monix.execution.{ Ack, Cancelable } +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import monix.execution.cancelables.CompositeCancelable import scala.util.control.NonFatal @@ -33,7 +34,8 @@ private[reactive] final class CombineLatest5Observable[A1, A2, A3, A4, A5, +R]( obsA2: Observable[A2], obsA3: Observable[A3], obsA4: Observable[A4], - obsA5: Observable[A5])(f: (A1, A2, A3, A4, A5) => R) + obsA5: Observable[A5] +)(f: (A1, A2, A3, A4, A5) => R) extends Observable[R] { def unsafeSubscribeFn(out: Subscriber[R]): Cancelable = { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest6Observable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest6Observable.scala index 546f7a2ca..19aae51a3 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest6Observable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatest6Observable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,8 +17,9 @@ package monix.reactive.internal.builders -import monix.execution.{Ack, Cancelable, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import monix.execution.{ Ack, Cancelable } +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import monix.execution.cancelables.CompositeCancelable import scala.util.control.NonFatal @@ -34,7 +35,8 @@ private[reactive] final class CombineLatest6Observable[A1, A2, A3, A4, A5, A6, + obsA3: Observable[A3], obsA4: Observable[A4], obsA5: Observable[A5], - obsA6: Observable[A6])(f: (A1, A2, A3, A4, A5, A6) => R) + obsA6: Observable[A6] +)(f: (A1, A2, A3, A4, A5, A6) => R) extends Observable[R] { def unsafeSubscribeFn(out: Subscriber[R]): Cancelable = { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatestListObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatestListObservable.scala index 3f3a8f2ed..9ec237c7c 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatestListObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CombineLatestListObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,9 @@ package monix.reactive.internal.builders -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.cancelables.CompositeCancelable -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ConsObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ConsObservable.scala index 933ae458e..f9be89d83 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ConsObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ConsObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,31 +18,30 @@ package monix.reactive.internal.builders import monix.execution.Cancelable -import monix.execution.cancelables.{AssignableCancelable, MultiAssignCancelable, SingleAssignCancelable} +import monix.execution.cancelables.{ AssignableCancelable, MultiAssignCancelable, SingleAssignCancelable } import monix.reactive.Observable import monix.reactive.observables.ChainedObservable -import monix.reactive.observables.ChainedObservable.{subscribe => chain} +import monix.reactive.observables.ChainedObservable.{ subscribe => chain } import monix.reactive.observers.Subscriber private[reactive] final class ConsObservable[+A](head: A, tail: Observable[A]) extends ChainedObservable[A] { def unsafeSubscribeFn(conn: AssignableCancelable.Multi, out: Subscriber[A]): Unit = { - import out.{scheduler => s} - out.onNext(head).syncOnContinue(chain(tail, conn, out))(s) + import out.scheduler + val _ = out.onNext(head).syncOnContinue(chain(tail, conn, out)) () } private def simpleSubscribe(conn: SingleAssignCancelable, out: Subscriber[A]): Unit = { import out.scheduler - out.onNext(head).syncOnContinue { + val _ = out.onNext(head).syncOnContinue { conn := tail.unsafeSubscribeFn(out) () } - () } override def unsafeSubscribeFn(out: Subscriber[A]): Cancelable = { - if (!tail.isInstanceOf[ChainedObservable[_]]) { + if (!tail.isInstanceOf[ChainedObservable[?]]) { val conn = SingleAssignCancelable() simpleSubscribe(conn, out) conn diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CreateObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CreateObservable.scala index 7d0a9529c..5c0cd52e9 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CreateObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/CreateObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,17 +17,17 @@ package monix.reactive.internal.builders -import monix.execution.{Cancelable, ChannelType} +import monix.execution.{ Cancelable, ChannelType } import scala.util.control.NonFatal -import monix.reactive.observers.{BufferedSubscriber, Subscriber} -import monix.reactive.{Observable, OverflowStrategy} +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } +import monix.reactive.{ Observable, OverflowStrategy } /** Implementation for [[monix.reactive.Observable.create]]. */ private[reactive] final class CreateObservable[+A]( overflowStrategy: OverflowStrategy.Synchronous[A], producerType: ChannelType.ProducerSide, - f: Subscriber.Sync[A] => Cancelable) - extends Observable[A] { + f: Subscriber.Sync[A] => Cancelable +) extends Observable[A] { def unsafeSubscribeFn(subscriber: Subscriber[A]): Cancelable = { val out = BufferedSubscriber.synchronous(subscriber, overflowStrategy, producerType) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/DeferObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/DeferObservable.scala index ed3155529..e1c3ad16c 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/DeferObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/DeferObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,20 +18,19 @@ package monix.reactive.internal.builders import monix.execution.Cancelable -import monix.execution.cancelables.{AssignableCancelable, MultiAssignCancelable} +import monix.execution.cancelables.{ AssignableCancelable, MultiAssignCancelable } import scala.util.control.NonFatal import monix.reactive.Observable import monix.reactive.observables.ChainedObservable -import monix.reactive.observables.ChainedObservable.{subscribe => chain} +import monix.reactive.observables.ChainedObservable.{ subscribe => chain } import monix.reactive.observers.Subscriber private[reactive] final class DeferObservable[+A](factory: () => Observable[A]) extends ChainedObservable[A] { - override def unsafeSubscribeFn(out: Subscriber[A]): Cancelable = { val fa = try factory() catch { case e if NonFatal(e) => Observable.raiseError(e) } - if (fa.isInstanceOf[ChainedObservable[_]]) { + if (fa.isInstanceOf[ChainedObservable[?]]) { val ch = fa.asInstanceOf[ChainedObservable[A]] val conn = MultiAssignCancelable() ch.unsafeSubscribeFn(conn, out) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/EmptyObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/EmptyObservable.scala index 565ab85b5..312804695 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/EmptyObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/EmptyObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ErrorObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ErrorObservable.scala index 3c3d55209..eaf6d8d87 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ErrorObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ErrorObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/EvalAlwaysObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/EvalAlwaysObservable.scala index 8c462474c..e780fde10 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/EvalAlwaysObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/EvalAlwaysObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,6 +17,7 @@ package monix.reactive.internal.builders +import scala.annotation.nowarn import monix.execution.Cancelable import scala.util.control.NonFatal import monix.reactive.Observable @@ -25,6 +26,7 @@ import monix.reactive.observers.Subscriber /** An observable that evaluates the given by-name argument, * and emits it. */ +@nowarn("msg=unused value of type") private[reactive] final class EvalAlwaysObservable[+A](f: () => A) extends Observable[A] { def unsafeSubscribeFn(subscriber: Subscriber[A]): Cancelable = { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/EvalOnceObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/EvalOnceObservable.scala index 6347e0d94..0feb45f81 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/EvalOnceObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/EvalOnceObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,6 +17,7 @@ package monix.reactive.internal.builders +import scala.annotation.nowarn import monix.execution.Cancelable import scala.util.control.NonFatal import monix.reactive.Observable @@ -25,11 +26,12 @@ import monix.reactive.observers.Subscriber /** An observable that evaluates the given by-name argument, * and emits it. */ +@nowarn("msg=unused value of type") private[reactive] final class EvalOnceObservable[A](a: => A) extends Observable[A] { - private[this] var result: A = _ - private[this] var errorThrown: Throwable = null - @volatile private[this] var hasResult = false + private var result: A = null.asInstanceOf[A] + private var errorThrown: Throwable = null + @volatile private var hasResult = false private def signalResult(out: Subscriber[A], value: A, ex: Throwable): Unit = { if (ex == null) { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ExecuteAsyncObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ExecuteAsyncObservable.scala index f0db9495b..ad10da69d 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ExecuteAsyncObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ExecuteAsyncObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ExecuteWithModelObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ExecuteWithModelObservable.scala index 798d39dc0..c724f40f0 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ExecuteWithModelObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ExecuteWithModelObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,8 @@ package monix.reactive.internal.builders import scala.util.control.NonFatal -import monix.execution.{Ack, Cancelable, ExecutionModel, Scheduler} +import monix.execution.{ Ack, Cancelable, ExecutionModel } +import monix.execution.Scheduler import monix.reactive.Observable import monix.reactive.observers.Subscriber diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/FirstStartedObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/FirstStartedObservable.scala index 8c9c8a863..8ff3fd9f7 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/FirstStartedObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/FirstStartedObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,12 +19,12 @@ package monix.reactive.internal.builders import monix.execution.Ack.Stop import monix.execution.atomic.PaddingStrategy.NoPadding -import monix.execution.atomic.{Atomic, AtomicInt} +import monix.execution.atomic.{ Atomic, AtomicInt } import monix.execution.cancelables.CompositeCancelable -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.observers.Subscriber -import monix.reactive.{Observable, Observer} -import scala.concurrent.{Future, Promise} +import monix.reactive.{ Observable, Observer } +import scala.concurrent.{ Future, Promise } private[reactive] final class FirstStartedObservable[A](source: Observable[A]*) extends Observable[A] { @@ -68,11 +68,12 @@ private[reactive] final class FirstStartedObservable[A](source: Observable[A]*) observer: Observer[A], finishLine: AtomicInt, idx: Int, - p: Promise[Int])(implicit s: Scheduler): Cancelable = { + p: Promise[Int] + )(implicit s: Scheduler): Cancelable = { observable.unsafeSubscribeFn(new Observer[A] { // for fast path - private[this] var finishLineCache = -1 + private var finishLineCache = -1 private def shouldStream(): Boolean = { if (finishLineCache != idx) finishLineCache = finishLine.get() diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/FutureAsObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/FutureAsObservable.scala index db3750dfd..8622a2cd6 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/FutureAsObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/FutureAsObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,19 +17,21 @@ package monix.reactive.internal.builders +import scala.annotation.nowarn import scala.util.control.NonFatal -import monix.execution.{Cancelable, CancelableFuture} +import monix.execution.{ Cancelable, CancelableFuture } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.concurrent.Future -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } /** Converts any `Future` into an observable */ +@nowarn("msg=unused value of type") private[reactive] final class FutureAsObservable[A](factory: => Future[A]) extends Observable[A] { def unsafeSubscribeFn(subscriber: Subscriber[A]): Cancelable = { - import subscriber.{scheduler => s} + import subscriber.{ scheduler => s } // Protects calls to user code var streamErrors = true try { @@ -54,7 +56,7 @@ private[reactive] final class FutureAsObservable[A](factory: => Future[A]) exten } evaluated match { - case c: CancelableFuture[_] => c + case c: CancelableFuture[?] => c case _ => Cancelable.empty } } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/InputStreamObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/InputStreamObservable.scala index 49b5da4b4..6a9e34c52 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/InputStreamObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/InputStreamObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.internal.builders import java.io.InputStream import java.util -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.cancelables.BooleanCancelable import monix.execution._ import monix.reactive.Observable @@ -30,15 +30,15 @@ import monix.execution.exceptions.APIContractViolationException import monix.execution.internal.Platform import scala.annotation.tailrec -import scala.concurrent.{blocking, Future} +import scala.concurrent.{ blocking, Future } import scala.util.control.NonFatal -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } private[reactive] final class InputStreamObservable(in: InputStream, chunkSize: Int) extends Observable[Array[Byte]] { require(chunkSize > 0, "chunkSize > 0") - private[this] val wasSubscribed = Atomic(false) + private val wasSubscribed = Atomic(false) def unsafeSubscribeFn(out: Subscriber[Array[Byte]]): Cancelable = { if (wasSubscribed.compareAndSet(expect = false, update = true)) { @@ -61,7 +61,8 @@ private[reactive] final class InputStreamObservable(in: InputStream, chunkSize: b: Array[Byte], out: Subscriber[Array[Byte]], c: BooleanCancelable, - em: ExecutionModel)(implicit s: Scheduler): Unit = { + em: ExecutionModel + )(implicit s: Scheduler): Unit = { ack.onComplete { case Success(next) => @@ -82,7 +83,8 @@ private[reactive] final class InputStreamObservable(in: InputStream, chunkSize: out: Subscriber[Array[Byte]], c: BooleanCancelable, em: ExecutionModel, - syncIndex: Int)(implicit s: Scheduler): Unit = { + syncIndex: Int + )(implicit s: Scheduler): Unit = { // Dealing with mutable status in order to keep the // loop tail-recursive :-( diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Interleave2Observable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Interleave2Observable.scala index e3910e382..6a56468a9 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Interleave2Observable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Interleave2Observable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,14 +17,16 @@ package monix.reactive.internal.builders -import monix.execution.Ack.{Continue, Stop} +import scala.annotation.nowarn +import monix.execution.Ack.{ Continue, Stop } import monix.execution.cancelables.CompositeCancelable -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable } +import monix.execution.Scheduler import monix.reactive.Observable import monix.reactive.observers.Subscriber +import scala.concurrent.{ Future, Promise } -import scala.concurrent.{Future, Promise} - +@nowarn("msg=unused value of type") private[reactive] final class Interleave2Observable[+A](obsA1: Observable[A], obsA2: Observable[A]) extends Observable[A] { @@ -83,7 +85,8 @@ private[reactive] final class Interleave2Observable[+A](obsA1: Observable[A], ob def onNext(elem: A): Future[Ack] = lock.synchronized { def sendSignal(elem: A): Future[Ack] = lock.synchronized { - if (isDone) Stop else { + if (isDone) Stop + else { downstreamAck = out.onNext(elem) pauseA1 = Promise[Ack]() pauseA2.completeWith(downstreamAck) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/IntervalFixedDelayObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/IntervalFixedDelayObservable.scala index 767bdee76..1b238e791 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/IntervalFixedDelayObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/IntervalFixedDelayObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,25 +18,25 @@ package monix.reactive.internal.builders import monix.execution.cancelables.MultiAssignCancelable -import monix.execution.{Ack, Cancelable} -import monix.execution.Ack.{Continue, Stop} +import monix.execution.{ Ack, Cancelable } +import monix.execution.Ack.{ Continue, Stop } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.concurrent.Future import scala.concurrent.duration.FiniteDuration -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } private[reactive] final class IntervalFixedDelayObservable(initialDelay: FiniteDuration, delay: FiniteDuration) extends Observable[Long] { def unsafeSubscribeFn(subscriber: Subscriber[Long]): Cancelable = { - import subscriber.{scheduler => s} + import subscriber.{ scheduler => s } val o = subscriber val task = MultiAssignCancelable() val runnable = new Runnable { self => - private[this] var counter = 0L + private var counter = 0L def scheduleNext(): Cancelable = { counter += 1 @@ -48,7 +48,7 @@ private[reactive] final class IntervalFixedDelayObservable(initialDelay: FiniteD def asyncScheduleNext(r: Future[Ack]): Unit = r.onComplete { case Success(ack) => - if (ack == Continue) scheduleNext() + if (ack == Continue) { val _ = scheduleNext() } case Failure(ex) => s.reportFailure(ex) } @@ -56,8 +56,7 @@ private[reactive] final class IntervalFixedDelayObservable(initialDelay: FiniteD def run(): Unit = { val ack = o.onNext(counter) if (ack == Continue) { - scheduleNext() - () + val _ = scheduleNext() } else if (ack != Stop) { asyncScheduleNext(ack) } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/IntervalFixedRateObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/IntervalFixedRateObservable.scala index b577ff61a..449b75f5a 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/IntervalFixedRateObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/IntervalFixedRateObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,28 +19,28 @@ package monix.reactive.internal.builders import java.util.concurrent.TimeUnit -import monix.execution.{Ack, Cancelable} -import monix.execution.Ack.{Continue, Stop} +import monix.execution.{ Ack, Cancelable } +import monix.execution.Ack.{ Continue, Stop } import monix.execution.cancelables.MultiAssignCancelable import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.concurrent.Future import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } private[reactive] final class IntervalFixedRateObservable(initialDelay: FiniteDuration, period: FiniteDuration) extends Observable[Long] { override def unsafeSubscribeFn(subscriber: Subscriber[Long]): Cancelable = { - import subscriber.{scheduler => s} + import subscriber.{ scheduler => s } val o = subscriber val task = MultiAssignCancelable() val runnable = new Runnable { self => - private[this] val periodNanos = period.toNanos - private[this] var counter = 0L - private[this] var startedAt = 0L + private val periodNanos = period.toNanos + private var counter = 0L + private var startedAt = 0L def scheduleNext(): Unit = { counter += 1 diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/IterableAsObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/IterableAsObservable.scala index df06ab546..a9fcf5ce2 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/IterableAsObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/IterableAsObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/IteratorAsObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/IteratorAsObservable.scala index edd4471a2..ed094075e 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/IteratorAsObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/IteratorAsObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.reactive.internal.builders -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.cancelables.BooleanCancelable import monix.execution._ import monix.reactive.Observable @@ -27,11 +27,11 @@ import monix.execution.exceptions.APIContractViolationException import scala.util.control.NonFatal import scala.annotation.tailrec import scala.concurrent.Future -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } /** Converts any `Iterator` into an observable */ private[reactive] final class IteratorAsObservable[A](iterator: Iterator[A]) extends Observable[A] { - private[this] val wasSubscribed = Atomic(false) + private val wasSubscribed = Atomic(false) def unsafeSubscribeFn(out: Subscriber[A]): Cancelable = { if (wasSubscribed.getAndSet(true)) { @@ -43,7 +43,7 @@ private[reactive] final class IteratorAsObservable[A](iterator: Iterator[A]) ext } private def startLoop(subscriber: Subscriber[A]): Cancelable = { - import subscriber.{scheduler => s} + import subscriber.{ scheduler => s } // Protect against contract violations - we are only allowed to // call onError if no other terminal event has been called. var streamErrors = true @@ -88,7 +88,8 @@ private[reactive] final class IteratorAsObservable[A](iterator: Iterator[A]) ext iter: Iterator[A], out: Subscriber[A], c: BooleanCancelable, - em: ExecutionModel)(implicit s: Scheduler): Unit = { + em: ExecutionModel + )(implicit s: Scheduler): Unit = { ack.onComplete { case Success(next) => @@ -123,7 +124,8 @@ private[reactive] final class IteratorAsObservable[A](iterator: Iterator[A]) ext out: Subscriber[A], c: BooleanCancelable, em: ExecutionModel, - syncIndex: Int)(implicit s: Scheduler): Unit = { + syncIndex: Int + )(implicit s: Scheduler): Unit = { // The result of onNext calls, on which we must do back-pressure var ack: Future[Ack] = Continue // We do not want to catch errors from our interaction with our diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/LinesReaderObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/LinesReaderObservable.scala index 4cc392c97..242b3e2cc 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/LinesReaderObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/LinesReaderObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,9 @@ package monix.reactive.internal.builders -import java.io.{BufferedReader, Reader} +import java.io.{ BufferedReader, Reader } -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.cancelables.BooleanCancelable import monix.execution._ import monix.reactive.Observable @@ -30,18 +30,18 @@ import monix.execution.internal.Platform import scala.util.control.NonFatal import scala.annotation.tailrec -import scala.concurrent.{blocking, Future} -import scala.util.{Failure, Success} +import scala.concurrent.{ blocking, Future } +import scala.util.{ Failure, Success } private[reactive] final class LinesReaderObservable(reader: Reader) extends Observable[String] { self => - private[this] val in: BufferedReader = + private val in: BufferedReader = if (!reader.isInstanceOf[BufferedReader]) new BufferedReader(reader) else reader.asInstanceOf[BufferedReader] - private[this] val wasSubscribed = Atomic(false) + private val wasSubscribed = Atomic(false) def unsafeSubscribeFn(out: Subscriber[String]): Cancelable = { if (wasSubscribed.getAndSet(true)) { @@ -59,7 +59,8 @@ private[reactive] final class LinesReaderObservable(reader: Reader) extends Obse } private def reschedule(ack: Future[Ack], out: Subscriber[String], c: BooleanCancelable, em: ExecutionModel)( - implicit s: Scheduler): Unit = { + implicit s: Scheduler + ): Unit = { ack.onComplete { case Success(next) => @@ -76,7 +77,8 @@ private[reactive] final class LinesReaderObservable(reader: Reader) extends Obse @tailrec private def fastLoop(out: Subscriber[String], c: BooleanCancelable, em: ExecutionModel, syncIndex: Int)( - implicit s: Scheduler): Unit = { + implicit s: Scheduler + ): Unit = { // Dealing with mutable status in order to keep the // loop tail-recursive :-( diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/MergePrioritizedListObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/MergePrioritizedListObservable.scala index c0b5093b2..672e3ae69 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/MergePrioritizedListObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/MergePrioritizedListObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,14 +17,14 @@ package monix.reactive.internal.builders -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.cancelables.CompositeCancelable -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.collection.mutable -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.util.Success /** Given a sequence of priority/observable pairs, combines them into a new @@ -44,8 +44,8 @@ import scala.util.Success * given source will be in flight at a time. */ private[reactive] final class MergePrioritizedListObservable[A]( - sources: Seq[(Int, Observable[A])]) - extends Observable[A] { + sources: Seq[(Int, Observable[A])] +) extends Observable[A] { override def unsafeSubscribeFn(out: Subscriber[A]): Cancelable = { import out.scheduler @@ -88,12 +88,12 @@ private[reactive] final class MergePrioritizedListObservable[A]( def signalOnNext(): Future[Ack] = { lastAck = lastAck match { case Continue => processNext() - case Stop => Stop + case Stop => Stop case async => async.flatMap { // async execution, we have to re-sync case Continue => lock.synchronized(processNext()) - case Stop => Stop + case Stop => Stop } } lastAck @@ -161,7 +161,7 @@ private[reactive] final class MergePrioritizedListObservable[A]( } else { val p = Promise[Ack]() pq.enqueue(PQElem(elem, p, pri)) - signalOnNext() + val _ = signalOnNext() p.future } } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/NeverObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/NeverObservable.scala index 8aa3978b9..f890d1f11 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/NeverObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/NeverObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/NowObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/NowObservable.scala index 3b280d626..782ef2790 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/NowObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/NowObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,13 @@ package monix.reactive.internal.builders +import scala.annotation.nowarn import monix.execution.Cancelable import monix.reactive.Observable import monix.reactive.observers.Subscriber /** Builds an observable that emits a single strict value. */ +@nowarn("msg=unused value of type") private[reactive] final class NowObservable[+A](elem: A) extends Observable[A] { def unsafeSubscribeFn(subscriber: Subscriber[A]): Cancelable = { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/PaginateEvalObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/PaginateEvalObservable.scala index 2ab6559fd..3371e7bbc 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/PaginateEvalObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/PaginateEvalObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,15 +17,18 @@ package monix.reactive.internal.builders +import scala.annotation.nowarn import monix.eval.Task -import monix.execution.Ack.{Continue, Stop} -import monix.execution.{Callback, Cancelable} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.{ Callback, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.util.control.NonFatal -private[reactive] final class PaginateEvalObservable[S, A](seed: S, f: S => Task[(A, Option[S])]) extends Observable[A] { +@nowarn("msg=unused value of type") +private[reactive] final class PaginateEvalObservable[S, A](seed: S, f: S => Task[(A, Option[S])]) + extends Observable[A] { def unsafeSubscribeFn(subscriber: Subscriber[A]): Cancelable = { import subscriber.scheduler @@ -48,23 +51,24 @@ private[reactive] final class PaginateEvalObservable[S, A](seed: S, f: S => Task def loop(subscriber: Subscriber[A], state: S): Task[Unit] = try f(state).redeemWith( - { ex => - subscriber.onError(ex) - Task.unit - }, { - case (a, Some(newState)) => - Task.fromFuture(subscriber.onNext(a)).flatMap { - case Continue => - loop(subscriber, newState) - case Stop => - Task.unit - } - case (a, None) => - subscriber.onNext(a) - subscriber.onComplete() + { ex => + subscriber.onError(ex) Task.unit - } - ) + }, + { + case (a, Some(newState)) => + Task.fromFuture(subscriber.onNext(a)).flatMap { + case Continue => + loop(subscriber, newState) + case Stop => + Task.unit + } + case (a, None) => + subscriber.onNext(a) + subscriber.onComplete() + Task.unit + } + ) catch { case ex if NonFatal(ex) => Task.raiseError(ex) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/PaginateObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/PaginateObservable.scala index ddc4f4aba..22fd6d01c 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/PaginateObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/PaginateObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,16 +17,18 @@ package monix.reactive.internal.builders -import monix.execution.Ack.{Continue, Stop} +import scala.annotation.nowarn +import monix.execution.Ack.{ Continue, Stop } import monix.execution.cancelables.BooleanCancelable -import monix.execution.{Ack, Cancelable} +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.annotation.tailrec import scala.util.control.NonFatal -import scala.util.{Failure, Try} +import scala.util.{ Failure, Try } +@nowarn("msg=unused value of type") private[reactive] final class PaginateObservable[S, A](seed: => S, f: S => (A, Option[S])) extends Observable[A] { def unsafeSubscribeFn(subscriber: Subscriber[A]): Cancelable = { var streamErrors = true @@ -44,16 +46,16 @@ private[reactive] final class PaginateObservable[S, A](seed: => S, f: S => (A, O } } - private[this] final class StateRunLoop(o: Subscriber[A], c: BooleanCancelable, initialSeed: S, f: S => (A, Option[S])) + private final class StateRunLoop(o: Subscriber[A], c: BooleanCancelable, initialSeed: S, f: S => (A, Option[S])) extends Runnable { self => - import o.{scheduler => s} + import o.{ scheduler => s } - private[this] var seed = initialSeed - private[this] val em = s.executionModel + private var seed = initialSeed + private val em = s.executionModel - private[this] val asyncReschedule: Try[Ack] => Unit = { + private val asyncReschedule: Try[Ack] => Unit = { case Continue.AsSuccess => self.run() case Failure(ex) => diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/PipeThroughSelectorObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/PipeThroughSelectorObservable.scala index 04541a9d0..3958fe573 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/PipeThroughSelectorObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/PipeThroughSelectorObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,20 +17,21 @@ package monix.reactive.internal.builders -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable } +import monix.execution.Scheduler import monix.execution.cancelables.SingleAssignCancelable import scala.util.control.NonFatal import monix.reactive.observers.Subscriber -import monix.reactive.{Observable, Pipe} +import monix.reactive.{ Observable, Pipe } import scala.concurrent.Future private[reactive] final class PipeThroughSelectorObservable[A, B, C]( source: Observable[A], pipe: Pipe[A, B], - f: Observable[B] => Observable[C]) - extends Observable[C] { + f: Observable[B] => Observable[C] +) extends Observable[C] { def unsafeSubscribeFn(out: Subscriber[C]): Cancelable = { import out.scheduler diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RangeObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RangeObservable.scala index 10244d272..5041bf896 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RangeObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RangeObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,15 +17,15 @@ package monix.reactive.internal.builders -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.cancelables.BooleanCancelable -import monix.execution.{Ack, Cancelable, ExecutionModel, Scheduler} +import monix.execution.{ Ack, Cancelable, ExecutionModel, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.annotation.tailrec import scala.concurrent.Future -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } /** Generates ranges */ private[reactive] final class RangeObservable(from: Long, until: Long, step: Long = 1) extends Observable[Long] { @@ -46,7 +46,8 @@ private[reactive] final class RangeObservable(from: Long, until: Long, step: Lon @tailrec private def loop(c: BooleanCancelable, downstream: Subscriber[Long], em: ExecutionModel, from: Long, syncIndex: Int)( - implicit s: Scheduler): Unit = { + implicit s: Scheduler + ): Unit = { val ack = downstream.onNext(from) val nextFrom = from + step @@ -71,7 +72,8 @@ private[reactive] final class RangeObservable(from: Long, until: Long, step: Lon ack: Future[Ack], downstream: Subscriber[Long], em: ExecutionModel, - from: Long)(implicit s: Scheduler): Unit = { + from: Long + )(implicit s: Scheduler): Unit = { ack.onComplete { case Success(success) => diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ReactiveObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ReactiveObservable.scala index 7bc6fe4a8..d40041550 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ReactiveObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ReactiveObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ import monix.execution.rstreams.SingleAssignSubscription import monix.reactive.Observable import monix.reactive.observers.Subscriber import org.reactivestreams -import org.reactivestreams.{Subscription, Publisher => RPublisher} +import org.reactivestreams.{ Publisher => RPublisher, Subscription } /** Implementation for `Observable.fromReactivePublisher` */ private[reactive] final class ReactiveObservable[A](publisher: RPublisher[A], requestCount: Int) extends Observable[A] { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RepeatEvalObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RepeatEvalObservable.scala index 041dc6b19..85c9d0649 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RepeatEvalObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RepeatEvalObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.reactive.internal.builders -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.cancelables.BooleanCancelable import monix.execution._ import scala.util.control.NonFatal @@ -26,7 +26,7 @@ import monix.reactive.observers.Subscriber import scala.annotation.tailrec import scala.concurrent.Future -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } private[reactive] final class RepeatEvalObservable[+A](eval: => A) extends Observable[A] { @@ -38,7 +38,8 @@ private[reactive] final class RepeatEvalObservable[+A](eval: => A) extends Obser } def reschedule(ack: Future[Ack], o: Subscriber[A], c: BooleanCancelable, em: ExecutionModel)( - implicit s: Scheduler): Unit = + implicit s: Scheduler + ): Unit = ack.onComplete { case Success(Continue) => fastLoop(o, c, em, 0) @@ -50,7 +51,8 @@ private[reactive] final class RepeatEvalObservable[+A](eval: => A) extends Obser @tailrec def fastLoop(o: Subscriber[A], c: BooleanCancelable, em: ExecutionModel, syncIndex: Int)( - implicit s: Scheduler): Unit = { + implicit s: Scheduler + ): Unit = { val ack = try o.onNext(eval) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RepeatObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RepeatObservable.scala index e8027b0e1..5fb865096 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RepeatObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RepeatObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ import monix.reactive.observers.Subscriber /** Repeats the given elements */ private[reactive] final class RepeatObservable[A](elems: A*) extends Observable[A] { - private[this] val source = + private val source = if (elems.isEmpty) Observable.empty else if (elems.length == 1) new RepeatOneObservable(elems.head) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RepeatOneObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RepeatOneObservable.scala index 6ba0904b7..d75199759 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RepeatOneObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RepeatOneObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,15 +17,15 @@ package monix.reactive.internal.builders -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.cancelables.BooleanCancelable -import monix.execution.{Ack, Cancelable, ExecutionModel, Scheduler} +import monix.execution.{ Ack, Cancelable, ExecutionModel, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.annotation.tailrec import scala.concurrent.Future -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } private[reactive] final class RepeatOneObservable[A](elem: A) extends Observable[A] { def unsafeSubscribeFn(subscriber: Subscriber[A]): Cancelable = { @@ -36,7 +36,8 @@ private[reactive] final class RepeatOneObservable[A](elem: A) extends Observable } def reschedule(ack: Future[Ack], o: Subscriber[A], c: BooleanCancelable, em: ExecutionModel)( - implicit s: Scheduler): Unit = + implicit s: Scheduler + ): Unit = ack.onComplete { case Success(Continue) => fastLoop(o, c, em, 0) @@ -48,7 +49,8 @@ private[reactive] final class RepeatOneObservable[A](elem: A) extends Observable @tailrec def fastLoop(o: Subscriber[A], c: BooleanCancelable, em: ExecutionModel, syncIndex: Int)( - implicit s: Scheduler): Unit = { + implicit s: Scheduler + ): Unit = { val ack = o.onNext(elem) val nextIndex = diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RepeatedValueObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RepeatedValueObservable.scala index 7c77525c9..442828a8c 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RepeatedValueObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RepeatedValueObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,12 +19,12 @@ package monix.reactive.internal.builders import java.util.concurrent.TimeUnit import monix.execution.cancelables.MultiAssignCancelable -import monix.execution.{Ack, Cancelable, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import monix.execution.{ Ack, Cancelable, Scheduler } +import monix.execution.Ack.{ Continue, Stop } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.concurrent.duration._ -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } private[reactive] final class RepeatedValueObservable[A](initialDelay: FiniteDuration, period: FiniteDuration, unit: A) extends Observable[A] { @@ -43,11 +43,11 @@ private[reactive] final class RepeatedValueObservable[A](initialDelay: FiniteDur task } - private[this] def runnable(subscriber: Subscriber[A], task: MultiAssignCancelable): Runnable = + private def runnable(subscriber: Subscriber[A], task: MultiAssignCancelable): Runnable = new Runnable { self => - private[this] implicit val s: Scheduler = subscriber.scheduler - private[this] val periodMs = period.toMillis - private[this] var startedAt = 0L + private implicit val s: Scheduler = subscriber.scheduler + private val periodMs = period.toMillis + private var startedAt = 0L def syncScheduleNext(): Unit = { val initialDelay = { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ResourceCaseObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ResourceCaseObservable.scala index e40432386..a9f5b3cb1 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ResourceCaseObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/ResourceCaseObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ package builders import cats.effect.ExitCase import monix.execution.Callback import monix.eval.Task -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.Cancelable import monix.execution.cancelables.AssignableCancelable import monix.reactive.observables.ChainedObservable @@ -31,8 +31,8 @@ import scala.util.Success private[reactive] final class ResourceCaseObservable[A]( acquire: Task[A], - release: (A, ExitCase[Throwable]) => Task[Unit]) - extends ChainedObservable[A] { + release: (A, ExitCase[Throwable]) => Task[Unit] +) extends ChainedObservable[A] { def unsafeSubscribeFn(conn: AssignableCancelable.Multi, subscriber: Subscriber[A]): Unit = { implicit val s = subscriber.scheduler diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RunnableObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RunnableObservable.scala index e75728c72..b93f220b0 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RunnableObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/RunnableObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,6 +17,7 @@ package monix.reactive.internal.builders +import scala.annotation.nowarn import monix.execution.Cancelable import scala.util.control.NonFatal import monix.reactive.Observable @@ -25,6 +26,7 @@ import monix.reactive.observers.Subscriber /** An observable that evaluates the given by-name argument, * and emits it. */ +@nowarn("msg=unused value of type") private[reactive] final class RunnableObservable(r: Runnable) extends Observable[Unit] { def unsafeSubscribeFn(subscriber: Subscriber[Unit]): Cancelable = { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/StateActionObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/StateActionObservable.scala index 9613b1c41..1509b605c 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/StateActionObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/StateActionObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,14 +18,14 @@ package monix.reactive.internal.builders import monix.execution.cancelables.BooleanCancelable -import monix.execution.{Ack, Cancelable} -import monix.execution.Ack.{Continue, Stop} +import monix.execution.{ Ack, Cancelable } +import monix.execution.Ack.{ Continue, Stop } import scala.util.control.NonFatal import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.annotation.tailrec -import scala.util.{Failure, Try} +import scala.util.{ Failure, Try } private[reactive] final class StateActionObservable[S, A](seed: => S, f: S => (A, S)) extends Observable[A] { def unsafeSubscribeFn(subscriber: Subscriber[A]): Cancelable = { @@ -44,14 +44,14 @@ private[reactive] final class StateActionObservable[S, A](seed: => S, f: S => (A } } - private[this] final class StateRunLoop(o: Subscriber[A], c: BooleanCancelable, initialSeed: S, f: S => (A, S)) + private final class StateRunLoop(o: Subscriber[A], c: BooleanCancelable, initialSeed: S, f: S => (A, S)) extends Runnable { self => - import o.{scheduler => s} - private[this] var seed = initialSeed - private[this] val em = s.executionModel + import o.{ scheduler => s } + private var seed = initialSeed + private val em = s.executionModel - private[this] val asyncReschedule: Try[Ack] => Unit = { + private val asyncReschedule: Try[Ack] => Unit = { case Continue.AsSuccess => self.run() case Failure(ex) => diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/TailRecMObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/TailRecMObservable.scala index 30eeaa7f7..61106f4fd 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/TailRecMObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/TailRecMObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,19 +17,21 @@ package monix.reactive.internal.builders +import scala.annotation.nowarn import monix.execution.Scheduler -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.atomic.AtomicBoolean -import monix.execution.cancelables.{SingleAssignCancelable, StackedCancelable} +import monix.execution.cancelables.{ SingleAssignCancelable, StackedCancelable } import scala.util.control.NonFatal import monix.execution.schedulers.TrampolineExecutionContext.immediate -import monix.execution.{Ack, Cancelable} +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber -import scala.concurrent.{Future, Promise} -import scala.util.{Failure, Success} +import scala.concurrent.{ Future, Promise } +import scala.util.{ Failure, Success } /** Implementation for `Observable.tailRecM`. */ +@nowarn("msg=unused value of type") private[monix] final class TailRecMObservable[A, B](seed: A, f: A => Observable[Either[A, B]]) extends Observable[B] { def unsafeSubscribeFn(out: Subscriber[B]): Cancelable = { @@ -69,7 +71,7 @@ private[monix] final class TailRecMObservable[A, B](seed: A, f: A => Observable[ val loopSubscriber = new Subscriber[Either[A, B]] { override def scheduler = s - private[this] implicit val s: Scheduler = out.scheduler + private implicit val s: Scheduler = out.scheduler // We need to protect `conn.pop()` - unfortunately // there has to be an order for `push` and `pop` on @@ -79,12 +81,12 @@ private[monix] final class TailRecMObservable[A, B](seed: A, f: A => Observable[ // `onComplete`, unfortunately we need it. Hopefully // on Java 8 it is fast enough as we are doing a // `getAndSet` instead of `compareAndSet`. - private[this] val isActive = AtomicBoolean(true) + private val isActive = AtomicBoolean(true) // Stores the last acknowledgement we received from // `out.onNext` - to be used for applying back-pressure // where needed. - private[this] var lastAck: Future[Ack] = Continue + private var lastAck: Future[Ack] = Continue // Pushes a final result (for this iteration of `loop` at least), // but before that it pops the current cancelable from our diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/TaskAsObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/TaskAsObservable.scala index ec01e91c1..be439c29e 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/TaskAsObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/TaskAsObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,12 +17,14 @@ package monix.reactive.internal.builders +import scala.annotation.nowarn import monix.execution.Cancelable import monix.reactive.Observable import monix.reactive.observers.Subscriber import monix.execution.Callback import monix.eval.Task +@nowarn("msg=unused value of type") private[reactive] final class TaskAsObservable[+A](task: Task[A]) extends Observable[A] { def unsafeSubscribeFn(subscriber: Subscriber[A]): Cancelable = { import subscriber.scheduler diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/UnfoldEvalObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/UnfoldEvalObservable.scala index c46d74760..3f7e04d7b 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/UnfoldEvalObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/UnfoldEvalObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,8 +18,8 @@ package monix.reactive.internal.builders import monix.eval.Task -import monix.execution.Ack.{Continue, Stop} -import monix.execution.{Callback, Cancelable} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.{ Callback, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber @@ -48,22 +48,23 @@ private[reactive] final class UnfoldEvalObservable[S, A](seed: S, f: S => Task[O def loop(subscriber: Subscriber[A], state: S): Task[Unit] = try f(state).redeemWith( - { ex => - subscriber.onError(ex) - Task.unit - }, { - case Some((a, newState)) => - Task.fromFuture(subscriber.onNext(a)).flatMap { - case Continue => - loop(subscriber, newState) - case Stop => - Task.unit - } - case None => - subscriber.onComplete() + { ex => + subscriber.onError(ex) Task.unit - } - ) + }, + { + case Some((a, newState)) => + Task.fromFuture(subscriber.onNext(a)).flatMap { + case Continue => + loop(subscriber, newState) + case Stop => + Task.unit + } + case None => + subscriber.onComplete() + Task.unit + } + ) catch { case ex if NonFatal(ex) => Task.raiseError(ex) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/UnfoldObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/UnfoldObservable.scala index 34c39956e..70c0f4bf2 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/UnfoldObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/UnfoldObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,15 +17,15 @@ package monix.reactive.internal.builders -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.cancelables.BooleanCancelable -import monix.execution.{Ack, Cancelable} +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.annotation.tailrec import scala.util.control.NonFatal -import scala.util.{Failure, Try} +import scala.util.{ Failure, Try } private[reactive] final class UnfoldObservable[S, A](seed: => S, f: S => Option[(A, S)]) extends Observable[A] { def unsafeSubscribeFn(subscriber: Subscriber[A]): Cancelable = { @@ -44,16 +44,16 @@ private[reactive] final class UnfoldObservable[S, A](seed: => S, f: S => Option[ } } - private[this] final class StateRunLoop(o: Subscriber[A], c: BooleanCancelable, initialSeed: S, f: S => Option[(A, S)]) + private final class StateRunLoop(o: Subscriber[A], c: BooleanCancelable, initialSeed: S, f: S => Option[(A, S)]) extends Runnable { self => - import o.{scheduler => s} + import o.{ scheduler => s } - private[this] var seed = initialSeed - private[this] val em = s.executionModel + private var seed = initialSeed + private val em = s.executionModel - private[this] val asyncReschedule: Try[Ack] => Unit = { + private val asyncReschedule: Try[Ack] => Unit = { case Continue.AsSuccess => self.run() case Failure(ex) => diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/UnsafeCreateObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/UnsafeCreateObservable.scala index 6ff1e2b08..692ce9c64 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/UnsafeCreateObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/UnsafeCreateObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,9 @@ package monix.reactive.internal.builders -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import scala.util.control.NonFatal -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.Observable import monix.reactive.internal.builders.UnsafeCreateObservable.SafeSubscriber import monix.reactive.observers.Subscriber @@ -45,7 +45,7 @@ private[reactive] object UnsafeCreateObservable { private final class SafeSubscriber[-A](underlying: Subscriber[A]) extends Subscriber[A] { self => implicit val scheduler: Scheduler = underlying.scheduler - private[this] var isDone = false + private var isDone = false def onNext(elem: A): Future[Ack] = if (isDone) Stop diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip2Observable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip2Observable.scala index 226ac637e..e9ece687f 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip2Observable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip2Observable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,17 +17,18 @@ package monix.reactive.internal.builders +import scala.annotation.nowarn import monix.execution.cancelables.CompositeCancelable -import monix.execution.{Ack, Cancelable, Scheduler} -import monix.execution.Ack.{Continue, Stop} - +import monix.execution.{ Ack, Cancelable, Scheduler } +import monix.execution.Ack.{ Continue, Stop } import scala.util.control.NonFatal import monix.reactive.Observable import monix.reactive.observers.Subscriber -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.util.Success +@nowarn("msg=unused value of type") private[reactive] final class Zip2Observable[A1, A2, +R](obsA1: Observable[A1], obsA2: Observable[A2])(f: (A1, A2) => R) extends Observable[R] { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip3Observable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip3Observable.scala index cd7fc3fcc..148e5d39a 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip3Observable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip3Observable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,21 +17,24 @@ package monix.reactive.internal.builders -import monix.execution.{Ack, Cancelable, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import scala.annotation.nowarn +import monix.execution.{ Ack, Cancelable, Scheduler } +import monix.execution.Ack.{ Continue, Stop } import monix.execution.cancelables.CompositeCancelable import scala.util.control.NonFatal import monix.reactive.Observable import monix.reactive.observers.Subscriber -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.util.Success +@nowarn("msg=unused value of type") private[reactive] final class Zip3Observable[A1, A2, A3, +R]( obsA1: Observable[A1], obsA2: Observable[A2], - obsA3: Observable[A3])(f: (A1, A2, A3) => R) + obsA3: Observable[A3] +)(f: (A1, A2, A3) => R) extends Observable[R] { def unsafeSubscribeFn(out: Subscriber[R]): Cancelable = { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip4Observable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip4Observable.scala index dbf739942..d7f71e16b 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip4Observable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip4Observable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,22 +17,25 @@ package monix.reactive.internal.builders -import monix.execution.{Ack, Cancelable, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import scala.annotation.nowarn +import monix.execution.{ Ack, Cancelable, Scheduler } +import monix.execution.Ack.{ Continue, Stop } import monix.execution.cancelables.CompositeCancelable import scala.util.control.NonFatal import monix.reactive.Observable import monix.reactive.observers.Subscriber -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.util.Success +@nowarn("msg=unused value of type") private[reactive] final class Zip4Observable[A1, A2, A3, A4, +R]( obsA1: Observable[A1], obsA2: Observable[A2], obsA3: Observable[A3], - obsA4: Observable[A4])(f: (A1, A2, A3, A4) => R) + obsA4: Observable[A4] +)(f: (A1, A2, A3, A4) => R) extends Observable[R] { def unsafeSubscribeFn(out: Subscriber[R]): Cancelable = { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip5Observable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip5Observable.scala index 86425ae64..be8894bd3 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip5Observable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip5Observable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,23 +17,25 @@ package monix.reactive.internal.builders +import scala.annotation.nowarn import monix.execution.cancelables.CompositeCancelable -import monix.execution.{Ack, Cancelable, Scheduler} -import monix.execution.Ack.{Continue, Stop} - +import monix.execution.{ Ack, Cancelable, Scheduler } +import monix.execution.Ack.{ Continue, Stop } import scala.util.control.NonFatal import monix.reactive.Observable import monix.reactive.observers.Subscriber -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.util.Success +@nowarn("msg=unused value of type") private[reactive] final class Zip5Observable[A1, A2, A3, A4, A5, +R]( obsA1: Observable[A1], obsA2: Observable[A2], obsA3: Observable[A3], obsA4: Observable[A4], - obsA5: Observable[A5])(f: (A1, A2, A3, A4, A5) => R) + obsA5: Observable[A5] +)(f: (A1, A2, A3, A4, A5) => R) extends Observable[R] { def unsafeSubscribeFn(out: Subscriber[R]): Cancelable = { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip6Observable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip6Observable.scala index a2c6f540c..6e4366302 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip6Observable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/builders/Zip6Observable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,24 +17,26 @@ package monix.reactive.internal.builders +import scala.annotation.nowarn import monix.execution.cancelables.CompositeCancelable -import monix.execution.{Ack, Cancelable, Scheduler} -import monix.execution.Ack.{Continue, Stop} - +import monix.execution.{ Ack, Cancelable, Scheduler } +import monix.execution.Ack.{ Continue, Stop } import scala.util.control.NonFatal import monix.reactive.Observable import monix.reactive.observers.Subscriber -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.util.Success +@nowarn("msg=unused value of type") private[reactive] final class Zip6Observable[A1, A2, A3, A4, A5, A6, +R]( obsA1: Observable[A1], obsA2: Observable[A2], obsA3: Observable[A3], obsA4: Observable[A4], obsA5: Observable[A5], - obsA6: Observable[A6])(f: (A1, A2, A3, A4, A5, A6) => R) + obsA6: Observable[A6] +)(f: (A1, A2, A3, A4, A5, A6) => R) extends Observable[R] { def unsafeSubscribeFn(out: Subscriber[R]): Cancelable = { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/CancelledConsumer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/CancelledConsumer.scala index 0dc86d84e..d77ae33db 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/CancelledConsumer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/CancelledConsumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.consumers import monix.execution.Callback import monix.execution.Ack.Stop -import monix.execution.{Ack, Scheduler} +import monix.execution.{ Ack, Scheduler } import monix.execution.cancelables.AssignableCancelable import monix.reactive.Consumer import monix.reactive.observers.Subscriber @@ -35,7 +35,7 @@ private[reactive] object CancelledConsumer extends Consumer.Sync[Any, Unit] { } // Forcing async boundary to prevent problems - s.execute(new Runnable { def run() = cb.onSuccess(()) }) + s.execute(() => cb.onSuccess(())) (out, AssignableCancelable.alreadyCanceled) } } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/CompleteConsumer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/CompleteConsumer.scala index 923c2b2ce..b4fdf2fb4 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/CompleteConsumer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/CompleteConsumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.consumers import monix.execution.Callback import monix.execution.Ack.Continue -import monix.execution.{Ack, Scheduler} +import monix.execution.{ Ack, Scheduler } import monix.execution.cancelables.AssignableCancelable import monix.reactive.Consumer import monix.reactive.observers.Subscriber @@ -28,7 +28,8 @@ import monix.reactive.observers.Subscriber private[reactive] object CompleteConsumer extends Consumer.Sync[Any, Unit] { override def createSubscriber( cb: Callback[Throwable, Unit], - s: Scheduler): (Subscriber.Sync[Any], AssignableCancelable) = { + s: Scheduler + ): (Subscriber.Sync[Any], AssignableCancelable) = { val out = new Subscriber.Sync[Any] { implicit val scheduler: Scheduler = s def onNext(elem: Any): Ack = Continue diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/ContraMapConsumer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/ContraMapConsumer.scala index 8b2122b7d..e7c606179 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/ContraMapConsumer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/ContraMapConsumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.consumers import monix.execution.Callback import monix.execution.Ack.Stop -import monix.execution.{Ack, Scheduler} +import monix.execution.{ Ack, Scheduler } import monix.execution.cancelables.AssignableCancelable import scala.util.control.NonFatal import monix.reactive.Consumer @@ -35,9 +35,9 @@ private[reactive] final class ContraMapConsumer[In2, -In, +R](source: Consumer[I val (out, c) = source.createSubscriber(cb, s) val out2 = new Subscriber[In2] { - override implicit val scheduler: Scheduler = out.scheduler + implicit val scheduler: Scheduler = out.scheduler // For protecting the contract - private[this] var isDone = false + private var isDone = false def onError(ex: Throwable): Unit = if (!isDone) { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/CreateConsumer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/CreateConsumer.scala index 47f840d80..f9ac4a7ae 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/CreateConsumer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/CreateConsumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,16 +18,16 @@ package monix.reactive.internal.consumers import monix.execution.Callback -import monix.execution.{Cancelable, Scheduler} -import monix.execution.cancelables.{AssignableCancelable, SingleAssignCancelable} -import monix.reactive.{Consumer, Observer} +import monix.execution.{ Cancelable, Scheduler } +import monix.execution.cancelables.{ AssignableCancelable, SingleAssignCancelable } +import monix.reactive.{ Consumer, Observer } import monix.reactive.observers.Subscriber -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } /** Implementation for [[monix.reactive.Consumer.create]]. */ private[reactive] final class CreateConsumer[-In, +Out]( - f: (Scheduler, Cancelable, Callback[Throwable, Out]) => Observer[In]) - extends Consumer[In, Out] { + f: (Scheduler, Cancelable, Callback[Throwable, Out]) => Observer[In] +) extends Consumer[In, Out] { def createSubscriber(cb: Callback[Throwable, Out], s: Scheduler): (Subscriber[In], AssignableCancelable) = { val conn = SingleAssignCancelable() diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/FirstNotificationConsumer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/FirstNotificationConsumer.scala index 020de0e32..4d97583f2 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/FirstNotificationConsumer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/FirstNotificationConsumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,18 +20,19 @@ package monix.reactive.internal.consumers import monix.execution.Callback import monix.execution.Ack.Stop import monix.execution.cancelables.AssignableCancelable -import monix.execution.{Ack, Scheduler} +import monix.execution.{ Ack, Scheduler } import monix.reactive.observers.Subscriber -import monix.reactive.{Consumer, Notification} +import monix.reactive.{ Consumer, Notification } /** Implementation for [[monix.reactive.Consumer.firstNotification]]. */ private[reactive] final class FirstNotificationConsumer[A] extends Consumer.Sync[A, Notification[A]] { override def createSubscriber( cb: Callback[Throwable, Notification[A]], - s: Scheduler): (Subscriber.Sync[A], AssignableCancelable) = { + s: Scheduler + ): (Subscriber.Sync[A], AssignableCancelable) = { val out = new Subscriber.Sync[A] { implicit val scheduler: Scheduler = s - private[this] var isDone = false + private var isDone = false def onNext(elem: A): Ack = { isDone = true diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/FoldLeftConsumer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/FoldLeftConsumer.scala index 9afa8762c..6a03dc012 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/FoldLeftConsumer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/FoldLeftConsumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,8 +18,8 @@ package monix.reactive.internal.consumers import monix.execution.Callback -import monix.execution.Ack.{Continue, Stop} -import monix.execution.{Ack, Scheduler} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.{ Ack, Scheduler } import monix.execution.cancelables.AssignableCancelable import scala.util.control.NonFatal import monix.reactive.Consumer @@ -31,8 +31,8 @@ private[reactive] final class FoldLeftConsumer[A, R](initial: () => R, f: (R, A) def createSubscriber(cb: Callback[Throwable, R], s: Scheduler): (Subscriber.Sync[A], AssignableCancelable) = { val out = new Subscriber.Sync[A] { implicit val scheduler: Scheduler = s - private[this] var isDone = false - private[this] var state = initial() + private var isDone = false + private var state = initial() def onNext(elem: A): Ack = { // Protects calls to user code from within the operator, diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/FoldLeftTaskConsumer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/FoldLeftTaskConsumer.scala index bbab2864d..ae51ae033 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/FoldLeftTaskConsumer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/FoldLeftTaskConsumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,10 +17,10 @@ package monix.reactive.internal.consumers -import monix.execution.{Ack, Callback, Cancelable, Scheduler} +import monix.execution.{ Ack, Callback, Cancelable, Scheduler } import monix.eval.Task -import monix.execution.Ack.{Continue, Stop} -import monix.execution.cancelables.{AssignableCancelable, SingleAssignCancelable} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.cancelables.{ AssignableCancelable, SingleAssignCancelable } import scala.util.control.NonFatal import monix.reactive.Consumer @@ -38,20 +38,23 @@ private[reactive] final class FoldLeftTaskConsumer[A, R](initial: () => R, f: (R val out = new Subscriber[A] { implicit val scheduler: Scheduler = s - private[this] var state = initial() + private var state = initial() def onNext(elem: A): Future[Ack] = { // Protects calls to user code from within the operator, // as a matter of contract. try { def task = - f(state, elem).redeem(error => { - onError(error) - Stop - }, update => { - state = update - Continue - }) + f(state, elem).redeem( + error => { + onError(error) + Stop + }, + update => { + state = update + Continue + } + ) synchronized { if (!isDone) { @@ -80,12 +83,15 @@ private[reactive] final class FoldLeftTaskConsumer[A, R](initial: () => R, f: (R } } - (out, SingleAssignCancelable.plusOne(Cancelable { () => - synchronized { - isDone = true - lastCancelable.cancel() - lastCancelable = Cancelable.empty - } - })) + ( + out, + SingleAssignCancelable.plusOne(Cancelable { () => + synchronized { + isDone = true + lastCancelable.cancel() + lastCancelable = Cancelable.empty + } + }) + ) } } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/ForeachAsyncConsumer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/ForeachAsyncConsumer.scala index e87d2e47a..0992a7854 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/ForeachAsyncConsumer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/ForeachAsyncConsumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,10 +17,10 @@ package monix.reactive.internal.consumers -import monix.execution.{Ack, Callback, Cancelable, Scheduler} +import monix.execution.{ Ack, Callback, Cancelable, Scheduler } import monix.eval.Task -import monix.execution.Ack.{Continue, Stop} -import monix.execution.cancelables.{AssignableCancelable, SingleAssignCancelable} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.cancelables.{ AssignableCancelable, SingleAssignCancelable } import scala.util.control.NonFatal import monix.reactive.Consumer @@ -41,7 +41,7 @@ private[reactive] final class ForeachAsyncConsumer[A](f: A => Task[Unit]) extend try { this.synchronized { if (!isDone) { - val future = f(elem).redeem({e => onError(e); Stop}, _ => Continue).runToFuture + val future = f(elem).redeem({ e => onError(e); Stop }, _ => Continue).runToFuture lastCancelable = future future.syncTryFlatten } else Stop @@ -66,12 +66,15 @@ private[reactive] final class ForeachAsyncConsumer[A](f: A => Task[Unit]) extend } } - (out, SingleAssignCancelable.plusOne(Cancelable { () => - out.synchronized { - isDone = true - lastCancelable.cancel() - lastCancelable = Cancelable.empty - } - })) + ( + out, + SingleAssignCancelable.plusOne(Cancelable { () => + out.synchronized { + isDone = true + lastCancelable.cancel() + lastCancelable = Cancelable.empty + } + }) + ) } } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/ForeachConsumer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/ForeachConsumer.scala index 580ea1b2e..4d96009e8 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/ForeachConsumer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/ForeachConsumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,8 +18,8 @@ package monix.reactive.internal.consumers import monix.execution.Callback -import monix.execution.Ack.{Continue, Stop} -import monix.execution.{Ack, Scheduler} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.{ Ack, Scheduler } import monix.execution.cancelables.AssignableCancelable import scala.util.control.NonFatal import monix.reactive.Consumer @@ -31,7 +31,7 @@ private[reactive] final class ForeachConsumer[A](f: A => Unit) extends Consumer. def createSubscriber(cb: Callback[Throwable, Unit], s: Scheduler): (Subscriber.Sync[A], AssignableCancelable) = { val out = new Subscriber.Sync[A] { implicit val scheduler: Scheduler = s - private[this] var isDone = false + private var isDone = false def onNext(elem: A): Ack = { try { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/FromObserverConsumer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/FromObserverConsumer.scala index 788b86c3f..f7d10e49b 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/FromObserverConsumer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/FromObserverConsumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,15 +19,15 @@ package monix.reactive.internal.consumers import monix.execution.Callback import monix.execution.Ack.Stop -import monix.execution.{Ack, Scheduler} +import monix.execution.{ Ack, Scheduler } import monix.execution.atomic.Atomic import monix.execution.cancelables.AssignableCancelable import scala.util.control.NonFatal -import monix.reactive.{Consumer, Observer} +import monix.reactive.{ Consumer, Observer } import monix.reactive.observers.Subscriber import scala.concurrent.Future -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } /** Implementation for [[monix.reactive.Consumer.fromObserver]]. */ private[reactive] final class FromObserverConsumer[In](f: Scheduler => Observer[In]) extends Consumer[In, Unit] { @@ -41,7 +41,7 @@ private[reactive] final class FromObserverConsumer[In](f: Scheduler => Observer[ val sub = new Subscriber[In] { self => implicit val scheduler: Scheduler = s - private[this] val isDone = Atomic(false) + private val isDone = Atomic(false) private def signal(ex: Throwable): Unit = if (!isDone.getAndSet(true)) { if (ex == null) { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/HeadConsumer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/HeadConsumer.scala index af36402e5..a1635140e 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/HeadConsumer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/HeadConsumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.consumers import monix.execution.Callback import monix.execution.Ack.Stop -import monix.execution.{Ack, Scheduler} +import monix.execution.{ Ack, Scheduler } import monix.execution.cancelables.AssignableCancelable import monix.reactive.Consumer import monix.reactive.observers.Subscriber @@ -28,10 +28,11 @@ import monix.reactive.observers.Subscriber private[reactive] final class HeadConsumer[A] extends Consumer.Sync[A, A] { override def createSubscriber( cb: Callback[Throwable, A], - s: Scheduler): (Subscriber.Sync[A], AssignableCancelable) = { + s: Scheduler + ): (Subscriber.Sync[A], AssignableCancelable) = { val out = new Subscriber.Sync[A] { implicit val scheduler: Scheduler = s - private[this] var isDone = false + private var isDone = false def onNext(elem: A): Ack = { isDone = true diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/HeadOptionConsumer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/HeadOptionConsumer.scala index fdc3ade8c..d136f0473 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/HeadOptionConsumer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/HeadOptionConsumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.consumers import monix.execution.Callback import monix.execution.Ack.Stop -import monix.execution.{Ack, Scheduler} +import monix.execution.{ Ack, Scheduler } import monix.execution.cancelables.AssignableCancelable import monix.reactive.Consumer import monix.reactive.observers.Subscriber @@ -28,10 +28,11 @@ import monix.reactive.observers.Subscriber private[reactive] final class HeadOptionConsumer[A] extends Consumer.Sync[A, Option[A]] { override def createSubscriber( cb: Callback[Throwable, Option[A]], - s: Scheduler): (Subscriber.Sync[A], AssignableCancelable) = { + s: Scheduler + ): (Subscriber.Sync[A], AssignableCancelable) = { val out = new Subscriber.Sync[A] { implicit val scheduler: Scheduler = s - private[this] var isDone = false + private var isDone = false def onNext(elem: A): Ack = { isDone = true diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/LoadBalanceConsumer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/LoadBalanceConsumer.scala index 16925da3b..18b69cbd6 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/LoadBalanceConsumer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/LoadBalanceConsumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,20 +18,20 @@ package monix.reactive.internal.consumers import monix.execution.Callback -import monix.execution.Ack.{Continue, Stop} -import monix.execution.{Ack, Cancelable, Scheduler} -import monix.execution.atomic.{Atomic, PaddingStrategy} -import monix.execution.cancelables.{AssignableCancelable, SingleAssignCancelable} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.{ Ack, Cancelable, Scheduler } +import monix.execution.atomic.{ Atomic, PaddingStrategy } +import monix.execution.cancelables.{ AssignableCancelable, SingleAssignCancelable } import scala.util.control.NonFatal import monix.reactive.Consumer import monix.reactive.internal.consumers.LoadBalanceConsumer.IndexedSubscriber import monix.reactive.observers.Subscriber import scala.annotation.tailrec -import scala.collection.immutable.{BitSet, Queue} +import scala.collection.immutable.{ BitSet, Queue } import scala.collection.mutable.ListBuffer -import scala.concurrent.{Future, Promise} -import scala.util.{Failure, Success} +import scala.concurrent.{ Future, Promise } +import scala.util.{ Failure, Success } /** Implementation for [[monix.reactive.Consumer.loadBalance]]. */ private[reactive] final class LoadBalanceConsumer[-In, R](parallelism: Int, consumers: Array[Consumer[In, R]]) @@ -53,29 +53,29 @@ private[reactive] final class LoadBalanceConsumer[-In, R](parallelism: Int, cons // Trying to prevent contract violations, once this turns // true, then no final events are allowed to happen. // MUST BE synchronized by `self`. - private[this] var isUpstreamComplete = false + private var isUpstreamComplete = false // Trying to prevent contract violations. Turns true in case // we already signaled a result upstream. // MUST BE synchronized by `self`. - private[this] var isDownstreamDone = false + private var isDownstreamDone = false // Stores the error that was reported upstream - basically // multiple subscribers can report multiple errors, but we // emit the first one, so in case multiple errors happen we // want to log them, but only if they aren't the same reference // MUST BE synchronized by `self` - private[this] var reportedError: Throwable = _ + private var reportedError: Throwable = null.asInstanceOf[Throwable] // Results accumulator - when length == parallelism, // that's when we need to trigger `onFinish.onSuccess`. // MUST BE synchronized by `self` - private[this] val accumulator = ListBuffer.empty[R] + private val accumulator = ListBuffer.empty[R] /** Builds cancelables for subscribers. */ private def newCancelableFor(out: IndexedSubscriber[In]): Cancelable = new Cancelable { - private[this] var isCanceled = false + private var isCanceled = false // Forcing an asynchronous boundary, to avoid any possible // initialization issues (in building subscribersQueue) or // stack overflows and other problems @@ -98,7 +98,7 @@ private[reactive] final class LoadBalanceConsumer[-In, R](parallelism: Int, cons // Asynchronous queue that serves idle subscribers waiting // for something to process, or that puts the stream on wait // until there are subscribers available - private[this] val subscribersQueue = self.synchronized { + private val subscribersQueue = self.synchronized { var initial = Queue.empty[IndexedSubscriber[In]] // When the callback gets called by each subscriber, on success we // do nothing because for normal completion we are listing on @@ -216,18 +216,19 @@ private[reactive] final class LoadBalanceConsumer[-In, R](parallelism: Int, cons // don't want to block the main thread! scheduler.execute { () => try out.out.onNext(elem).syncOnComplete { - case Success(ack) => - ack match { - case Continue => - // We have permission to continue from this subscriber - // so returning it to the queue, to be reused - subscribersQueue.offer(out) - case Stop => - interruptOne(out, null) - } - case Failure(ex) => - interruptAll(ex) - } catch { + case Success(ack) => + ack match { + case Continue => + // We have permission to continue from this subscriber + // so returning it to the queue, to be reused + subscribersQueue.offer(out) + case Stop => + interruptOne(out, null) + } + case Failure(ex) => + interruptAll(ex) + } + catch { case ex if NonFatal(ex) => interruptAll(ex) } @@ -295,7 +296,7 @@ private[reactive] object LoadBalanceConsumer { private final class AsyncQueue[In](initialQueue: Queue[IndexedSubscriber[In]], parallelism: Int) { - private[this] val stateRef = { + private val stateRef = { val initial: State[In] = Available(initialQueue, BitSet.empty, parallelism) Atomic.withPadding(initial, PaddingStrategy.LeftRight256) } @@ -414,12 +415,12 @@ private[reactive] object LoadBalanceConsumer { private[reactive] final case class Available[In]( available: Queue[IndexedSubscriber[In]], canceledIDs: BitSet, - activeCount: Int) - extends State[In] + activeCount: Int + ) extends State[In] private[reactive] final case class Waiting[In]( promise: Promise[IndexedSubscriber[In]], canceledIDs: BitSet, - activeCount: Int) - extends State[In] + activeCount: Int + ) extends State[In] } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/MapConsumer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/MapConsumer.scala index c6110cb4c..7b87f8f37 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/MapConsumer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/MapConsumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,20 +30,16 @@ private[reactive] final class MapConsumer[In, R, R2](source: Consumer[In, R], f: def createSubscriber(cb: Callback[Throwable, R2], s: Scheduler): (Subscriber[In], AssignableCancelable) = { val cb1 = new Callback[Throwable, R] { def onSuccess(value: R): Unit = - s.execute(new Runnable { - // Forcing an asynchronous boundary, otherwise - // this isn't a safe operation. - def run(): Unit = { - var streamErrors = true - try { - val r2 = f(value) - streamErrors = false - cb.onSuccess(r2) - } catch { - case ex if NonFatal(ex) => - if (streamErrors) cb.onError(ex) - else s.reportFailure(ex) - } + s.execute(() => { + var streamErrors = true + try { + val r2 = f(value) + streamErrors = false + cb.onSuccess(r2) + } catch { + case ex if NonFatal(ex) => + if (streamErrors) cb.onError(ex) + else s.reportFailure(ex) } }) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/MapTaskConsumer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/MapTaskConsumer.scala index b5dbc1411..eca1ac2a7 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/MapTaskConsumer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/MapTaskConsumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.reactive.internal.consumers -import monix.execution.{Callback, Cancelable, Scheduler} +import monix.execution.{ Callback, Cancelable, Scheduler } import monix.eval.Task import monix.execution.cancelables.AssignableCancelable import scala.util.control.NonFatal @@ -34,50 +34,49 @@ private[reactive] final class MapTaskConsumer[In, R, R2](source: Consumer[In, R] var isCancelled = false val asyncCallback = new Callback[Throwable, R] { self => def onSuccess(value: R): Unit = - s.execute(new Runnable { - // Forcing async boundary, otherwise we might - // end up with stack-overflows or other problems - def run(): Unit = { - implicit val scheduler: Scheduler = s - // For protecting the contract, as if a call was already made to - // `onSuccess`, then we can't call `onError` - var streamErrors = true - try { - val task = f(value) - streamErrors = false - self.synchronized { - if (!isCancelled) - lastCancelable = task.runAsync(cb) - } - } catch { - case ex if NonFatal(ex) => - if (streamErrors) cb.onError(ex) - else s.reportFailure(ex) + s.execute(() => { + implicit val scheduler = s + // For protecting the contract, as if a call was already made to + // `onSuccess`, then we can't call `onError` + var streamErrors = true + try { + val task = f(value) + streamErrors = false + self.synchronized { + if (!isCancelled) + lastCancelable = task.runAsync(cb) } + } catch { + case ex if NonFatal(ex) => + if (streamErrors) cb.onError(ex) + else s.reportFailure(ex) } }) def onError(ex: Throwable): Unit = { // Forcing async boundary, otherwise we might // end up with stack-overflows or other problems - s.execute(new Runnable { def run(): Unit = cb.onError(ex) }) + s.execute(() => cb.onError(ex)) } } val (sub, ac) = source.createSubscriber(asyncCallback, s) - (sub, new AssignableCancelable { - override def `:=`(value: Cancelable): this.type = { - ac := value - this - } + ( + sub, + new AssignableCancelable { + override def `:=`(value: Cancelable): this.type = { + ac := value + this + } - override def cancel(): Unit = { - ac.cancel() - asyncCallback.synchronized { - isCancelled = true - lastCancelable.cancel() + override def cancel(): Unit = { + ac.cancel() + asyncCallback.synchronized { + isCancelled = true + lastCancelable.cancel() + } } } - }) + ) } } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/RaiseErrorConsumer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/RaiseErrorConsumer.scala index f2c799260..7ddff9aef 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/RaiseErrorConsumer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/RaiseErrorConsumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.consumers import monix.execution.Callback import monix.execution.Ack.Stop -import monix.execution.{Ack, Scheduler} +import monix.execution.{ Ack, Scheduler } import monix.execution.cancelables.AssignableCancelable import monix.reactive.Consumer import monix.reactive.observers.Subscriber @@ -36,7 +36,7 @@ private[reactive] final class RaiseErrorConsumer(ex: Throwable) extends Consumer } // Forcing async boundary to prevent problems - s.execute(new Runnable { def run() = cb.onError(ex) }) + s.execute(() => cb.onError(ex)) (out, AssignableCancelable.alreadyCanceled) } } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/TransformInputConsumer.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/TransformInputConsumer.scala index 5f22a5308..32ac23265 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/TransformInputConsumer.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/consumers/TransformInputConsumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,17 +17,19 @@ package monix.reactive.internal.consumers +import scala.annotation.nowarn import monix.execution.Callback import monix.execution.Scheduler import monix.execution.cancelables.AssignableCancelable import monix.reactive.observers.Subscriber -import monix.reactive.{Consumer, Observable, Pipe} +import monix.reactive.{ Consumer, Observable, Pipe } /** Implementation for [[monix.reactive.Consumer.transformInput]]. */ +@nowarn("msg=unused value of type") private[reactive] final class TransformInputConsumer[In2, -In, +R]( source: Consumer[In, R], - f: Observable[In2] => Observable[In]) - extends Consumer[In2, R] { + f: Observable[In2] => Observable[In] +) extends Consumer[In2, R] { def createSubscriber(cb: Callback[Throwable, R], s: Scheduler): (Subscriber[In2], AssignableCancelable) = { val (input1, conn) = source.createSubscriber(cb, s) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/deprecated/ConcurrentSubjectDeprecatedBuilders.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/deprecated/ConcurrentSubjectDeprecatedBuilders.scala new file mode 100644 index 000000000..100e85acf --- /dev/null +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/deprecated/ConcurrentSubjectDeprecatedBuilders.scala @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.reactive.internal.deprecated + +import monix.execution.Scheduler +import monix.reactive.subjects.ConcurrentSubject + +/** Binary-compatibility shims for [[monix.reactive.subjects.ConcurrentSubject]]. + * + * These methods preserve the binary interface of `ConcurrentSubject` from 3.4.0. + * They are package-private and must not be called by user code. + */ +private[monix] trait ConcurrentSubjectDeprecatedBuilders extends Any { + + /** Binary-compatibility shim — the `Scheduler` parameter is no longer needed. + * + * In 3.4.0, `async` required an implicit `Scheduler`; in 3.5.0 it does not. + * This overload preserves the old JVM bytecode descriptor so that pre-compiled + * 3.4.0 call-sites remain link-compatible at runtime. + * + * @deprecated Use [[ConcurrentSubject.async[A]:* ConcurrentSubject.async]] instead. + */ + @deprecated("The Scheduler parameter is no longer needed; use ConcurrentSubject.async without it.", "3.5.0") + private[deprecated] def async[A](implicit s: Scheduler): ConcurrentSubject[A, A] = + // $COVERAGE-OFF$ + ConcurrentSubject.async[A] + // $COVERAGE-ON$ +} diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/deprecated/ObservableDeprecatedBuilders.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/deprecated/ObservableDeprecatedBuilders.scala index 0c8f95dfb..6f97ac672 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/deprecated/ObservableDeprecatedBuilders.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/deprecated/ObservableDeprecatedBuilders.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.internal.deprecated import cats.Eval import cats.effect.IO import monix.execution.Scheduler -import monix.reactive.{Observable, OverflowStrategy} +import monix.reactive.{ Observable, OverflowStrategy } private[reactive] trait ObservableDeprecatedBuilders extends Any { /** DEPRECATED — please use [[Observable!.executeAsync .executeAsync]]. @@ -104,7 +104,8 @@ private[reactive] trait ObservableDeprecatedBuilders extends Any { */ @deprecated("Switch to Observable(list).merge", "3.0.0") def mergeDelayError[A](sources: Observable[A]*)( - implicit os: OverflowStrategy[A] = OverflowStrategy.Default): Observable[A] = { + implicit os: OverflowStrategy[A] = OverflowStrategy.Default + ): Observable[A] = { // $COVERAGE-OFF$ Observable.fromIterable(sources).mergeMapDelayErrors(identity)(os) // $COVERAGE-ON$ diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/deprecated/ObservableDeprecatedMethods.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/deprecated/ObservableDeprecatedMethods.scala index ab71ecead..8247dcf38 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/deprecated/ObservableDeprecatedMethods.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/deprecated/ObservableDeprecatedMethods.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,9 @@ package monix.reactive.internal.deprecated -import cats.effect.{Effect, ExitCase} -import cats.{Monoid, Order} -import monix.eval.{Task, TaskLike} +import cats.effect.{ Effect, ExitCase } +import cats.{ Monoid, Order } +import monix.eval.{ Task, TaskLike } import monix.execution.Ack import monix.reactive.Observable import monix.reactive.internal.operators.DoOnTerminateOperator diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/AsyncBoundaryOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/AsyncBoundaryOperator.scala index 1bbe5fb38..beb6480e2 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/AsyncBoundaryOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/AsyncBoundaryOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.internal.operators import monix.execution.ChannelType.SingleProducer import monix.reactive.Observable.Operator import monix.reactive.OverflowStrategy -import monix.reactive.observers.{BufferedSubscriber, Subscriber} +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } private[reactive] final class AsyncBoundaryOperator[A](overflowStrategy: OverflowStrategy[A]) extends Operator[A, A] { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferIntrospectiveObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferIntrospectiveObservable.scala index 996ffca98..4db807d25 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferIntrospectiveObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferIntrospectiveObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.internal.operators import monix.execution.Cancelable import monix.execution.ChannelType.SingleProducer import monix.reactive.Observable -import monix.reactive.observers.{BufferedSubscriber, Subscriber} +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } private[reactive] final class BufferIntrospectiveObservable[+A](source: Observable[A], maxSize: Int) extends Observable[List[A]] { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferSlidingOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferSlidingOperator.scala index e46bca376..e2e05664f 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferSlidingOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferSlidingOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,14 +17,17 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import scala.annotation.nowarn +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber import scala.concurrent.Future import monix.execution.compat.internal.toSeq +@nowarn("msg=unused value of type") private[reactive] final class BufferSlidingOperator[A](count: Int, skip: Int) extends Operator[A, Seq[A]] { require(count > 0, "count must be strictly positive") @@ -34,15 +37,15 @@ private[reactive] final class BufferSlidingOperator[A](count: Int, skip: Int) ex new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false - private[this] var ack: Future[Ack] = _ + private var isDone = false + private var ack: Future[Ack] = null.asInstanceOf[Future[Ack]] - private[this] val toDrop = if (count > skip) 0 else skip - count - private[this] val toRepeat = if (skip > count) 0 else count - skip + private val toDrop = if (count > skip) 0 else skip - count + private val toRepeat = if (skip > count) 0 else count - skip - private[this] var buffer = new Array[AnyRef](count) - private[this] var dropped = 0 - private[this] var length = 0 + private var buffer = new Array[AnyRef](count) + private var dropped = 0 + private var length = 0 def onNext(elem: A): Future[Ack] = { if (isDone) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferTimedObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferTimedObservable.scala index e2bee124a..094df6b34 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferTimedObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferTimedObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,15 +18,16 @@ package monix.reactive.internal.operators import java.util.concurrent.TimeUnit -import monix.execution.Ack.{Continue, Stop} -import monix.execution.cancelables.{CompositeCancelable, MultiAssignCancelable} -import monix.execution.{Ack, Cancelable, Scheduler} + +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.cancelables.{ CompositeCancelable, MultiAssignCancelable } +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.collection.mutable.ListBuffer import scala.concurrent.Future -import scala.concurrent.duration.{Duration, FiniteDuration, MILLISECONDS} +import scala.concurrent.duration.{ Duration, FiniteDuration, MILLISECONDS } private[reactive] final class BufferTimedObservable[+A](source: Observable[A], timespan: FiniteDuration, maxCount: Int) extends Observable[Seq[A]] { @@ -40,17 +41,17 @@ private[reactive] final class BufferTimedObservable[+A](source: Observable[A], t val connection = source.unsafeSubscribeFn(new Subscriber[A] with Runnable { self => implicit val scheduler: Scheduler = out.scheduler - private[this] val timespanMillis = timespan.toMillis + private val timespanMillis = timespan.toMillis // MUST BE synchronized by `self` - private[this] var ack: Future[Ack] = Continue + private var ack: Future[Ack] = Continue // MUST BE synchronized by `self` - private[this] var buffer = ListBuffer.empty[A] + private var buffer = ListBuffer.empty[A] // MUST BE synchronized by `self` - private[this] var expiresAt = scheduler.clockMonotonic(MILLISECONDS) + timespanMillis + private var expiresAt = scheduler.clockMonotonic(MILLISECONDS) + timespanMillis locally { // Scheduling the first tick, in the constructor - periodicTask := out.scheduler.scheduleOnce(timespanMillis, TimeUnit.MILLISECONDS, self) + val _ = periodicTask := out.scheduler.scheduleOnce(timespanMillis, TimeUnit.MILLISECONDS, self) } // Runs periodically, every `timespan` @@ -62,16 +63,16 @@ private[reactive] final class BufferTimedObservable[+A](source: Observable[A], t // problem, or we rushed to signaling the bundle upon reaching // the maximum size in onNext. So we sleep some more. val remaining = expiresAt - now - periodicTask := scheduler.scheduleOnce(remaining, TimeUnit.MILLISECONDS, self) + val _ = periodicTask := scheduler.scheduleOnce(remaining, TimeUnit.MILLISECONDS, self) } else if (buffer != null) { // The timespan has passed since the last signal so we need // to send the current bundle - sendNextAndReset(now).syncOnContinue( + val _ = sendNextAndReset(now).syncOnContinue( // Schedule the next tick, but only after we are done // sending the bundle - run()) + run() + ) } - () } // Must be synchronized by `self` @@ -113,8 +114,8 @@ private[reactive] final class BufferTimedObservable[+A](source: Observable[A], t // In case the last onNext isn't finished, then // we need to apply back-pressure, otherwise this // onNext will break the contract. - ack.syncOnContinue { - out.onNext(bundleToSend) + val _ = ack.syncOnContinue { + val _ = out.onNext(bundleToSend) out.onComplete() } } else { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferWhileOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferWhileOperator.scala index 08a4f7862..996055dde 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferWhileOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferWhileOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,8 +17,10 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import scala.annotation.nowarn +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber @@ -26,14 +28,15 @@ import scala.collection.mutable.ListBuffer import scala.concurrent.Future import scala.util.control.NonFatal +@nowarn("msg=unused value of type") private[reactive] final class BufferWhileOperator[A](p: A => Boolean, inclusive: Boolean) extends Operator[A, Seq[A]] { def apply(out: Subscriber[Seq[A]]): Subscriber[A] = new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false - private[this] var ack: Future[Ack] = Continue - private[this] var buffer = ListBuffer.empty[A] + private var isDone = false + private var ack: Future[Ack] = Continue + private var buffer = ListBuffer.empty[A] def onNext(elem: A): Future[Ack] = if (isDone) Stop diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferWithSelectorObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferWithSelectorObservable.scala index 981db6e05..a047f26c5 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferWithSelectorObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/BufferWithSelectorObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,21 +17,24 @@ package monix.reactive.internal.operators -import monix.execution.Ack.{Continue, Stop} -import monix.execution.cancelables.{CompositeCancelable, SingleAssignCancelable} -import monix.execution.{Ack, Cancelable, Scheduler} +import scala.annotation.nowarn +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler +import monix.execution.cancelables.{ CompositeCancelable, SingleAssignCancelable } +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.collection.mutable.ListBuffer -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } +@nowarn("msg=unused value of type") private[reactive] final class BufferWithSelectorObservable[+A, S]( source: Observable[A], sampler: Observable[S], maxSize: Int, - sizeOf: A => Int) - extends Observable[Seq[A]] { + sizeOf: A => Int +) extends Observable[Seq[A]] { def unsafeSubscribeFn(downstream: Subscriber[Seq[A]]): Cancelable = { val upstreamSubscription = SingleAssignCancelable() @@ -42,18 +45,18 @@ private[reactive] final class BufferWithSelectorObservable[+A, S]( implicit val scheduler: Scheduler = downstream.scheduler // MUST BE synchronized by `self` - private[this] var buffer = ListBuffer.empty[A] + private var buffer = ListBuffer.empty[A] // Maintain internal buffer weight not to compute the weight // of the buffer each time an element is added. // So to keep complexity to O(1) for each added element. // MUST BE synchronized by `self` - private[this] var bufferWeight: Int = 0 + private var bufferWeight: Int = 0 // MUST BE synchronized by `self` - private[this] var promise = Promise[Ack]() + private var promise = Promise[Ack]() // To be written in onComplete/onError, to be read from tick - private[this] var upstreamIsDone = false + private var upstreamIsDone = false // MUST BE synchronized by `self`. - private[this] var downstreamIsDone = false + private var downstreamIsDone = false def onNext(elem: A): Future[Ack] = upstreamSubscriber.synchronized { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/CollectOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/CollectOperator.scala index 8b1c8b1dc..d665c9406 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/CollectOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/CollectOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,9 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} - +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import scala.util.control.NonFatal import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber @@ -28,12 +28,12 @@ import scala.concurrent.Future private[reactive] final class CollectOperator[-A, +B](pf: PartialFunction[A, B]) extends Operator[A, B] { - import CollectOperator.{checkFallback, isDefined} + import CollectOperator.{ checkFallback, isDefined } def apply(out: Subscriber[B]): Subscriber[A] = { new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false + private var isDone = false def onNext(elem: A): Future[Ack] = { // Protects calls to user code from within the operator and diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/CollectWhileOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/CollectWhileOperator.scala index a0e36a517..2e708fda4 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/CollectWhileOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/CollectWhileOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,10 +19,10 @@ package monix.reactive.internal.operators import monix.execution.{Ack, Scheduler} import monix.execution.Ack.Stop - +import monix.execution.Scheduler import scala.util.control.NonFatal import monix.reactive.Observable.Operator -import monix.reactive.internal.operators.CollectOperator.{checkFallback, isDefined} +import monix.reactive.internal.operators.CollectOperator.{ checkFallback, isDefined } import monix.reactive.observers.Subscriber import scala.concurrent.Future @@ -32,7 +32,7 @@ private[reactive] final class CollectWhileOperator[-A, +B](pf: PartialFunction[A def apply(out: Subscriber[B]): Subscriber[A] = new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isActive = true + private var isActive = true def onNext(elem: A): Future[Ack] = { if (!isActive) Stop @@ -70,14 +70,3 @@ private[reactive] final class CollectWhileOperator[-A, +B](pf: PartialFunction[A } } } - -private object CollectWhileOperator extends (Any => Any) { - /** In the case a partial function is not defined, return a magic fallback value. */ - def checkFallback[B]: Any => B = this.asInstanceOf[Any => B] - - /** Indicates whether the result is the magic fallback value. */ - def isDefined(result: Any): Boolean = result.asInstanceOf[AnyRef] ne this - - /** Always returns `this`, used as the magic fallback value. */ - override def apply(elem: Any): Any = this -} diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/CompletedOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/CompletedOperator.scala index afb2cc932..d8c395478 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/CompletedOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/CompletedOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ConcatMapIterableOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ConcatMapIterableOperator.scala index 787f8a49c..84b599bca 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ConcatMapIterableOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ConcatMapIterableOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,8 +17,9 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber @@ -31,8 +32,8 @@ private[reactive] final class ConcatMapIterableOperator[-A, +B](f: A => immutabl def apply(out: Subscriber[B]): Subscriber[A] = { new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false - private[this] var ack: Future[Ack] = Continue + private var isDone = false + private var ack: Future[Ack] = Continue def onNext(elem: A): Future[Ack] = { // Protects calls to user code from within the operator and diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ConcatMapObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ConcatMapObservable.scala index f5bf5d84c..a07e90a33 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ConcatMapObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ConcatMapObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,20 +17,22 @@ package monix.reactive.internal.operators +import scala.annotation.nowarn import cats.effect.ExitCase import monix.eval.Task -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import monix.execution.atomic.Atomic import monix.execution.atomic.PaddingStrategy.LeftRight128 import scala.util.control.NonFatal -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable } import monix.execution.exceptions.CompositeException import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.annotation.tailrec -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.util.Failure /** Implementation for `Observable.concatMap`. @@ -64,12 +66,13 @@ import scala.util.Failure * however it's OK-ish, since these CAS operations are not going * to be contended */ +@nowarn("msg=unused value of type") private[reactive] final class ConcatMapObservable[A, B]( source: Observable[A], f: A => Observable[B], release: (A, ExitCase[Throwable]) => Task[Unit], - delayErrors: Boolean) - extends Observable[B] { + delayErrors: Boolean +) extends Observable[B] { def unsafeSubscribeFn(out: Subscriber[B]): Cancelable = { val subscriber = new ConcatMapSubscriber(out) @@ -89,18 +92,18 @@ private[reactive] final class ConcatMapObservable[A, B]( implicit val scheduler: Scheduler = out.scheduler // For gathering errors - private[this] val errors = + private val errors = if (delayErrors) Atomic(List.empty[Throwable]) else null // Boolean for keeping the `isActive` state, needed because we could miss // out on seeing a `Cancelled` state due to the `lazySet` instructions, // making the visibility of the `Cancelled` state thread-unsafe! - private[this] val isActive = Atomic(true) + private val isActive = Atomic(true) // For synchronizing our internal state machine, padded // in order to avoid the false sharing problem - private[this] val stateRef = + private val stateRef = Atomic.withPadding(WaitOnNextChild(Continue): FlatMapState, LeftRight128) /** For canceling the current active task, in case there is any. Here @@ -333,17 +336,18 @@ private[reactive] final class ConcatMapObservable[A, B]( s"State $state in the Monix ConcatMap.$method implementation is invalid, " + "due to either a broken Subscriber implementation, or a bug, " + "please open an issue, see: https://monix.io" - )) + ) + ) // $COVERAGE-ON$ } private final class ChildSubscriber(out: Subscriber[B], asyncUpstreamAck: Promise[Ack]) extends Subscriber[B] { implicit val scheduler: Scheduler = out.scheduler - private[this] var ack: Future[Ack] = Continue + private var ack: Future[Ack] = Continue // Reusable reference to stop creating function references for each `onNext` - private[this] val onStopOrFailureRef = (err: Option[Throwable]) => { + private val onStopOrFailureRef = (err: Option[Throwable]) => { if (err.isDefined) out.scheduler.reportFailure(err.get) signalChildOnComplete(Stop, isStop = true) } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ConcatObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ConcatObservable.scala index 60b2a867b..1f46e4d3b 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ConcatObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ConcatObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,17 +17,20 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Scheduler} +import scala.annotation.nowarn +import monix.execution.Ack import monix.execution.Ack.Continue +import monix.execution.Scheduler import monix.execution.cancelables.AssignableCancelable import monix.reactive.Observable import monix.reactive.observables.ChainedObservable -import monix.reactive.observables.ChainedObservable.{subscribe => chain} +import monix.reactive.observables.ChainedObservable.{ subscribe => chain } import monix.reactive.observers.Subscriber import scala.concurrent.Future /** Implementation for observable concatenation `++`. */ +@nowarn("msg=unused value of type") private[reactive] final class ConcatObservable[A](lh: Observable[A], rh: Observable[A]) extends ChainedObservable[A] { def unsafeSubscribeFn(conn: AssignableCancelable.Multi, out: Subscriber[A]): Unit = { @@ -35,7 +38,7 @@ private[reactive] final class ConcatObservable[A](lh: Observable[A], rh: Observa lh, conn, new Subscriber[A] { - private[this] var ack: Future[Ack] = Continue + private var ack: Future[Ack] = Continue implicit val scheduler: Scheduler = out.scheduler def onNext(elem: A): Future[Ack] = { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/CountOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/CountOperator.scala index f12c26896..c95e6b5d2 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/CountOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/CountOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,18 +17,21 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Scheduler} +import scala.annotation.nowarn +import monix.execution.Ack import monix.execution.Ack.Continue +import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber import scala.concurrent.Future +@nowarn("msg=unused value of type") private[reactive] object CountOperator extends Operator[Any, Long] { def apply(out: Subscriber[Long]): Subscriber[Any] = new Subscriber[Any] { implicit val scheduler: Scheduler = out.scheduler - private[this] var count = 0L + private var count = 0L def onNext(elem: Any): Future[Ack] = { count += 1 diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DebounceObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DebounceObservable.scala index eade4dfc0..22700024c 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DebounceObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DebounceObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,15 +17,19 @@ package monix.reactive.internal.operators +import scala.annotation.nowarn import java.util.concurrent.TimeUnit -import monix.execution.Ack.{Continue, Stop} -import monix.execution.cancelables.{CompositeCancelable, MultiAssignCancelable, SingleAssignCancelable} -import monix.execution.{Ack, Cancelable, Scheduler} + +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler +import monix.execution.cancelables.{ CompositeCancelable, MultiAssignCancelable, SingleAssignCancelable } +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber -import scala.concurrent.duration.{FiniteDuration, MILLISECONDS} +import scala.concurrent.duration.{ FiniteDuration, MILLISECONDS } +@nowarn("msg=discarded non-Unit value") private[reactive] final class DebounceObservable[A](source: Observable[A], timeout: FiniteDuration, repeat: Boolean) extends Observable[A] { @@ -37,11 +41,11 @@ private[reactive] final class DebounceObservable[A](source: Observable[A], timeo mainTask := source.unsafeSubscribeFn(new Subscriber.Sync[A] with Runnable { self => implicit val scheduler: Scheduler = out.scheduler - private[this] val timeoutMillis = timeout.toMillis - private[this] var isDone = false - private[this] var lastEvent: A = _ - private[this] var lastTSInMillis: Long = 0L - private[this] var hasValue = false + private val timeoutMillis = timeout.toMillis + private var isDone = false + private var lastEvent: A = null.asInstanceOf[A] + private var lastTSInMillis: Long = 0L + private var hasValue = false locally { scheduleNext(timeoutMillis) @@ -94,7 +98,6 @@ private[reactive] final class DebounceObservable[A](source: Observable[A], timeo } } } - () } def onNext(elem: A): Ack = self.synchronized { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DefaultIfEmptyOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DefaultIfEmptyOperator.scala index 7431ba8a7..cadcd7605 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DefaultIfEmptyOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DefaultIfEmptyOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,20 +17,22 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Scheduler} - +import scala.annotation.nowarn +import monix.execution.Ack +import monix.execution.Scheduler import scala.util.control.NonFatal import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber import scala.concurrent.Future +@nowarn("msg=unused value of type") private[reactive] final class DefaultIfEmptyOperator[A](default: () => A) extends Operator[A, A] { def apply(out: Subscriber[A]): Subscriber[A] = new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isEmpty = true + private var isEmpty = true def onNext(elem: A): Future[Ack] = { if (isEmpty) isEmpty = false diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayBySelectorObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayBySelectorObservable.scala index 2153d9b82..719758241 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayBySelectorObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayBySelectorObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,16 +17,18 @@ package monix.reactive.internal.operators -import monix.execution.Ack.{Continue, Stop} -import monix.execution.cancelables.{CompositeCancelable, MultiAssignCancelable} - +import scala.annotation.nowarn +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler +import monix.execution.cancelables.{ CompositeCancelable, MultiAssignCancelable } import scala.util.control.NonFatal -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } +@nowarn("msg=unused value of type") private[reactive] final class DelayBySelectorObservable[A, S](source: Observable[A], selector: A => Observable[S]) extends Observable[A] { @@ -37,12 +39,12 @@ private[reactive] final class DelayBySelectorObservable[A, S](source: Observable composite += source.unsafeSubscribeFn(new Subscriber[A] { self => implicit val scheduler: Scheduler = out.scheduler - private[this] var completeTriggered = false - private[this] var isDone = false - private[this] var currentElem: A = _ - private[this] var ack: Promise[Ack] = _ + private var completeTriggered = false + private var isDone = false + private var currentElem: A = null.asInstanceOf[A] + private var ack: Promise[Ack] = null.asInstanceOf[Promise[Ack]] - private[this] val trigger = new Subscriber.Sync[Any] { + private val trigger = new Subscriber.Sync[Any] { implicit val scheduler: Scheduler = out.scheduler def onNext(elem: Any): Ack = throw new IllegalStateException def onError(ex: Throwable): Unit = self.onError(ex) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayByTimespanObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayByTimespanObservable.scala index 69cf76a89..d39b9505e 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayByTimespanObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayByTimespanObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,15 +18,17 @@ package monix.reactive.internal.operators import java.util.concurrent.TimeUnit -import monix.execution.Ack.{Continue, Stop} -import monix.execution.cancelables.{CompositeCancelable, MultiAssignCancelable} -import monix.execution.{Ack, Cancelable, Scheduler} + +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler +import monix.execution.cancelables.{ CompositeCancelable, MultiAssignCancelable } +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber import monix.execution.atomic.Atomic import scala.concurrent.duration.FiniteDuration -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } private[reactive] final class DelayByTimespanObservable[A](source: Observable[A], delay: FiniteDuration) extends Observable[A] { @@ -37,12 +39,12 @@ private[reactive] final class DelayByTimespanObservable[A](source: Observable[A] composite += source.unsafeSubscribeFn(new Subscriber[A] with Runnable { self => implicit val scheduler: Scheduler = out.scheduler - private[this] var hasError = false - private[this] val isDone = Atomic(false) - private[this] var completeTriggered = false - private[this] val delayMs = delay.toMillis - private[this] var currentElem: A = _ - private[this] var ack: Promise[Ack] = _ + private var hasError = false + private val isDone = Atomic(false) + private var completeTriggered = false + private val delayMs = delay.toMillis + private var currentElem: A = null.asInstanceOf[A] + private var ack: Promise[Ack] = null.asInstanceOf[Promise[Ack]] def onNext(elem: A): Future[Ack] = { currentElem = elem @@ -58,11 +60,9 @@ private[reactive] final class DelayByTimespanObservable[A](source: Observable[A] def onComplete(): Unit = { completeTriggered = true val lastAck = if (ack eq null) Continue else ack.future - - lastAck.syncTryFlatten.syncOnContinue { + val _ = lastAck.syncTryFlatten.syncOnContinue { if (!isDone.getAndSet(true)) out.onComplete() } - () } // Method `onError` is concurrent with run(), so we need to synchronize @@ -73,7 +73,7 @@ private[reactive] final class DelayByTimespanObservable[A](source: Observable[A] hasError = true try out.onError(ex) finally { - if (ack != null) ack.trySuccess(Stop) + if (ack != null) { val _ = ack.trySuccess(Stop) } task.cancel() } } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayExecutionByTimespanObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayExecutionByTimespanObservable.scala index 28cd307e7..7875cd14d 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayExecutionByTimespanObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayExecutionByTimespanObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,12 +28,14 @@ private[reactive] final class DelayExecutionByTimespanObservable[A](source: Obse def unsafeSubscribeFn(out: Subscriber[A]): Cancelable = { val conn = OrderedCancelable() - val main = out.scheduler.scheduleOnce(timespan.length, timespan.unit, new Runnable { - def run(): Unit = { + val main = out.scheduler.scheduleOnce( + timespan.length, + timespan.unit, + () => { conn.orderedUpdate(source.unsafeSubscribeFn(out), order = 2) () } - }) + ) conn.orderedUpdate(main, order = 1) } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayExecutionWithTriggerObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayExecutionWithTriggerObservable.scala index 5e84be659..b0f87e1ff 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayExecutionWithTriggerObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayExecutionWithTriggerObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,14 +18,15 @@ package monix.reactive.internal.operators import monix.execution.Ack.Stop +import monix.execution.Scheduler import monix.execution.cancelables.OrderedCancelable -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.concurrent.Future -private[reactive] final class DelayExecutionWithTriggerObservable[A](source: Observable[A], trigger: Observable[_]) +private[reactive] final class DelayExecutionWithTriggerObservable[A](source: Observable[A], trigger: Observable[?]) extends Observable[A] { def unsafeSubscribeFn(subscriber: Subscriber[A]): Cancelable = { @@ -35,7 +36,7 @@ private[reactive] final class DelayExecutionWithTriggerObservable[A](source: Obs .asInstanceOf[Observable[Any]] .unsafeSubscribeFn(new Subscriber[Any] { implicit val scheduler: Scheduler = subscriber.scheduler - private[this] var isDone = false + private var isDone = false def onNext(elem: Any): Future[Ack] = { if (isDone) Stop diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayOnCompleteObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayOnCompleteObservable.scala index ced86d625..5a628fade 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayOnCompleteObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DelayOnCompleteObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,13 +17,15 @@ package monix.reactive.internal.operators +import scala.annotation.nowarn import monix.execution.cancelables.OrderedCancelable -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.concurrent.Future import scala.concurrent.duration.FiniteDuration +@nowarn("msg=unused value of type") private[reactive] final class DelayOnCompleteObservable[A](source: Observable[A], delay: FiniteDuration) extends Observable[A] { @@ -32,7 +34,7 @@ private[reactive] final class DelayOnCompleteObservable[A](source: Observable[A] val c = source.unsafeSubscribeFn(new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false + private var isDone = false def onNext(elem: A): Future[Ack] = { val ack = out.onNext(elem) @@ -49,9 +51,7 @@ private[reactive] final class DelayOnCompleteObservable[A](source: Observable[A] def onComplete(): Unit = if (!isDone) { isDone = true - val scheduled = scheduler.scheduleOnce(delay.length, delay.unit, new Runnable { - def run(): Unit = out.onComplete() - }) + val scheduled = scheduler.scheduleOnce(delay.length, delay.unit, () => out.onComplete()) task.orderedUpdate(scheduled, order = 2) () } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DematerializeOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DematerializeOperator.scala index e6d153097..be3674b16 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DematerializeOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DematerializeOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,8 +19,9 @@ package monix.reactive.internal.operators import monix.execution.{Ack, Scheduler} import monix.execution.Ack.Stop +import monix.execution.Scheduler import monix.reactive.Notification -import monix.reactive.Notification.{OnComplete, OnError, OnNext} +import monix.reactive.Notification.{ OnComplete, OnError, OnNext } import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber @@ -31,7 +32,7 @@ private[reactive] final class DematerializeOperator[A] extends Operator[Notifica def apply(out: Subscriber[A]): Subscriber[Notification[A]] = new Subscriber[Notification[A]] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false + private var isDone = false def onNext(elem: Notification[A]): Future[Ack] = { if (isDone) Stop diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DistinctUntilChangedByKeyOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DistinctUntilChangedByKeyOperator.scala index 17b598e36..9c00bb9af 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DistinctUntilChangedByKeyOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DistinctUntilChangedByKeyOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,8 +18,9 @@ package monix.reactive.internal.operators import cats.Eq -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import monix.reactive.Observable.Operator import scala.util.control.NonFatal @@ -34,9 +35,9 @@ private[reactive] final class DistinctUntilChangedByKeyOperator[A, K](key: A => new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false - private[this] var isFirst = true - private[this] var lastKey: K = _ + private var isDone = false + private var isFirst = true + private var lastKey: K = null.asInstanceOf[K] def onNext(elem: A): Future[Ack] = { // Protects calls to user code from within the operator and diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DistinctUntilChangedOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DistinctUntilChangedOperator.scala index 02d6761ca..bb44f0370 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DistinctUntilChangedOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DistinctUntilChangedOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.reactive.internal.operators import cats.Eq -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.Scheduler import scala.util.control.NonFatal @@ -31,8 +31,8 @@ private[reactive] final class DistinctUntilChangedOperator[A](implicit A: Eq[A]) def apply(out: Subscriber[A]): Subscriber[A] = new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isFirst = true - private[this] var lastElem: A = _ + private var isFirst = true + private var lastElem: A = null.asInstanceOf[A] def onNext(elem: A) = { // Protects calls to user code from within the operator and diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnCompleteOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnCompleteOperator.scala index 498e78546..3fb6f9ddb 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnCompleteOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnCompleteOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,8 @@ package monix.reactive.internal.operators import monix.eval.Task -import monix.execution.{Ack, Scheduler} +import monix.execution.Ack +import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnEarlyStopOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnEarlyStopOperator.scala index 50fe3f431..1820cd6b2 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnEarlyStopOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnEarlyStopOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,8 +18,9 @@ package monix.reactive.internal.operators import monix.eval.Task -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import monix.execution.atomic.Atomic import scala.util.control.NonFatal @@ -35,7 +36,7 @@ private[reactive] final class DoOnEarlyStopOperator[A](onStop: Task[Unit]) exten def apply(out: Subscriber[A]): Subscriber[A] = new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] val isActive = Atomic(true) + private val isActive = Atomic(true) def onNext(elem: A): Future[Ack] = { val result = diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnErrorOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnErrorOperator.scala index d72501b0a..ae55ffbeb 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnErrorOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnErrorOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,8 +18,8 @@ package monix.reactive.internal.operators import monix.eval.Task -import monix.execution.{Ack, Scheduler} - +import monix.execution.Ack +import monix.execution.Scheduler import scala.util.control.NonFatal import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnNextAckOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnNextAckOperator.scala index f2a42dd0e..37f7eabcc 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnNextAckOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnNextAckOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +20,7 @@ package monix.reactive.internal.operators import monix.eval.Task import monix.execution.{Ack, Scheduler} import monix.execution.Ack.Stop +import monix.execution.Scheduler import monix.execution.atomic.Atomic import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber @@ -32,7 +33,7 @@ private[reactive] final class DoOnNextAckOperator[A](cb: (A, Ack) => Task[Unit]) def apply(out: Subscriber[A]): Subscriber[A] = new Subscriber[A] { self => implicit val scheduler: Scheduler = out.scheduler - private[this] val isActive = Atomic(true) + private val isActive = Atomic(true) def onNext(elem: A): Future[Ack] = { // We are calling out.onNext directly, meaning that in onComplete/onError diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnStartOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnStartOperator.scala index ffe8e958b..718f4644c 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnStartOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnStartOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +20,7 @@ package monix.reactive.internal.operators import monix.eval.Task import monix.execution.{Ack, Scheduler} import monix.execution.Ack.Stop +import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber @@ -32,8 +33,8 @@ private[reactive] final class DoOnStartOperator[A](cb: A => Task[Unit]) extends new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false - private[this] var isStart = true + private var isDone = false + private var isStart = true def onNext(elem: A): Future[Ack] = { if (isStart) { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnSubscribeObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnSubscribeObservable.scala index 384581682..c6b0381f6 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnSubscribeObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnSubscribeObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,14 +20,16 @@ package monix.reactive.internal.operators import monix.execution.{Ack, Callback, Cancelable, FutureUtils, Scheduler} import monix.eval.Task import monix.execution.Ack.Stop +import monix.execution.Scheduler import monix.execution.atomic.Atomic -import monix.execution.cancelables.{OrderedCancelable, SingleAssignCancelable, StackedCancelable} +import monix.execution.cancelables.{ OrderedCancelable, SingleAssignCancelable, StackedCancelable } import monix.execution.schedulers.TrampolineExecutionContext.immediate +import monix.execution.{ Ack, Cancelable, FutureUtils } import monix.reactive.Observable import monix.reactive.observers.Subscriber -import scala.concurrent.{Future, Promise} -import scala.util.{Failure, Success} +import scala.concurrent.{ Future, Promise } +import scala.util.{ Failure, Success } private[reactive] object DoOnSubscribeObservable { // Implementation for doBeforeSubscribe @@ -61,8 +63,8 @@ private[reactive] object DoOnSubscribeObservable { val cancelable = source.unsafeSubscribeFn( new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] val completeGuard = Atomic(true) - private[this] var isActive = false + private val completeGuard = Atomic(true) + private var isActive = false def onNext(elem: A): Future[Ack] = { if (isActive) { @@ -79,12 +81,15 @@ private[reactive] object DoOnSubscribeObservable { out.onNext(elem) } } else { - FutureUtils.transformWith[Unit, Ack](p.future, { - case Success(_) => out.onNext(elem) - case Failure(e) => - finalSignal(e) - Stop - })(immediate) + FutureUtils.transformWith[Unit, Ack]( + p.future, + { + case Success(_) => out.onNext(elem) + case Failure(e) => + finalSignal(e) + Stop + } + )(immediate) } } @@ -107,12 +112,12 @@ private[reactive] object DoOnSubscribeObservable { ref := task.runAsync(new Callback[Throwable, Unit] { def onSuccess(value: Unit): Unit = { - conn.pop() + val _ = conn.pop() p.success(()) () } def onError(ex: Throwable): Unit = { - conn.pop() + val _ = conn.pop() p.failure(ex) () } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnSubscriptionCancelObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnSubscriptionCancelObservable.scala index 7279b6ab0..7979b40d1 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnSubscriptionCancelObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnSubscriptionCancelObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnTerminateOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnTerminateOperator.scala index bb985698b..dc71e5981 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnTerminateOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DoOnTerminateOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,12 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Callback, Scheduler} +import scala.annotation.nowarn +import monix.execution.Callback import monix.eval.Task -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import monix.execution.atomic.Atomic import scala.util.control.NonFatal @@ -30,16 +33,17 @@ import monix.reactive.observers.Subscriber import scala.concurrent.Future import scala.util.Success +@nowarn("msg=unused value of type") private[reactive] final class DoOnTerminateOperator[A]( onTerminate: Option[Throwable] => Task[Unit], - happensBefore: Boolean) - extends Operator[A, A] { + happensBefore: Boolean +) extends Operator[A, A] { def apply(out: Subscriber[A]): Subscriber[A] = new Subscriber[A] { // Wrapping in a cancelable in order to protect it from // being called multiple times - private[this] val active = Atomic(true) + private val active = Atomic(true) implicit val scheduler: Scheduler = out.scheduler def onNext(elem: A): Future[Ack] = { @@ -82,18 +86,19 @@ private[reactive] final class DoOnTerminateOperator[A]( if (active.getAndSet(false)) { var streamErrors = true try if (happensBefore) { - val task = onTerminate(ex).onErrorHandle { ex => - scheduler.reportFailure(ex) - } - streamErrors = false - task.map { _ => + val task = onTerminate(ex).onErrorHandle { ex => + scheduler.reportFailure(ex) + } + streamErrors = false + task.map { _ => + triggerSignal() + } + } else { + streamErrors = false triggerSignal() + onTerminate(ex) } - } else { - streamErrors = false - triggerSignal() - onTerminate(ex) - } catch { + catch { case err if NonFatal(err) => if (streamErrors) { out.onError(err) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DownstreamTimeoutObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DownstreamTimeoutObservable.scala index 38126511e..4247bd8b3 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DownstreamTimeoutObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DownstreamTimeoutObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,18 +17,20 @@ package monix.reactive.internal.operators +import scala.annotation.nowarn import java.util.concurrent.TimeUnit -import monix.execution.Ack.{Continue, Stop} -import monix.execution.cancelables.{CompositeCancelable, MultiAssignCancelable, SingleAssignCancelable} -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.cancelables.{ CompositeCancelable, MultiAssignCancelable, SingleAssignCancelable } +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.execution.exceptions.DownstreamTimeoutException import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.concurrent.Future -import scala.concurrent.duration.{FiniteDuration, MILLISECONDS} +import scala.concurrent.duration.{ FiniteDuration, MILLISECONDS } +@nowarn("msg=unused value of type") private[reactive] final class DownstreamTimeoutObservable[+A](source: Observable[A], timeout: FiniteDuration) extends Observable[A] { @@ -40,13 +42,13 @@ private[reactive] final class DownstreamTimeoutObservable[+A](source: Observable mainTask := source.unsafeSubscribeFn(new Subscriber[A] with Runnable { self => implicit val scheduler: Scheduler = downstream.scheduler - private[this] val timeoutMillis = timeout.toMillis + private val timeoutMillis = timeout.toMillis // MUST BE synchronized by `self` - private[this] var isProcessingOnNext = false + private var isProcessingOnNext = false // MUST BE synchronized by `self` - private[this] var isDone = false + private var isDone = false // MUST BE synchronized by `self` - private[this] var lastEmittedMillis: Long = + private var lastEmittedMillis: Long = scheduler.clockMonotonic(MILLISECONDS) locally { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropByPredicateOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropByPredicateOperator.scala index 35e0fcb57..b0dbf28fb 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropByPredicateOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropByPredicateOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,9 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} - +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import scala.util.control.NonFatal import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber @@ -31,8 +31,8 @@ private[reactive] final class DropByPredicateOperator[A](p: A => Boolean, inclus def apply(out: Subscriber[A]): Subscriber[A] = new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var continueDropping = true - private[this] var isDone = false + private var continueDropping = true + private var isDone = false def onNext(elem: A): Future[Ack] = { if (continueDropping) { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropByPredicateWithIndexOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropByPredicateWithIndexOperator.scala index 5dc572b1b..2b8ff0825 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropByPredicateWithIndexOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropByPredicateWithIndexOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,8 @@ package monix.reactive.internal.operators -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.Scheduler - import scala.util.control.NonFatal import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber @@ -29,9 +28,9 @@ private[reactive] final class DropByPredicateWithIndexOperator[A](p: (A, Int) => def apply(out: Subscriber[A]): Subscriber[A] = new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var continueDropping = true - private[this] var index = 0 - private[this] var isDone = false + private var continueDropping = true + private var index = 0 + private var isDone = false def onNext(elem: A) = { if (continueDropping) { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropByTimespanObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropByTimespanObservable.scala index fbfbcf38a..9341f5338 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropByTimespanObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropByTimespanObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,15 +17,18 @@ package monix.reactive.internal.operators +import scala.annotation.nowarn import monix.execution.Ack.Continue -import monix.execution.cancelables.{CompositeCancelable, SingleAssignCancelable} -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.Scheduler +import monix.execution.cancelables.{ CompositeCancelable, SingleAssignCancelable } +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.concurrent.Future import scala.concurrent.duration.FiniteDuration +@nowarn("msg=unused value of type") private[reactive] final class DropByTimespanObservable[A](source: Observable[A], timespan: FiniteDuration) extends Observable[A] { @@ -35,7 +38,7 @@ private[reactive] final class DropByTimespanObservable[A](source: Observable[A], composite += source.unsafeSubscribeFn(new Subscriber[A] with Runnable { self => implicit val scheduler: Scheduler = out.scheduler - @volatile private[this] var shouldDrop = true + @volatile private var shouldDrop = true locally { trigger := scheduler.scheduleOnce(timespan.length, timespan.unit, self) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropFirstOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropFirstOperator.scala index c8d1529a8..e89a086d6 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropFirstOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropFirstOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,7 +27,7 @@ private[reactive] final class DropFirstOperator[A](nr: Long) extends Operator[A, def apply(out: Subscriber[A]): Subscriber[A] = new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var count = 0L + private var count = 0L def onNext(elem: A) = { if (count < nr) { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropLastOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropLastOperator.scala index f7e7b2b84..77ba1c0b0 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropLastOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropLastOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,6 +19,7 @@ package monix.reactive.internal.operators import monix.execution.{Ack, Scheduler} import monix.execution.Ack.Continue +import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber @@ -32,8 +33,8 @@ private[reactive] final class DropLastOperator[A](n: Int) extends Operator[A, A] def apply(out: Subscriber[A]): Subscriber[A] = new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var queue = mutable.Queue.empty[A] - private[this] var length = 0 + private var queue = mutable.Queue.empty[A] + private var length = 0 override def onNext(elem: A): Future[Ack] = { queue.enqueue(elem) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropUntilObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropUntilObservable.scala index b92304fa5..b9d925de5 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropUntilObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DropUntilObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,14 +17,17 @@ package monix.reactive.internal.operators -import monix.execution.Ack.{Continue, Stop} -import monix.execution.cancelables.{CompositeCancelable, SingleAssignCancelable} -import monix.execution.{Ack, Cancelable, Scheduler} +import scala.annotation.nowarn +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler +import monix.execution.cancelables.{ CompositeCancelable, SingleAssignCancelable } +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.concurrent.Future +@nowarn("msg=unused value of type") private[reactive] final class DropUntilObservable[A](source: Observable[A], trigger: Observable[Any]) extends Observable[A] { @@ -35,11 +38,11 @@ private[reactive] final class DropUntilObservable[A](source: Observable[A], trig composite += source.unsafeSubscribeFn(new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isActive = true - private[this] var errorThrown: Throwable = null - @volatile private[this] var shouldDrop = true + private var isActive = true + private var errorThrown: Throwable = null + @volatile private var shouldDrop = true - private[this] def interruptDropMode(ex: Throwable = null): Ack = { + private def interruptDropMode(ex: Throwable /*| Null*/ ): Ack = { // must happen before changing shouldDrop errorThrown = ex shouldDrop = false diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DumpObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DumpObservable.scala index 19d018daa..8f57fe7a1 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DumpObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/DumpObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.operators import java.io.PrintStream import scala.util.control.NonFatal -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber @@ -34,7 +34,7 @@ private[reactive] final class DumpObservable[A](source: Observable[A], prefix: S val upstream = source.unsafeSubscribeFn(new Subscriber[A] { implicit val scheduler: Scheduler = subscriber.scheduler - private[this] val downstreamActive = Cancelable { () => + private val downstreamActive = Cancelable { () => pos += 1 out.println(s"$pos: $prefix stopped") } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/EchoObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/EchoObservable.scala index aa085d756..e8279533e 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/EchoObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/EchoObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,20 +18,21 @@ package monix.reactive.internal.operators import java.util.concurrent.TimeUnit -import monix.execution.Ack.{Continue, Stop} -import monix.execution.cancelables.{CompositeCancelable, MultiAssignCancelable, SingleAssignCancelable} -import monix.execution.{Ack, Cancelable, Scheduler} + +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.cancelables.{ CompositeCancelable, MultiAssignCancelable, SingleAssignCancelable } +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.concurrent.Future -import scala.concurrent.duration.{FiniteDuration, MILLISECONDS} +import scala.concurrent.duration.{ FiniteDuration, MILLISECONDS } import scala.util.Success private[reactive] final class EchoObservable[+A](source: Observable[A], timeout: FiniteDuration, onlyOnce: Boolean) extends Observable[A] { - private[this] val timeoutMillis = timeout.toMillis + private val timeoutMillis = timeout.toMillis def unsafeSubscribeFn(out: Subscriber[A]): Cancelable = { val task = MultiAssignCancelable() @@ -41,11 +42,11 @@ private[reactive] final class EchoObservable[+A](source: Observable[A], timeout: mainTask := source.unsafeSubscribeFn(new Subscriber[A] with Runnable { self => implicit val scheduler: Scheduler = out.scheduler - private[this] var ack: Future[Ack] = Continue - private[this] var lastEvent: A = _ - private[this] var lastTSInMillis: Long = 0L - private[this] var isDone = false - private[this] var hasValue = false + private var ack: Future[Ack] = Continue + private var lastEvent: A = null.asInstanceOf[A] + private var lastTSInMillis: Long = 0L + private var isDone = false + private var hasValue = false locally { scheduleNext(timeoutMillis) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/EndWithErrorOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/EndWithErrorOperator.scala index d01907fef..2c5e626f0 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/EndWithErrorOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/EndWithErrorOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,8 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Scheduler} +import monix.execution.Ack +import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ExecuteOnObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ExecuteOnObservable.scala index b2069421c..4b5098a6e 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ExecuteOnObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ExecuteOnObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,9 @@ package monix.reactive.internal.operators -import monix.execution.cancelables.{AssignableCancelable, SingleAssignCancelable} +import monix.execution.cancelables.{ AssignableCancelable, SingleAssignCancelable } import monix.execution.schedulers.TrampolinedRunnable -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.concurrent.Future diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FailedOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FailedOperator.scala index 0dfa02898..f78b4aea9 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FailedOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FailedOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,13 @@ package monix.reactive.internal.operators +import scala.annotation.nowarn import monix.execution.Ack.Continue import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber +@nowarn("msg=unused value of type") private[reactive] object FailedOperator extends Operator[Any, Throwable] { def apply(out: Subscriber[Throwable]): Subscriber[Any] = new Subscriber.Sync[Any] { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FilterOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FilterOperator.scala index e7d26131d..95a54145b 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FilterOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FilterOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,8 @@ package monix.reactive.internal.operators -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.Scheduler - import scala.util.control.NonFatal import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber @@ -29,7 +28,7 @@ private[reactive] final class FilterOperator[A](p: A => Boolean) extends Operato def apply(out: Subscriber[A]): Subscriber[A] = new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false + private var isDone = false def onNext(elem: A) = { // Protects calls to user code from within the operator and diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FlatScanObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FlatScanObservable.scala index 6bbdd9dc9..fd7733995 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FlatScanObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FlatScanObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,18 +17,19 @@ package monix.reactive.internal.operators -import monix.execution.Ack.{Continue, Stop} +import scala.annotation.nowarn +import monix.execution.Ack.{ Continue, Stop } import monix.execution.atomic.Atomic import monix.execution.atomic.PaddingStrategy.LeftRight128 import scala.util.control.NonFatal -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.execution.exceptions.CompositeException import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.annotation.tailrec -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.util.Failure /** Implementation for `Observable.scanTask`. @@ -37,12 +38,13 @@ import scala.util.Failure * * Tricky concurrency handling within, here be dragons! */ +@nowarn("msg=unused value of type") private[reactive] final class FlatScanObservable[A, R]( source: Observable[A], initial: () => R, op: (R, A) => Observable[R], - delayErrors: Boolean) - extends Observable[R] { + delayErrors: Boolean +) extends Observable[R] { def unsafeSubscribeFn(out: Subscriber[R]): Cancelable = { var streamErrors = true @@ -75,21 +77,21 @@ private[reactive] final class FlatScanObservable[A, R]( implicit val scheduler: Scheduler = out.scheduler // For gathering errors - private[this] val errors = + private val errors = if (delayErrors) Atomic(List.empty[Throwable]) else null // Boolean for keeping the `isActive` state, needed because we could miss // out on seeing a `Cancelled` state due to the `lazySet` instructions, // making the visibility of the `Cancelled` state thread-unsafe! - private[this] val isActive = Atomic(true) + private val isActive = Atomic(true) // For synchronizing our internal state machine, padded // in order to avoid the false sharing problem - private[this] val stateRef = Atomic.withPadding(WaitOnNextChild(Continue): FlatMapState, LeftRight128) + private val stateRef = Atomic.withPadding(WaitOnNextChild(Continue): FlatMapState, LeftRight128) // Mutable reference to the current state - private[this] var currentState = initial + private var currentState = initial /** For canceling the current active task, in case there is any. Here * we can afford a `compareAndSet`, not being a big deal since @@ -308,17 +310,18 @@ private[reactive] final class FlatScanObservable[A, R]( s"State $state in the Monix ConcatMap.$method implementation is invalid, " + "due to either a broken Subscriber implementation, or a bug, " + "please open an issue, see: https://monix.io" - )) + ) + ) // $COVERAGE-ON$ } private final class ChildSubscriber(out: Subscriber[R], asyncUpstreamAck: Promise[Ack]) extends Subscriber[R] { implicit val scheduler: Scheduler = out.scheduler - private[this] var ack: Future[Ack] = Continue + private var ack: Future[Ack] = Continue // Reusable reference to stop creating function references for each `onNext` - private[this] val onStopOrFailureRef = (err: Option[Throwable]) => { + private val onStopOrFailureRef = (err: Option[Throwable]) => { if (err.isDefined) out.scheduler.reportFailure(err.get) signalChildOnComplete(Stop, isStop = true) } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FoldLeftObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FoldLeftObservable.scala index f80170d10..68cb29c1e 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FoldLeftObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FoldLeftObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,13 +17,14 @@ package monix.reactive.internal.operators -import monix.execution.Ack.{Continue, Stop} - +import scala.annotation.nowarn +import monix.execution.Ack.{ Continue, Stop } import scala.util.control.NonFatal -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber +@nowarn("msg=unused value of type") private[reactive] final class FoldLeftObservable[A, R](source: Observable[A], initial: () => R, f: (R, A) => R) extends Observable[R] { @@ -35,8 +36,8 @@ private[reactive] final class FoldLeftObservable[A, R](source: Observable[A], in source.unsafeSubscribeFn(new Subscriber.Sync[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false - private[this] var state: R = initialState + private var isDone = false + private var state: R = initialState def onNext(elem: A): Ack = { // Protects calls to user code from within the operator, diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FoldWhileLeftObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FoldWhileLeftObservable.scala index 6a85a5b50..26a33e9ab 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FoldWhileLeftObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/FoldWhileLeftObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,10 +17,9 @@ package monix.reactive.internal.operators -import monix.execution.Ack.{Continue, Stop} - +import monix.execution.Ack.{ Continue, Stop } import scala.util.control.NonFatal -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber @@ -29,8 +28,8 @@ import scala.concurrent.Future private[reactive] final class FoldWhileLeftObservable[A, S]( source: Observable[A], seed: () => S, - op: (S, A) => Either[S, S]) - extends Observable[S] { + op: (S, A) => Either[S, S] +) extends Observable[S] { def unsafeSubscribeFn(out: Subscriber[S]): Cancelable = { var streamErrors = true @@ -40,8 +39,8 @@ private[reactive] final class FoldWhileLeftObservable[A, S]( source.unsafeSubscribeFn(new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false - private[this] var state = initialState + private var isDone = false + private var state = initialState def onNext(elem: A): Future[Ack] = { // Protects calls to user code from within the operator, diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/GroupByOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/GroupByOperator.scala index 6f0b10829..85a013e58 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/GroupByOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/GroupByOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,32 +17,32 @@ package monix.reactive.internal.operators -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.ChannelType.SingleProducer import monix.execution.atomic.Atomic import scala.util.control.NonFatal -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.observables.GroupedObservable import monix.reactive.Observable.Operator -import monix.reactive.observers.{BufferedSubscriber, Subscriber} -import monix.reactive.{Observer, OverflowStrategy} +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } +import monix.reactive.{ Observer, OverflowStrategy } import scala.annotation.tailrec import scala.concurrent.Future private[reactive] final class GroupByOperator[A, K]( os: OverflowStrategy.Synchronous[GroupedObservable[K, A]], - keyFn: A => K) - extends Operator[A, GroupedObservable[K, A]] { + keyFn: A => K +) extends Operator[A, GroupedObservable[K, A]] { def apply(subscriber: Subscriber[GroupedObservable[K, A]]): Subscriber[A] = new Subscriber[A] { self => implicit val scheduler: Scheduler = subscriber.scheduler - private[this] var isDone = false - private[this] val downstream = BufferedSubscriber(subscriber, os, SingleProducer) - private[this] val cacheRef = Atomic(Map.empty[K, Observer[A]]) + private var isDone = false + private val downstream = BufferedSubscriber(subscriber, os, SingleProducer) + private val cacheRef = Atomic(Map.empty[K, Observer[A]]) @tailrec - private[this] def recycleKey(key: K): Unit = { + private def recycleKey(key: K): Unit = { val current = cacheRef.get() if (!cacheRef.compareAndSet(current, current - key)) recycleKey(key) @@ -106,7 +106,7 @@ private[reactive] final class GroupByOperator[A, K]( } } - private[this] def foreachObserver(f: Observer[A] => Unit): Unit = { + private def foreachObserver(f: Observer[A] => Unit): Unit = { val cache = cacheRef.get() if (cacheRef.compareAndSet(cache, Map.empty)) { cache.values.foreach(f) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/GuaranteeCaseObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/GuaranteeCaseObservable.scala index 03ae53bbb..1011c379f 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/GuaranteeCaseObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/GuaranteeCaseObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,17 +20,17 @@ package monix.reactive.internal.operators import cats.effect.ExitCase import monix.execution.Callback import monix.eval.Task -import monix.execution.Ack.{Continue, Stop} -import monix.execution.atomic.{Atomic, AtomicBoolean} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.atomic.{ Atomic, AtomicBoolean } import monix.execution.internal.Platform import monix.execution.schedulers.TrampolineExecutionContext.immediate import monix.execution.schedulers.TrampolinedRunnable -import monix.execution.{Ack, Cancelable, FutureUtils, Scheduler} +import monix.execution.{ Ack, Cancelable, FutureUtils, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.concurrent.Future import scala.util.control.NonFatal -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } private[reactive] class GuaranteeCaseObservable[A](source: Observable[A], f: ExitCase[Throwable] => Task[Unit]) extends Observable[A] { @@ -67,7 +67,7 @@ private[reactive] class GuaranteeCaseObservable[A](source: Observable[A], f: Exi extends Subscriber[A] with Cancelable { implicit val scheduler: Scheduler = out.scheduler - private[this] var ack: Future[Ack] = Continue + private var ack: Future[Ack] = Continue def onNext(elem: A): Future[Ack] = { var catchErrors = true @@ -98,7 +98,7 @@ private[reactive] class GuaranteeCaseObservable[A](source: Observable[A], f: Exi FutureUtils.transformWith(async, asyncTransformRef)(immediate) } - private[this] val asyncTransformRef: Try[Ack] => Future[Ack] = { + private val asyncTransformRef: Try[Ack] => Future[Ack] = { case Success(value) => detectStopOrFailure(value) case Failure(e) => diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/IntersperseObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/IntersperseObservable.scala index 516623633..12a36e028 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/IntersperseObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/IntersperseObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,25 +18,24 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber - import scala.concurrent.Future private[reactive] final class IntersperseObservable[+A]( source: Observable[A], start: Option[A], separator: A, - end: Option[A]) - extends Observable[A] { self => + end: Option[A] +) extends Observable[A] { self => override def unsafeSubscribeFn(out: Subscriber[A]): Cancelable = { val upstream = source.unsafeSubscribeFn(new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var atLeastOne = false - private[this] var downstreamAck = Continue: Future[Ack] + private var atLeastOne = false + private var downstreamAck = Continue: Future[Ack] override def onNext(elem: A): Future[Ack] = { downstreamAck = if (!atLeastOne) { @@ -55,16 +54,16 @@ private[reactive] final class IntersperseObservable[+A]( } def onError(ex: Throwable) = { - downstreamAck.syncOnContinue(out.onError(ex)) - () + val _ = downstreamAck.syncOnContinue(out.onError(ex)) } def onComplete() = { - downstreamAck.syncOnContinue { - if (atLeastOne && end.nonEmpty) out.onNext(end.get) + val _ = downstreamAck.syncOnContinue { + if (atLeastOne && end.nonEmpty) { + val _ = out.onNext(end.get) + } out.onComplete() } - () } }) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/IsEmptyOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/IsEmptyOperator.scala index e3acf3398..0198cc5af 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/IsEmptyOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/IsEmptyOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,17 +17,20 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Scheduler} +import scala.annotation.nowarn +import monix.execution.Ack import monix.execution.Ack.Stop +import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber +@nowarn("msg=unused value of type") private[reactive] object IsEmptyOperator extends Operator[Any, Boolean] { def apply(out: Subscriber[Boolean]): Subscriber[Any] = new Subscriber[Any] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false - private[this] var isEmpty = true + private var isDone = false + private var isEmpty = true def onNext(elem: Any): Ack = { isEmpty = false diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/LiftByOperatorObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/LiftByOperatorObservable.scala index 017f0adba..e49c770f0 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/LiftByOperatorObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/LiftByOperatorObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapAccumulateObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapAccumulateObservable.scala index 4d9009702..bbe0a93f1 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapAccumulateObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapAccumulateObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Stop import scala.util.control.NonFatal -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber @@ -28,8 +28,8 @@ import scala.concurrent.Future private[reactive] final class MapAccumulateObservable[A, S, R]( source: Observable[A], initial: () => S, - f: (S, A) => (S, R)) - extends Observable[R] { + f: (S, A) => (S, R) +) extends Observable[R] { def unsafeSubscribeFn(out: Subscriber[R]): Cancelable = { var streamErrors = true @@ -40,8 +40,8 @@ private[reactive] final class MapAccumulateObservable[A, S, R]( // Initial state was evaluated, subscribing to source source.unsafeSubscribeFn(new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false - private[this] var state = initialState + private var isDone = false + private var state = initialState def onNext(elem: A): Future[Ack] = { // Protects calls to user code from within the operator and diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapOperator.scala index f5eb5f540..e6cbd5579 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.operators import monix.execution.{Ack, Scheduler} import monix.execution.Ack.Stop - +import monix.execution.Scheduler import scala.util.control.NonFatal import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber @@ -31,7 +31,7 @@ private[reactive] final class MapOperator[-A, +B](f: A => B) extends Operator[A, def apply(out: Subscriber[B]): Subscriber[A] = { new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false + private var isDone = false def onNext(elem: A): Future[Ack] = { // Protects calls to user code from within the operator and diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapParallelOrderedObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapParallelOrderedObservable.scala index ba1480d6e..70645d001 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapParallelOrderedObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapParallelOrderedObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,23 +19,24 @@ package monix.reactive.internal.operators import java.util.concurrent.ConcurrentLinkedQueue import monix.eval.Task -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.cancelables.CompositeCancelable import monix.execution.{Ack, AsyncSemaphore, Cancelable, CancelableFuture, Scheduler} import monix.execution.ChannelType.MultiProducer -import monix.reactive.observers.{BufferedSubscriber, Subscriber} -import monix.reactive.{Observable, OverflowStrategy} +import monix.execution.{ Ack, Cancelable, CancelableFuture, Scheduler } +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } +import monix.reactive.{ Observable, OverflowStrategy } import scala.concurrent.Future import scala.util.control.NonFatal -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } private[reactive] final class MapParallelOrderedObservable[A, B]( source: Observable[A], parallelism: Int, f: A => Task[B], - overflowStrategy: OverflowStrategy[B]) - extends Observable[B] { + overflowStrategy: OverflowStrategy[B] +) extends Observable[B] { override def unsafeSubscribeFn(out: Subscriber[B]): Cancelable = { if (parallelism <= 0) { @@ -57,24 +58,24 @@ private[reactive] final class MapParallelOrderedObservable[A, B]( implicit val scheduler: Scheduler = out.scheduler // Ensures we don't execute more than a maximum number of tasks in parallel - private[this] val semaphore = AsyncSemaphore(parallelism.toLong) + private val semaphore = AsyncSemaphore(parallelism.toLong) // Buffer with the supplied overflow strategy. - private[this] val buffer = BufferedSubscriber[B](out, overflowStrategy, MultiProducer) + private val buffer = BufferedSubscriber[B](out, overflowStrategy, MultiProducer) // Flag indicating whether a final event was called, after which // nothing else can happen. It's a very light protection, as // access to it is concurrent and not synchronized - private[this] var isDone = false + private var isDone = false // Turns to `Stop` when a stop acknowledgement is observed // coming from the `buffer` - this indicates that the downstream // no longer wants any events, so we must cancel - private[this] var lastAck: Ack = Continue + private var lastAck: Ack = Continue // Buffer for signaling new elements downstream preserving original order // It needs to be thread safe Queue because we want to allow adding and removing // elements at the same time. - private[this] val queue = new ConcurrentLinkedQueue[CancelableFuture[B]] + private val queue = new ConcurrentLinkedQueue[CancelableFuture[B]] // This lock makes sure that only one thread at the time sends processed elements downstream - private[this] val sendDownstreamSemaphore = AsyncSemaphore(1) + private val sendDownstreamSemaphore = AsyncSemaphore(1) private def shouldStop: Boolean = isDone || lastAck == Stop diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapParallelUnorderedObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapParallelUnorderedObservable.scala index 1e7937bdb..4a73aea01 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapParallelUnorderedObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapParallelUnorderedObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,17 +17,17 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, AsyncSemaphore, Callback, Cancelable, Scheduler} +import monix.execution.{ Ack, AsyncSemaphore, Callback, Cancelable, Scheduler } import monix.eval.Task -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.ChannelType.MultiProducer -import monix.execution.cancelables.{CompositeCancelable, SingleAssignCancelable} -import monix.reactive.{Observable, OverflowStrategy} -import monix.reactive.observers.{BufferedSubscriber, Subscriber} +import monix.execution.cancelables.{ CompositeCancelable, SingleAssignCancelable } +import monix.reactive.{ Observable, OverflowStrategy } +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } import scala.concurrent.Future import scala.util.control.NonFatal -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } /** Implementation for a `mapTask`-like operator that can execute * multiple tasks in parallel. Similar with @@ -45,8 +45,8 @@ private[reactive] final class MapParallelUnorderedObservable[A, B]( source: Observable[A], parallelism: Int, f: A => Task[B], - overflowStrategy: OverflowStrategy[B]) - extends Observable[B] { + overflowStrategy: OverflowStrategy[B] +) extends Observable[B] { def unsafeSubscribeFn(out: Subscriber[B]): Cancelable = { if (parallelism <= 0) { @@ -68,18 +68,18 @@ private[reactive] final class MapParallelUnorderedObservable[A, B]( implicit val scheduler: Scheduler = out.scheduler // Ensures we don't execute more than a maximum number of tasks in parallel - private[this] val semaphore = AsyncSemaphore(parallelism.toLong) + private val semaphore = AsyncSemaphore(parallelism.toLong) // Buffer with the supplied overflow strategy. - private[this] val buffer = BufferedSubscriber[B](out, overflowStrategy, MultiProducer) + private val buffer = BufferedSubscriber[B](out, overflowStrategy, MultiProducer) // Flag indicating whether a final event was called, after which // nothing else can happen. It's a very light protection, as // access to it is concurrent and not synchronized - private[this] var isDone = false + private var isDone = false // Turns to `Stop` when a stop acknowledgement is observed // coming from the `buffer` - this indicates that the downstream // no longer wants any events, so we must cancel - private[this] var lastAck: Ack = Continue + private var lastAck: Ack = Continue private def process(elem: A) = { // For protecting against user code, without violating the diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapTaskObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapTaskObservable.scala index a01a86e81..cc556137a 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapTaskObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MapTaskObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ import monix.execution.atomic.Atomic import monix.execution.atomic.PaddingStrategy.LeftRight128 import scala.util.control.NonFatal -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber @@ -84,13 +84,13 @@ private[reactive] final class MapTaskObservable[A, B](source: Observable[A], f: // For synchronizing our internal state machine, padded // in order to avoid the false sharing problem - private[this] val stateRef = + private val stateRef = Atomic.withPadding(WaitOnNext: MapTaskState, LeftRight128) // Boolean for keeping the `isActive` state, needed because we could miss // out on seeing a `Cancelled` state due to the `lazySet` instructions, // making the visibility of the `Cancelled` state thread-unsafe! - private[this] val isActive = Atomic(true) + private val isActive = Atomic(true) /** For canceling the current active task, in case there is any. Here * we can afford a `compareAndSet`, not being a big deal since @@ -224,7 +224,7 @@ private[reactive] final class MapTaskObservable[A, B](source: Observable[A], f: // Reusable function reference, to prevent creating a new instance // on each `onNext` / `transformWith` call below - private[this] val childOnSuccess = (value: B) => { + private val childOnSuccess = (value: B) => { // Shoot first, ask questions later :-) val next = out.onNext(value) @@ -257,7 +257,7 @@ private[reactive] final class MapTaskObservable[A, B](source: Observable[A], f: // Reusable function reference, to prevent creating a new instance // on each `onNext` / `transformWith` call below - private[this] val childOnError = (error: Throwable) => { + private val childOnError = (error: Throwable) => { // The cancelable passed in WaitComplete here can be `null` // because it would only replace the child's own cancelable stateRef.getAndSet(WaitComplete(Some(error), null)) match { @@ -352,7 +352,8 @@ private[reactive] final class MapTaskObservable[A, B](source: Observable[A], f: s"State $state in the Monix MapTask.$method implementation is invalid, " + "due to either a broken Subscriber implementation, or a bug, " + s"please open an issue, see: https://monix.io. Executed function: $f" - )) + ) + ) // $COVERAGE-ON$ } } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MaterializeOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MaterializeOperator.scala index 396596d26..40c125361 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MaterializeOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MaterializeOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,22 +17,25 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Scheduler} +import scala.annotation.nowarn +import monix.execution.Ack import monix.execution.Ack.Continue +import monix.execution.Scheduler import monix.reactive.Notification -import monix.reactive.Notification.{OnComplete, OnError, OnNext} +import monix.reactive.Notification.{ OnComplete, OnError, OnNext } import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber import scala.concurrent.Future +@nowarn("msg=unused value of type") private[reactive] final class MaterializeOperator[A] extends Operator[A, Notification[A]] { def apply(out: Subscriber[Notification[A]]): Subscriber[A] = new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false - private[this] var ack: Future[Ack] = Continue + private var isDone = false + private var ack: Future[Ack] = Continue def onNext(elem: A): Future[Ack] = { ack = out.onNext(OnNext(elem)) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MergeMapObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MergeMapObservable.scala index 6ebf2cda9..8e1e6defd 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MergeMapObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/MergeMapObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,40 +17,42 @@ package monix.reactive.internal.operators -import monix.execution.Ack.{Continue, Stop} +import scala.annotation.nowarn +import monix.execution.Ack.{ Continue, Stop } import monix.execution.ChannelType.MultiProducer -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.execution.cancelables._ import monix.execution.exceptions.CompositeException -import monix.reactive.observers.{BufferedSubscriber, Subscriber} -import monix.reactive.{Observable, OverflowStrategy} +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } +import monix.reactive.{ Observable, OverflowStrategy } import monix.execution.atomic.Atomic import scala.util.control.NonFatal import scala.collection.mutable +@nowarn("msg=unused value of type") private[reactive] final class MergeMapObservable[A, B]( source: Observable[A], f: A => Observable[B], overflowStrategy: OverflowStrategy[B], - delayErrors: Boolean) - extends Observable[B] { + delayErrors: Boolean +) extends Observable[B] { def unsafeSubscribeFn(downstream: Subscriber[B]): Cancelable = { val composite = CompositeCancelable() composite += source.unsafeSubscribeFn(new Subscriber[A] { implicit val scheduler: Scheduler = downstream.scheduler - private[this] val subscriberB: Subscriber[B] = + private val subscriberB: Subscriber[B] = BufferedSubscriber(downstream, overflowStrategy, MultiProducer) - private[this] val upstreamIsDone = Atomic(false) - private[this] val errors = + private val upstreamIsDone = Atomic(false) + private val errors = if (delayErrors) mutable.ArrayBuffer.empty[Throwable] else null - private[this] val refCount = RefCountCancelable { () => + private val refCount = RefCountCancelable { () => if (!upstreamIsDone.getAndSet(true)) { if (delayErrors) errors.synchronized { @@ -58,7 +60,8 @@ private[reactive] final class MergeMapObservable[A, B]( subscriberB.onError(CompositeException(errors.toSeq)) else subscriberB.onComplete() - } else { + } + else { subscriberB.onComplete() } } @@ -94,7 +97,8 @@ private[reactive] final class MergeMapObservable[A, B]( if (delayErrors) errors.synchronized { errors += ex refID.cancel() - } else if (!upstreamIsDone.getAndSet(true)) { + } + else if (!upstreamIsDone.getAndSet(true)) { try subscriberB.onError(ex) finally composite.cancel() } @@ -122,7 +126,8 @@ private[reactive] final class MergeMapObservable[A, B]( if (delayErrors) errors.synchronized { errors += ex onComplete() - } else if (!upstreamIsDone.getAndSet(true)) { + } + else if (!upstreamIsDone.getAndSet(true)) { // oops, error happened on main thread, // piping that along should cancel everything composite.cancel() diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ObserveOnObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ObserveOnObservable.scala index f7fa9be4d..1b6dca71f 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ObserveOnObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ObserveOnObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,9 +18,9 @@ package monix.reactive.internal.operators import monix.execution.ChannelType.SingleProducer -import monix.execution.{Ack, Cancelable, Scheduler} -import monix.reactive.{Observable, OverflowStrategy} -import monix.reactive.observers.{BufferedSubscriber, Subscriber} +import monix.execution.{ Ack, Cancelable, Scheduler } +import monix.reactive.{ Observable, OverflowStrategy } +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } import scala.concurrent.Future diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/OnCancelTriggerErrorObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/OnCancelTriggerErrorObservable.scala index 86d31a603..e31007daa 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/OnCancelTriggerErrorObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/OnCancelTriggerErrorObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,8 +17,9 @@ package monix.reactive.internal.operators -import monix.execution.Ack.{Continue, Stop} -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.{ Ack, Cancelable } +import monix.execution.Scheduler import monix.reactive.Observable import monix.reactive.observers.Subscriber @@ -30,7 +31,7 @@ private[reactive] final class OnCancelTriggerErrorObservable[A](source: Observab def unsafeSubscribeFn(downstream: Subscriber[A]): Cancelable = { val out: Subscriber[A] = new Subscriber[A] { self => implicit val scheduler: Scheduler = downstream.scheduler - private[this] var isDone = false + private var isDone = false def onNext(elem: A): Future[Ack] = self.synchronized { @@ -70,7 +71,7 @@ private[reactive] final class OnCancelTriggerErrorObservable[A](source: Observab Stop } } else { - ack.onComplete(result => self.synchronized(stopStreamOnCancel(ack))) + ack.onComplete(_ => self.synchronized(stopStreamOnCancel(ack))) ack } } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/OnErrorRecoverWithObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/OnErrorRecoverWithObservable.scala index 7a2362874..30377d716 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/OnErrorRecoverWithObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/OnErrorRecoverWithObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,10 +18,11 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue +import monix.execution.Scheduler import monix.execution.cancelables.OrderedCancelable import scala.util.control.NonFatal -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber @@ -35,7 +36,7 @@ private[reactive] final class OnErrorRecoverWithObservable[A](source: Observable val main = source.unsafeSubscribeFn(new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var ack: Future[Ack] = Continue + private var ack: Future[Ack] = Continue def onNext(elem: A) = { ack = out.onNext(elem) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/OnErrorRetryCountedObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/OnErrorRetryCountedObservable.scala index 7f63e86db..4ef3da0e1 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/OnErrorRetryCountedObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/OnErrorRetryCountedObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue import monix.execution.cancelables.OrderedCancelable -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.concurrent.Future @@ -31,8 +31,8 @@ private[reactive] final class OnErrorRetryCountedObservable[+A](source: Observab private def loop(subscriber: Subscriber[A], task: OrderedCancelable, retryIdx: Long): Unit = { val cancelable = source.unsafeSubscribeFn(new Subscriber[A] { implicit val scheduler: Scheduler = subscriber.scheduler - private[this] var isDone = false - private[this] var ack: Future[Ack] = Continue + private var isDone = false + private var ack: Future[Ack] = Continue def onNext(elem: A) = { ack = subscriber.onNext(elem) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/OnErrorRetryIfObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/OnErrorRetryIfObservable.scala index 1cfd848fd..02dd02ffc 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/OnErrorRetryIfObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/OnErrorRetryIfObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.execution.cancelables.OrderedCancelable import scala.util.control.NonFatal import monix.reactive.Observable @@ -33,8 +33,8 @@ private[reactive] final class OnErrorRetryIfObservable[+A](source: Observable[A] private def loop(subscriber: Subscriber[A], task: OrderedCancelable, retryIdx: Long): Unit = { val cancelable = source.unsafeSubscribeFn(new Subscriber[A] { implicit val scheduler: Scheduler = subscriber.scheduler - private[this] var isDone = false - private[this] var ack: Future[Ack] = Continue + private var isDone = false + private var ack: Future[Ack] = Continue def onNext(elem: A): Future[Ack] = { ack = subscriber.onNext(elem) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/PipeThroughObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/PipeThroughObservable.scala index 5450e431e..db93c71a1 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/PipeThroughObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/PipeThroughObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,10 +18,10 @@ package monix.reactive.internal.operators import monix.execution.cancelables.SingleAssignCancelable -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable } +import monix.execution.Scheduler import monix.reactive.observers.Subscriber -import monix.reactive.{Observable, Pipe} - +import monix.reactive.{ Observable, Pipe } import scala.concurrent.Future private[reactive] final class PipeThroughObservable[A, B](source: Observable[A], pipe: Pipe[A, B]) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ReduceOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ReduceOperator.scala index 6aecb6bbf..d061d1644 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ReduceOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ReduceOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,9 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} - +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import scala.util.control.NonFatal import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber @@ -32,9 +32,9 @@ private[reactive] final class ReduceOperator[A](op: (A, A) => A) extends Operato new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false - private[this] var state: A = _ - private[this] var isFirst = true + private var isDone = false + private var state: A = null.asInstanceOf[A] + private var isFirst = true def onNext(elem: A): Future[Ack] = { try { @@ -56,7 +56,7 @@ private[reactive] final class ReduceOperator[A](op: (A, A) => A) extends Operato def onComplete(): Unit = if (!isDone) { isDone = true - if (!isFirst) out.onNext(state) + if (!isFirst) { val _ = out.onNext(state) } out.onComplete() } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/RepeatSourceObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/RepeatSourceObservable.scala index fc750203a..bc5aea83c 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/RepeatSourceObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/RepeatSourceObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,12 +18,12 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue -import monix.execution.cancelables.{CompositeCancelable, OrderedCancelable} -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.cancelables.{ CompositeCancelable, OrderedCancelable } +import monix.execution.{ Ack, Cancelable } +import monix.execution.Scheduler import monix.reactive.Observable import monix.reactive.observers.Subscriber -import monix.reactive.subjects.{ReplaySubject, Subject} - +import monix.reactive.subjects.{ ReplaySubject, Subject } import scala.concurrent.Future import scala.util.Success @@ -35,9 +35,9 @@ private[reactive] final class RepeatSourceObservable[A](source: Observable[A]) e val cancelable = subject.unsafeSubscribeFn(new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isEmpty = true - private[this] var isDone = false - private[this] var ack: Future[Ack] = Continue + private var isEmpty = true + private var isDone = false + private var ack: Future[Ack] = Continue def onNext(elem: A): Future[Ack] = { if (isEmpty) isEmpty = false diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/RestartUntilObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/RestartUntilObservable.scala index 2a6f7408f..6b657604d 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/RestartUntilObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/RestartUntilObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Stop import monix.execution.cancelables.SerialCancelable import scala.util.control.NonFatal -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber @@ -41,8 +41,8 @@ private[reactive] final class RestartUntilObservable[A](source: Observable[A], p synchronized { subscription := source.unsafeSubscribeFn(new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isValidated = false - private[this] var isDone = false + private var isValidated = false + private var isDone = false def onNext(elem: A): Future[Ack] = { // Stream was validated, so we can just stream the event. @@ -64,9 +64,7 @@ private[reactive] final class RestartUntilObservable[A](source: Observable[A], p isDone = true // Then we force an asynchronous boundary and retry - out.scheduler.execute(new Runnable { - def run(): Unit = loop(out, subscription) - }) + out.scheduler.execute(() => loop(out, subscription)) // Signal the current upstream to stop. // Current upstream will also be cancel when the diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ScanObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ScanObservable.scala index ce0460f31..87b4fb226 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ScanObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ScanObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,9 +18,9 @@ package monix.reactive.internal.operators import monix.execution.Ack.Stop - +import monix.execution.Scheduler import scala.util.control.NonFatal -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber @@ -38,8 +38,8 @@ private[reactive] final class ScanObservable[A, R](source: Observable[A], initia // Initial state was evaluated, subscribing to source source.unsafeSubscribeFn(new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false - private[this] var state = initialState + private var isDone = false + private var state = initialState def onNext(elem: A): Future[Ack] = { // Protects calls to user code from within the operator and diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ScanTaskObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ScanTaskObservable.scala index 1f40d9bcb..83078439f 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ScanTaskObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ScanTaskObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,11 +20,13 @@ package monix.reactive.internal.operators import monix.execution.{Ack, Callback, Cancelable, Scheduler} import monix.eval.Task import monix.execution.Ack.Stop +import monix.execution.Scheduler import monix.execution.atomic.Atomic import monix.execution.atomic.PaddingStrategy.LeftRight128 import monix.execution.cancelables.OrderedCancelable import scala.util.control.NonFatal +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber @@ -71,15 +73,15 @@ private[reactive] final class ScanTaskObservable[A, S](source: Observable[A], se // For synchronizing our internal state machine, padded // in order to avoid the false sharing problem - private[this] val stateRef = Atomic.withPadding(WaitOnNext: MapTaskState, LeftRight128) + private val stateRef = Atomic.withPadding(WaitOnNext: MapTaskState, LeftRight128) // Boolean for keeping the `isActive` state, needed because we could miss // out on seeing a `Cancelled` state due to the `lazySet` instructions, // making the visibility of the `Cancelled` state thread-unsafe! - private[this] val isActive = Atomic(true) + private val isActive = Atomic(true) // Current state, keeps getting updated by the task in `onNext` - private[this] var currentS = initial + private var currentS = initial /** For canceling the current active task, in case there is any. Here * we can afford a `compareAndSet`, not being a big deal since @@ -213,7 +215,7 @@ private[reactive] final class ScanTaskObservable[A, S](source: Observable[A], se // Reusable function reference, to prevent creating a new instance // on each `onNext` / `transformWith` call below - private[this] val childOnSuccess = (value: S) => { + private val childOnSuccess = (value: S) => { // Updating mutable shared state, no need for synchronization // because `onNext` operations are ordered currentS = value @@ -249,7 +251,7 @@ private[reactive] final class ScanTaskObservable[A, S](source: Observable[A], se // Reusable function reference, to prevent creating a new instance // on each `onNext` / `transformWith` call below - private[this] val childOnError = (error: Throwable) => { + private val childOnError = (error: Throwable) => { // The cancelable passed in WaitComplete here can be `null` // because it would only replace the child's own cancelable stateRef.getAndSet(WaitComplete(Some(error), null)) match { @@ -344,7 +346,8 @@ private[reactive] final class ScanTaskObservable[A, S](source: Observable[A], se s"State $state in the Monix MapTask.$method implementation is invalid, " + "due to either a broken Subscriber implementation, or a bug, " + "please open an issue, see: https://monix.io" - )) + ) + ) // $COVERAGE-ON$ } } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/SearchByOrderOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/SearchByOrderOperator.scala index 8605915bf..153132b8c 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/SearchByOrderOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/SearchByOrderOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,11 @@ package monix.reactive.internal.operators +import scala.annotation.nowarn import cats.Order -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import scala.util.control.NonFatal import monix.reactive.Observable.Operator @@ -28,7 +30,9 @@ import monix.reactive.observers.Subscriber /** * Common implementation for `minF`, `minByF`, `maxF`, `maxByF`. */ -private[reactive] abstract class SearchByOrderOperator[A, K](key: A => K)(implicit B: Order[K]) extends Operator[A, A] { +@nowarn("msg=unused value of type") +private[reactive] abstract class SearchByOrderOperator[A, K](key: A => K) + extends Operator[A, A] { def shouldCollect(key: K, current: K): Boolean @@ -36,10 +40,10 @@ private[reactive] abstract class SearchByOrderOperator[A, K](key: A => K)(implic new Subscriber.Sync[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false - private[this] var minValue: A = _ - private[this] var minValueU: K = _ - private[this] var hasValue = false + private var isDone = false + private var minValue: A = null.asInstanceOf[A] + private var minValueU: K = null.asInstanceOf[K] + private var hasValue = false def onNext(elem: A): Ack = { try { @@ -54,7 +58,6 @@ private[reactive] abstract class SearchByOrderOperator[A, K](key: A => K)(implic minValueU = m } } - Continue } catch { case ex if NonFatal(ex) => @@ -82,28 +85,30 @@ private[reactive] abstract class SearchByOrderOperator[A, K](key: A => K)(implic } } -private[reactive] final class MinOperator[A](implicit A: Order[A]) extends SearchByOrderOperator[A, A](identity)(A) { +private[reactive] final class MinOperator[A](implicit ord: Order[A]) + extends SearchByOrderOperator[A, A](identity) { def shouldCollect(key: A, current: A): Boolean = - A.compare(key, current) < 0 + ord.compare(key, current) < 0 } -private[reactive] final class MinByOperator[A, K](f: A => K)(implicit K: Order[K]) - extends SearchByOrderOperator[A, K](f)(K) { +private[reactive] final class MinByOperator[A, K](f: A => K)(implicit ord: Order[K]) + extends SearchByOrderOperator[A, K](f) { def shouldCollect(key: K, current: K): Boolean = - K.compare(key, current) < 0 + ord.compare(key, current) < 0 } -private[reactive] final class MaxOperator[A](implicit A: Order[A]) extends SearchByOrderOperator[A, A](identity)(A) { +private[reactive] final class MaxOperator[A](implicit ord: Order[A]) + extends SearchByOrderOperator[A, A](identity) { def shouldCollect(key: A, current: A): Boolean = - A.compare(key, current) > 0 + ord.compare(key, current) > 0 } -private[reactive] final class MaxByOperator[A, K](f: A => K)(implicit K: Order[K]) - extends SearchByOrderOperator[A, K](f)(K) { +private[reactive] final class MaxByOperator[A, K](f: A => K)(implicit ord: Order[K]) + extends SearchByOrderOperator[A, K](f) { def shouldCollect(key: K, current: K): Boolean = - K.compare(key, current) > 0 + ord.compare(key, current) > 0 } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/SubscribeOnObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/SubscribeOnObservable.scala index ea8000345..9aa87d643 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/SubscribeOnObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/SubscribeOnObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.reactive.internal.operators import monix.execution.cancelables.SingleAssignCancelable -import monix.execution.{Cancelable, Scheduler} +import monix.execution.{ Cancelable, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber @@ -27,11 +27,9 @@ private[reactive] final class SubscribeOnObservable[+A](source: Observable[A], s def unsafeSubscribeFn(out: Subscriber[A]): Cancelable = { val subscription = SingleAssignCancelable() - s.execute(new Runnable { - def run(): Unit = { - subscription := source.unsafeSubscribeFn(out) - () - } + s.execute(() => { + subscription := source.unsafeSubscribeFn(out) + () }) subscription diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/SwitchIfEmptyObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/SwitchIfEmptyObservable.scala index d0ec0fec8..78fd60edd 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/SwitchIfEmptyObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/SwitchIfEmptyObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,8 @@ package monix.reactive.internal.operators import monix.execution.cancelables.OrderedCancelable -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable } +import monix.execution.Scheduler import monix.reactive.Observable import monix.reactive.observers.Subscriber @@ -32,7 +33,7 @@ private[reactive] final class SwitchIfEmptyObservable[+A](source: Observable[A], val mainSub = source.unsafeSubscribeFn(new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isEmpty = true + private var isEmpty = true def onNext(elem: A): Future[Ack] = { if (isEmpty) isEmpty = false diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/SwitchMapObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/SwitchMapObservable.scala index 1472bfc5d..50c7c8dcc 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/SwitchMapObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/SwitchMapObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,16 +17,18 @@ package monix.reactive.internal.operators -import monix.execution.Ack.{Continue, Stop} -import monix.execution.cancelables.{CompositeCancelable, SerialCancelable, SingleAssignCancelable} - +import scala.annotation.nowarn +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler +import monix.execution.cancelables.{ CompositeCancelable, SerialCancelable, SingleAssignCancelable } import scala.util.control.NonFatal -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable } import monix.reactive.observers.Subscriber -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future +@nowarn("msg=unused value of type") private[reactive] final class SwitchMapObservable[A, B](source: Observable[A], f: A => Observable[B]) extends Observable[B] { @@ -38,13 +40,13 @@ private[reactive] final class SwitchMapObservable[A, B](source: Observable[A], f mainTask := source.unsafeSubscribeFn(new Subscriber.Sync[A] { self => implicit val scheduler: Scheduler = out.scheduler // MUST BE synchronized by `self` - private[this] var ack: Future[Ack] = Continue + private var ack: Future[Ack] = Continue // MUST BE synchronized by `self` - private[this] var activeChildIndex: Int = -1 + private var activeChildIndex: Int = -1 // MUST BE synchronized by `self` - private[this] var upstreamIsDone: Boolean = false + private var upstreamIsDone: Boolean = false // MUST BE synchronized by `self` - private[this] var lastChildIsDone: Boolean = false + private var lastChildIsDone: Boolean = false def onNext(elem: A): Ack = self.synchronized { if (upstreamIsDone) Stop diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeByPredicateOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeByPredicateOperator.scala index dd8247fa9..7bef5a2b7 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeByPredicateOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeByPredicateOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.operators import monix.execution.{Ack, Scheduler} import monix.execution.Ack.Stop - +import monix.execution.Scheduler import scala.util.control.NonFatal import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber @@ -31,7 +31,7 @@ private[reactive] final class TakeByPredicateOperator[A](p: A => Boolean, inclus def apply(out: Subscriber[A]): Subscriber[A] = new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isActive = true + private var isActive = true def onNext(elem: A): Future[Ack] = { if (!isActive) Stop @@ -47,7 +47,7 @@ private[reactive] final class TakeByPredicateOperator[A](p: A => Boolean, inclus } else { isActive = false if (inclusive) { - out.onNext(elem) + val _ = out.onNext(elem) } out.onComplete() Stop diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeEveryNthOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeEveryNthOperator.scala index cb289fd0b..3399bb454 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeEveryNthOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeEveryNthOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,6 +19,7 @@ package monix.reactive.internal.operators import monix.execution.{Ack, Scheduler} import monix.execution.Ack.Continue +import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber @@ -31,7 +32,7 @@ private[reactive] final class TakeEveryNthOperator[A](n: Int) extends Operator[A def apply(out: Subscriber[A]): Subscriber[A] = new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var index = n + private var index = n def onNext(elem: A): Future[Ack] = { index -= 1 diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeLastObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeLastObservable.scala index e9890e5f0..6b463b587 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeLastObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeLastObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,8 +17,10 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Scheduler} +import scala.annotation.nowarn +import monix.execution.Ack import monix.execution.Ack.Continue +import monix.execution.Scheduler import monix.execution.cancelables.AssignableCancelable import monix.reactive.Observable import monix.reactive.observables.ChainedObservable @@ -26,32 +28,37 @@ import monix.reactive.observers.Subscriber import scala.collection.mutable +@nowarn("msg=unused value of type") private[reactive] final class TakeLastObservable[A](source: Observable[A], n: Int) extends ChainedObservable[A] { override def unsafeSubscribeFn(conn: AssignableCancelable.Multi, out: Subscriber[A]): Unit = { - ChainedObservable.subscribe(source, conn, new Subscriber[A] { - implicit val scheduler: Scheduler = out.scheduler - private[this] val queue = mutable.Queue.empty[A] - private[this] var queued = 0 - - def onNext(elem: A): Ack = { - queue.enqueue(elem) - if (queued < n) - queued += 1 - else - queue.dequeue() - Continue - } + ChainedObservable.subscribe( + source, + conn, + new Subscriber[A] { + implicit val scheduler: Scheduler = out.scheduler + private val queue = mutable.Queue.empty[A] + private var queued = 0 - def onComplete(): Unit = { - val other = Observable.fromIteratorUnsafe(queue.iterator) - ChainedObservable.subscribe(other, conn, out) - } + def onNext(elem: A): Ack = { + queue.enqueue(elem) + if (queued < n) + queued += 1 + else + queue.dequeue() + Continue + } + + def onComplete(): Unit = { + val other = Observable.fromIteratorUnsafe(queue.iterator) + ChainedObservable.subscribe(other, conn, out) + } - def onError(ex: Throwable): Unit = { - out.onError(ex) + def onError(ex: Throwable): Unit = { + out.onError(ex) + } } - }) + ) } } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeLeftByTimespanObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeLeftByTimespanObservable.scala index d7a3022c8..163d048c0 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeLeftByTimespanObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeLeftByTimespanObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,8 +18,9 @@ package monix.reactive.internal.operators import monix.execution.Ack.Stop +import monix.execution.Scheduler import monix.execution.cancelables.CompositeCancelable -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber @@ -35,9 +36,9 @@ private[reactive] final class TakeLeftByTimespanObservable[A](source: Observable composite += source.unsafeSubscribeFn(new Subscriber[A] with Runnable { implicit val scheduler: Scheduler = out.scheduler - private[this] var isActive = true + private var isActive = true // triggers completion - private[this] val task: Cancelable = { + private val task: Cancelable = { val ref = scheduler.scheduleOnce(timespan.length, timespan.unit, this) composite += ref ref diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeLeftOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeLeftOperator.scala index 9ea95d597..a82517f3f 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeLeftOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeLeftOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,13 @@ package monix.reactive.internal.operators +import scala.annotation.nowarn import monix.execution.Ack.Stop import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber +@nowarn("msg=unused value of type") private[reactive] final class TakeLeftOperator[A](n: Long) extends Operator[A, A] { def apply(out: Subscriber[A]): Subscriber[A] = { @@ -29,8 +31,8 @@ private[reactive] final class TakeLeftOperator[A](n: Long) extends Operator[A, A new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var counter = 0L - private[this] var isActive = true + private var counter = 0L + private var isActive = true def onNext(elem: A) = { if (isActive && counter < n) { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeUntilObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeUntilObservable.scala index da652215d..9f7cfdcc6 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeUntilObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeUntilObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,8 +18,9 @@ package monix.reactive.internal.operators import monix.execution.Ack.Stop -import monix.execution.cancelables.{CompositeCancelable, SingleAssignCancelable} -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.Scheduler +import monix.execution.cancelables.{ CompositeCancelable, SingleAssignCancelable } +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeWhileNotCanceledOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeWhileNotCanceledOperator.scala index a620def26..3a779a666 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeWhileNotCanceledOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/TakeWhileNotCanceledOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,6 +19,7 @@ package monix.reactive.internal.operators import monix.execution.{Ack, Scheduler} import monix.execution.Ack.Stop +import monix.execution.Scheduler import monix.execution.cancelables.BooleanCancelable import scala.util.control.NonFatal @@ -32,7 +33,7 @@ private[reactive] final class TakeWhileNotCanceledOperator[A](c: BooleanCancelab def apply(out: Subscriber[A]): Subscriber[A] = new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var isActive = true + private var isActive = true def onNext(elem: A): Future[Ack] = if (!isActive) Stop diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ThrottleFirstOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ThrottleFirstOperator.scala index afc4c76f4..4107721ee 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ThrottleFirstOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ThrottleFirstOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,11 +19,12 @@ package monix.reactive.internal.operators import monix.execution.{Ack, Scheduler} import monix.execution.Ack.Continue +import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber import scala.concurrent.Future -import scala.concurrent.duration.{FiniteDuration, MILLISECONDS} +import scala.concurrent.duration.{ FiniteDuration, MILLISECONDS } private[reactive] final class ThrottleFirstOperator[A](interval: FiniteDuration) extends Operator[A, A] { @@ -31,8 +32,8 @@ private[reactive] final class ThrottleFirstOperator[A](interval: FiniteDuration) new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] val intervalMs = interval.toMillis - private[this] var nextChange = 0L + private val intervalMs = interval.toMillis + private var nextChange = 0L def onNext(elem: A): Future[Ack] = { val rightNow = scheduler.clockMonotonic(MILLISECONDS) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ThrottleLastObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ThrottleLastObservable.scala index 86dfed1d4..9d24836db 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ThrottleLastObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ThrottleLastObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,19 +17,22 @@ package monix.reactive.internal.operators -import monix.execution.Ack.{Continue, Stop} -import monix.execution.cancelables.{CompositeCancelable, SingleAssignCancelable} -import monix.execution.{Ack, Cancelable, Scheduler} +import scala.annotation.nowarn +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler +import monix.execution.cancelables.{ CompositeCancelable, SingleAssignCancelable } +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.concurrent.Future +@nowarn("msg=unused value of type") private[reactive] final class ThrottleLastObservable[+A, S]( source: Observable[A], sampler: Observable[S], - shouldRepeatOnSilence: Boolean) - extends Observable[A] { + shouldRepeatOnSilence: Boolean +) extends Observable[A] { def unsafeSubscribeFn(downstream: Subscriber[A]): Cancelable = { val upstreamSubscription = SingleAssignCancelable() @@ -41,13 +44,13 @@ private[reactive] final class ThrottleLastObservable[+A, S]( // Value is volatile to keep write to lastValue visible // after this one is seen as being true - @volatile private[this] var hasValue = false + @volatile private var hasValue = false // MUST BE written before `hasValue = true` - private[this] var lastValue: A = _ + private var lastValue: A = null.asInstanceOf[A] // To be written in onComplete/onError, to be read from tick - private[this] var upstreamIsDone = false + private var upstreamIsDone = false // MUST BE synchronized by `upstreamSubscriber`. - private[this] var downstreamIsDone = false + private var downstreamIsDone = false def onNext(elem: A): Ack = if (downstreamIsDone) Stop diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ThrottleLatestObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ThrottleLatestObservable.scala index 7607be001..810a1365f 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ThrottleLatestObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ThrottleLatestObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,10 @@ package monix.reactive.internal.operators -import monix.execution.Ack.{Continue, Stop} -import monix.execution.cancelables.{CompositeCancelable, MultiAssignCancelable, SingleAssignCancelable} -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler +import monix.execution.cancelables.{ CompositeCancelable, MultiAssignCancelable, SingleAssignCancelable } +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber @@ -30,8 +31,8 @@ import scala.concurrent.duration.FiniteDuration private[reactive] final class ThrottleLatestObservable[A]( source: Observable[A], duration: FiniteDuration, - emitLast: Boolean) - extends Observable[A] { + emitLast: Boolean +) extends Observable[A] { def unsafeSubscribeFn(out: Subscriber[A]): Cancelable = { val task = MultiAssignCancelable() @@ -42,12 +43,12 @@ private[reactive] final class ThrottleLatestObservable[A]( self => implicit val scheduler: Scheduler = out.scheduler - private[this] val durationMilis = duration.toMillis - private[this] var isDone = false - private[this] var lastEvent: A = _ - private[this] var hasValue = false - private[this] var shouldEmitNext = true - private[this] var ack: Future[Ack] = _ + private val durationMilis = duration.toMillis + private var isDone = false + private var lastEvent: A = null.asInstanceOf[A] + private var hasValue = false + private var shouldEmitNext = true + private var ack: Future[Ack] = null.asInstanceOf[Future[Ack]] def scheduleNext(delayMillis: Long): Unit = { // No need to synchronize this assignment, since we have a @@ -62,7 +63,7 @@ private[reactive] final class ThrottleLatestObservable[A]( hasValue = false val now = scheduler.clockMonotonic(TimeUnit.MILLISECONDS) ack = out.onNext(lastEvent) - ack.syncFlatMap { + val _ = ack.syncFlatMap { case Continue => val elapsed = scheduler.clockMonotonic(TimeUnit.MILLISECONDS) - now val delay = @@ -78,7 +79,6 @@ private[reactive] final class ThrottleLatestObservable[A]( } Stop } - () } else { shouldEmitNext = true } @@ -113,15 +113,14 @@ private[reactive] final class ThrottleLatestObservable[A]( override def onComplete(): Unit = self.synchronized { if (!isDone) { - val lastAck = if(ack == null) Continue else ack - lastAck.syncTryFlatten.syncOnContinue{signalOnComplete()} + val lastAck = if (ack == null) Continue else ack + val _ = lastAck.syncTryFlatten.syncOnContinue { signalOnComplete() } } - () } private def signalOnComplete(): Unit = { if (emitLast && hasValue) { - out.onNext(lastEvent).syncTryFlatten.syncOnContinue { + val _ = out.onNext(lastEvent).syncTryFlatten.syncOnContinue { isDone = true out.onComplete() task.cancel() @@ -131,7 +130,6 @@ private[reactive] final class ThrottleLatestObservable[A]( out.onComplete() task.cancel() } - () } }) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/UncancelableObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/UncancelableObservable.scala index ab1f8325b..f7741fd48 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/UncancelableObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/UncancelableObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,6 +17,7 @@ package monix.reactive.internal.operators +import scala.annotation.nowarn import monix.execution.Cancelable import monix.execution.cancelables.AssignableCancelable import monix.reactive.Observable @@ -24,6 +25,7 @@ import monix.reactive.observables.ChainedObservable import monix.reactive.observers.Subscriber /** Implementation for `Observable.uncancelable`. */ +@nowarn("msg=unused value of type") private[reactive] final class UncancelableObservable[A](source: Observable[A]) extends ChainedObservable[A] { override def unsafeSubscribeFn(conn: AssignableCancelable.Multi, out: Subscriber[A]): Unit = { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/UpstreamTimeoutObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/UpstreamTimeoutObservable.scala index f49f5003a..c8a21353b 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/UpstreamTimeoutObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/UpstreamTimeoutObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,18 +17,20 @@ package monix.reactive.internal.operators +import scala.annotation.nowarn import java.util.concurrent.TimeUnit -import monix.execution.Ack.{Continue, Stop} -import monix.execution.cancelables.{CompositeCancelable, MultiAssignCancelable, SingleAssignCancelable} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.cancelables.{ CompositeCancelable, MultiAssignCancelable, SingleAssignCancelable } import monix.execution.exceptions.UpstreamTimeoutException -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber import scala.concurrent.Future -import scala.concurrent.duration.{FiniteDuration, MILLISECONDS} +import scala.concurrent.duration.{ FiniteDuration, MILLISECONDS } +@nowarn("msg=unused value of type") private[reactive] final class UpstreamTimeoutObservable[+A](source: Observable[A], timeout: FiniteDuration) extends Observable[A] { @@ -40,13 +42,13 @@ private[reactive] final class UpstreamTimeoutObservable[+A](source: Observable[A mainTask := source.unsafeSubscribeFn(new Subscriber[A] with Runnable { self => implicit val scheduler: Scheduler = downstream.scheduler - private[this] val timeoutMillis = timeout.toMillis + private val timeoutMillis = timeout.toMillis // MUST BE synchronized by `self` - private[this] var isProcessingOnNext = false + private var isProcessingOnNext = false // MUST BE synchronized by `self` - private[this] var isDone = false + private var isDone = false // MUST BE synchronized by `self` - private[this] var lastEmittedMillis: Long = + private var lastEmittedMillis: Long = scheduler.clockMonotonic(MILLISECONDS) locally { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/WhileBusyAggregateEventsOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/WhileBusyAggregateEventsOperator.scala index c50cafe3a..057f94331 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/WhileBusyAggregateEventsOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/WhileBusyAggregateEventsOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,47 +17,51 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import scala.annotation.nowarn +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber import scala.concurrent.Future -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } import scala.util.control.NonFatal -private[reactive] final class WhileBusyAggregateEventsOperator[A, S](seed: A => S, aggregate: (S, A) => S) extends Operator[A, S] { +@nowarn("msg=unused value of type") +private[reactive] final class WhileBusyAggregateEventsOperator[A, S](seed: A => S, aggregate: (S, A) => S) + extends Operator[A, S] { def apply(downstream: Subscriber[S]): Subscriber.Sync[A] = { new Subscriber.Sync[A] { upstreamSubscriber => implicit val scheduler: Scheduler = downstream.scheduler - private[this] var aggregated: Option[S] = None - private[this] var lastAck: Future[Ack] = Continue - private[this] var pendingAck: Boolean = false - private[this] var downstreamIsDone = false + private var aggregated: Option[S] = None + private var lastAck: Future[Ack] = Continue + private var pendingAck: Boolean = false + private var downstreamIsDone = false override def onNext(elem: A): Ack = { upstreamSubscriber.synchronized { if (downstreamIsDone) Stop else { if (!pendingAck) { - val downstreamAck = try { - downstream.onNext(seed(elem)) - } catch { - case ex if NonFatal(ex) => - downstream.onError(ex) - Stop - } + val downstreamAck = + try { + downstream.onNext(seed(elem)) + } catch { + case ex if NonFatal(ex) => + downstream.onError(ex) + Stop + } lastAck = downstreamAck if (downstreamAck == Continue) Continue else if (downstreamAck == Stop) { downstreamIsDone = true Stop - } - else { + } else { pendingAck = true emitAggregatedOnAckContinue(downstreamAck) Continue @@ -115,8 +119,8 @@ private[reactive] final class WhileBusyAggregateEventsOperator[A, S](seed: A => } } - private def emitAggregatedOnAckContinue(ack: Future[Ack]): Unit = { - lastAck.onComplete { + private def emitAggregatedOnAckContinue(ack: Future[Ack]): Unit = + ack.onComplete { case Failure(ex) => onError(ex) case Success(Stop) => @@ -124,8 +128,6 @@ private[reactive] final class WhileBusyAggregateEventsOperator[A, S](seed: A => case Success(Continue) => upstreamSubscriber.synchronized { emitAggregated() } } - } - } } } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/WhileBusyDropEventsAndSignalOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/WhileBusyDropEventsAndSignalOperator.scala index 84e4b71c3..baea7ed43 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/WhileBusyDropEventsAndSignalOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/WhileBusyDropEventsAndSignalOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,24 +17,26 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} - +import scala.annotation.nowarn +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import scala.util.control.NonFatal import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber import scala.concurrent.Future +@nowarn("msg=unused value of type") private[reactive] final class WhileBusyDropEventsAndSignalOperator[A](onOverflow: Long => A) extends Operator[A, A] { def apply(out: Subscriber[A]): Subscriber.Sync[A] = new Subscriber.Sync[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var ack = Continue: Future[Ack] - private[this] var eventsDropped = 0L - private[this] var isDone = false + private var ack = Continue: Future[Ack] + private var eventsDropped = 0L + private var isDone = false def onNext(elem: A) = if (isDone) Stop diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/WhileBusyDropEventsOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/WhileBusyDropEventsOperator.scala index 3fb9511b7..6491d3ef7 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/WhileBusyDropEventsOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/WhileBusyDropEventsOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,8 +17,9 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber @@ -30,8 +31,8 @@ private[reactive] final class WhileBusyDropEventsOperator[A] extends Operator[A, new Subscriber.Sync[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var ack = Continue: Future[Ack] - private[this] var isDone = false + private var ack = Continue: Future[Ack] + private var isDone = false def onNext(elem: A) = if (isDone) Stop diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/WithLatestFromObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/WithLatestFromObservable.scala index 5bbfa5271..db300c682 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/WithLatestFromObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/WithLatestFromObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,12 @@ package monix.reactive.internal.operators -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import monix.execution.cancelables.CompositeCancelable import scala.util.control.NonFatal -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber @@ -30,8 +31,8 @@ import scala.concurrent.Future private[reactive] final class WithLatestFromObservable[A, B, +R]( source: Observable[A], other: Observable[B], - f: (A, B) => R) - extends Observable[R] { + f: (A, B) => R +) extends Observable[R] { def unsafeSubscribeFn(out: Subscriber[R]): Cancelable = { val connection = CompositeCancelable() @@ -39,11 +40,11 @@ private[reactive] final class WithLatestFromObservable[A, B, +R]( connection += source.unsafeSubscribeFn(new Subscriber[A] { self => implicit val scheduler: Scheduler = out.scheduler - private[this] var isDone = false - private[this] var otherStarted = false - private[this] var lastOther: B = _ + private var isDone = false + private var otherStarted = false + private var lastOther: B = null.asInstanceOf[B] - private[this] val otherConnection = { + private val otherConnection = { val ref = other.unsafeSubscribeFn(new Subscriber.Sync[B] { implicit val scheduler: Scheduler = out.scheduler diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ZipWithIndexOperator.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ZipWithIndexOperator.scala index 4831e8e54..a8a300fb6 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ZipWithIndexOperator.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/operators/ZipWithIndexOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,8 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Scheduler} +import monix.execution.Ack +import monix.execution.Scheduler import monix.reactive.Observable.Operator import monix.reactive.observers.Subscriber @@ -28,7 +29,7 @@ private[reactive] final class ZipWithIndexOperator[A] extends Operator[A, (A, Lo def apply(out: Subscriber[(A, Long)]): Subscriber[A] = new Subscriber[A] { implicit val scheduler: Scheduler = out.scheduler - private[this] var index = 0L + private var index = 0L def onNext(elem: A): Future[Ack] = { val oldIndex = index diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/rstreams/ReactiveSubscriberAsMonixSubscriber.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/rstreams/ReactiveSubscriberAsMonixSubscriber.scala index 68057e9d0..aee6fcc5f 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/rstreams/ReactiveSubscriberAsMonixSubscriber.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/rstreams/ReactiveSubscriberAsMonixSubscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,33 +17,36 @@ package monix.reactive.internal.rstreams -import monix.execution.{Ack, Cancelable, Scheduler} +import scala.annotation.nowarn +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.observers.Subscriber import monix.execution.atomic.Atomic -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.reactive.internal.rstreams.ReactiveSubscriberAsMonixSubscriber.RequestsQueue -import org.reactivestreams.{Subscriber => RSubscriber, Subscription} +import org.reactivestreams.{ Subscriber => RSubscriber, Subscription } import scala.annotation.tailrec import scala.collection.immutable.Queue -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } /** Wraps a `org.reactivestreams.Subscriber` instance that respects the * [[http://www.reactive-streams.org/ Reactive Streams]] contract * into an [[monix.reactive.Observer Observer]] instance that * respect the `Observer` contract. */ +@nowarn("msg=unused value of type") private[reactive] final class ReactiveSubscriberAsMonixSubscriber[A] private ( subscriber: RSubscriber[A], - subscription: Cancelable)(implicit val scheduler: Scheduler) + subscription: Cancelable +)(implicit val scheduler: Scheduler) extends Subscriber[A] with Cancelable { self => if (subscriber == null) throw new NullPointerException("Subscriber must not be null") - private[this] var isComplete = false - private[this] val requests = new RequestsQueue - private[this] var leftToPush = 0L - private[this] var firstEvent = true - private[this] var ack: Future[Ack] = Continue + private var isComplete = false + private val requests = new RequestsQueue + private var leftToPush = 0L + private var firstEvent = true + private var ack: Future[Ack] = Continue def cancel(): Unit = { requests.cancel() @@ -113,14 +116,15 @@ private[reactive] object ReactiveSubscriberAsMonixSubscriber { * instance compliant with the Monix Rx implementation. */ def apply[A](subscriber: RSubscriber[A], subscription: Cancelable)( - implicit s: Scheduler): ReactiveSubscriberAsMonixSubscriber[A] = + implicit s: Scheduler + ): ReactiveSubscriberAsMonixSubscriber[A] = new ReactiveSubscriberAsMonixSubscriber[A](subscriber, subscription) /** An asynchronous queue implementation for dealing with * requests from a Subscriber. */ private final class RequestsQueue { - private[this] val state = Atomic(ActiveState(Queue.empty, Queue.empty): State) + private val state = Atomic(ActiveState(Queue.empty, Queue.empty): State) @tailrec def await(): Future[Long] = { @@ -154,7 +158,8 @@ private[reactive] object ReactiveSubscriberAsMonixSubscriber { require( n > 0, "n must be strictly positive, according to " + - "the Reactive Streams contract, rule 3.9") + "the Reactive Streams contract, rule 3.9" + ) state.get() match { case CancelledState => diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/rstreams/SubscriberAsReactiveSubscriber.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/rstreams/SubscriberAsReactiveSubscriber.scala index daedf776e..edaef1a3e 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/rstreams/SubscriberAsReactiveSubscriber.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/rstreams/SubscriberAsReactiveSubscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,15 +17,15 @@ package monix.reactive.internal.rstreams -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } import monix.execution.ChannelType.SingleProducer +import monix.execution.Scheduler import monix.execution.rstreams.SingleAssignSubscription import monix.execution.schedulers.TrampolineExecutionContext.immediate import monix.reactive.OverflowStrategy.Unbounded -import monix.reactive.observers.{BufferedSubscriber, Subscriber} -import org.reactivestreams.{Subscriber => RSubscriber, Subscription => RSubscription} - +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } +import org.reactivestreams.{ Subscriber => RSubscriber, Subscription => RSubscription } import scala.concurrent.Future private[reactive] object SubscriberAsReactiveSubscriber { @@ -41,7 +41,7 @@ private[reactive] object SubscriberAsReactiveSubscriber { * {{{ * // uses the default requestCount of 128 * val subscriber = SubscriberAsReactiveSubscriber(new Observer[Int] { - * private[this] var sum = 0 + * private var sum = 0 * * def onNext(elem: Int) = { * sum += elem @@ -65,7 +65,7 @@ private[reactive] object SubscriberAsReactiveSubscriber { */ def apply[A](subscriber: Subscriber[A], requestCount: Int = 128): RSubscriber[A] = subscriber match { - case _: Subscriber.Sync[_] => + case _: Subscriber.Sync[?] => new SyncSubscriberAsReactiveSubscriber[A](subscriber.asInstanceOf[Subscriber.Sync[A]], requestCount) case _ => new AsyncSubscriberAsReactiveSubscriber[A](subscriber, requestCount) @@ -91,14 +91,14 @@ private[reactive] final class AsyncSubscriberAsReactiveSubscriber[A](target: Sub require(requestCount > 0, "requestCount must be strictly positive, according to the Reactive Streams contract") - private[this] val subscription = SingleAssignSubscription() - private[this] val downstream: Subscriber[A] = + private val subscription = SingleAssignSubscription() + private val downstream: Subscriber[A] = new Subscriber[A] { implicit val scheduler: Scheduler = target.scheduler - private[this] val isFinite = requestCount < Int.MaxValue - private[this] var isActive = true - private[this] var toReceive = requestCount + private val isFinite = requestCount < Int.MaxValue + private var isActive = true + private var toReceive = requestCount locally { // Requesting the first batch @@ -132,9 +132,10 @@ private[reactive] final class AsyncSubscriberAsReactiveSubscriber[A](target: Sub case Stop => stop() }, err => { - stop() + val _ = stop() err - })(immediate) + } + )(immediate) } def onNext(elem: A): Future[Ack] = { @@ -154,7 +155,7 @@ private[reactive] final class AsyncSubscriberAsReactiveSubscriber[A](target: Sub } } - private[this] val buffer: Subscriber.Sync[A] = + private val buffer: Subscriber.Sync[A] = BufferedSubscriber.synchronous(downstream, Unbounded, SingleProducer) def onSubscribe(s: RSubscription): Unit = @@ -162,7 +163,7 @@ private[reactive] final class AsyncSubscriberAsReactiveSubscriber[A](target: Sub def onNext(elem: A): Unit = { if (elem == null) throwNull("onNext") - buffer.onNext(elem) + val _ = buffer.onNext(elem) () } @@ -191,7 +192,7 @@ private[reactive] final class AsyncSubscriberAsReactiveSubscriber[A](target: Sub * To async an instance, [[SyncSubscriberAsReactiveSubscriber]] must be used: {{{ * // uses the default requestCount of 128 * val subscriber = SyncSubscriberAsReactiveSubscriber(new Observer[Int] { - * private[this] var sum = 0 + * private var sum = 0 * * def onNext(elem: Int) = { * sum += elem @@ -213,11 +214,9 @@ private[reactive] final class SyncSubscriberAsReactiveSubscriber[A](target: Subs require(requestCount > 0, "requestCount must be strictly positive, according to the Reactive Streams contract") - private[this] implicit val s: Scheduler = target.scheduler - - private[this] var subscription = null: RSubscription - private[this] var expectingCount = 0L - @volatile private[this] var isCanceled = false + private var subscription = null: RSubscription + private var expectingCount = 0L + @volatile private var isCanceled = false def onSubscribe(s: RSubscription): Unit = { if (subscription == null && !isCanceled) { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/subscribers/ForeachSubscriber.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/subscribers/ForeachSubscriber.scala index cca8c2b58..64f335e41 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/subscribers/ForeachSubscriber.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/subscribers/ForeachSubscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,9 +18,9 @@ package monix.reactive.internal.subscribers import monix.execution.Callback -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import scala.util.control.NonFatal -import monix.execution.{Ack, Scheduler} +import monix.execution.{ Ack, Scheduler } import monix.reactive.observers.Subscriber /** Subscriber implementation for `Observable.foreach` */ @@ -28,7 +28,7 @@ private[reactive] final class ForeachSubscriber[A](f: A => Unit, onFinish: Callb extends Subscriber.Sync[A] { implicit val scheduler: Scheduler = s - private[this] var isDone = false + private var isDone = false def onNext(elem: A): Ack = { try { diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/util/Instances.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/util/Instances.scala index 3a150e97f..343ffa838 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/util/Instances.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/util/Instances.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/internal/util/PromiseCounter.scala b/monix-reactive/shared/src/main/scala/monix/reactive/internal/util/PromiseCounter.scala index 6d28e1683..9ffa65fbc 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/internal/util/PromiseCounter.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/internal/util/PromiseCounter.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.reactive.internal.util import monix.execution.atomic.Atomic -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } /** * Represents a Promise that completes with `value` after @@ -27,8 +27,8 @@ import scala.concurrent.{Future, Promise} private[monix] final class PromiseCounter[A] private (value: A, initial: Int) { require(initial > 0, "length must be strictly positive") - private[this] val promise = Promise[A]() - private[this] val counter = Atomic(initial) + private val promise = Promise[A]() + private val counter = Atomic(initial) def future: Future[A] = promise.future diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/observables/CachedObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/observables/CachedObservable.scala index 9a548c9ba..f788f3e89 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/observables/CachedObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/observables/CachedObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,6 +22,7 @@ import monix.reactive.Observable import monix.reactive.subjects.ReplaySubject import monix.reactive.observers.Subscriber import monix.execution.atomic.Atomic +import scala.annotation.unchecked.uncheckedVariance /** A `CachedObservable` is an observable that wraps a regular * [[Observable]], initiating the connection on the first @@ -36,8 +37,8 @@ import monix.execution.atomic.Atomic */ final class CachedObservable[+A] private (source: Observable[A], maxCapacity: Int) extends Observable[A] { - private[this] val isStarted = Atomic(false) - private[this] val subject = { + private val isStarted = Atomic(false) + private val subject: ReplaySubject[A @uncheckedVariance] = { if (maxCapacity > 0) ReplaySubject.createLimited[A](maxCapacity) else ReplaySubject[A]() @@ -45,8 +46,9 @@ final class CachedObservable[+A] private (source: Observable[A], maxCapacity: In def unsafeSubscribeFn(subscriber: Subscriber[A]): Cancelable = { import subscriber.scheduler - if (isStarted.compareAndSet(expect = false, update = true)) - source.unsafeSubscribeFn(Subscriber(subject, scheduler)) + if (isStarted.compareAndSet(expect = false, update = true)) { + val _ = source.unsafeSubscribeFn(Subscriber(subject, scheduler)) + } subject.unsafeSubscribeFn(subscriber) } } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/observables/ChainedObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/observables/ChainedObservable.scala index ec6793bd6..d5800db38 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/observables/ChainedObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/observables/ChainedObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.reactive.observables import monix.execution.Cancelable -import monix.execution.cancelables.{AssignableCancelable, MultiAssignCancelable} +import monix.execution.cancelables.{ AssignableCancelable, MultiAssignCancelable } import monix.reactive.Observable import monix.reactive.observers.Subscriber @@ -68,7 +68,7 @@ object ChainedObservable { // to delay it and force ordering; plus it protects from stack overflows out.scheduler.executeTrampolined { () => source match { - case _: ChainedObservable[_] => + case _: ChainedObservable[?] => source.asInstanceOf[ChainedObservable[A]].unsafeSubscribeFn(conn, out) case _ => conn := source.unsafeSubscribeFn(out) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/observables/CombineObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/observables/CombineObservable.scala index 69ba3066f..b371f647d 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/observables/CombineObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/observables/CombineObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,7 +28,7 @@ import monix.reactive.Observable object CombineObservable extends Newtype1[Observable] { implicit val combineObservableApplicative: Apply[CombineObservable.Type] = new Apply[CombineObservable.Type] { - import CombineObservable.{apply => wrap} + import CombineObservable.{ apply => wrap } override def ap[A, B](ff: CombineObservable.Type[(A) => B])(fa: CombineObservable.Type[A]) = wrap(unwrap(ff).combineLatestMap(unwrap(fa))((f, a) => f(a))) @@ -37,12 +37,14 @@ object CombineObservable extends Newtype1[Observable] { wrap(unwrap(fa).map(f)) override def map2[A, B, C](fa: CombineObservable.Type[A], fb: CombineObservable.Type[B])( - f: (A, B) => C): CombineObservable.Type[C] = + f: (A, B) => C + ): CombineObservable.Type[C] = wrap(unwrap(fa).combineLatestMap(unwrap(fb))(f)) override def product[A, B]( fa: CombineObservable.Type[A], - fb: CombineObservable.Type[B]): CombineObservable.Type[(A, B)] = + fb: CombineObservable.Type[B] + ): CombineObservable.Type[(A, B)] = wrap(unwrap(fa).combineLatest(unwrap(fb))) } } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/observables/ConnectableObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/observables/ConnectableObservable.scala index 35d026f3c..6cc82072b 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/observables/ConnectableObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/observables/ConnectableObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,11 @@ package monix.reactive.observables -import monix.execution.annotations.{UnsafeBecauseImpure, UnsafeProtocol} -import monix.execution.{Cancelable, Scheduler} -import monix.reactive.observers.{CacheUntilConnectSubscriber, Subscriber} +import monix.execution.annotations.{ UnsafeBecauseImpure, UnsafeProtocol } +import monix.execution.{ Cancelable, Scheduler } +import monix.reactive.observers.{ CacheUntilConnectSubscriber, Subscriber } import monix.reactive.subjects.Subject -import monix.reactive.{Observable, Pipe} +import monix.reactive.{ Observable, Pipe } /** Represents an [[monix.reactive.Observable Observable]] that waits for * the call to `connect()` before @@ -51,10 +51,11 @@ object ConnectableObservable { @UnsafeProtocol @UnsafeBecauseImpure def unsafeMulticast[A, B](source: Observable[A], subject: Subject[A, B])( - implicit s: Scheduler): ConnectableObservable[B] = { + implicit s: Scheduler + ): ConnectableObservable[B] = { new ConnectableObservable[B] { - private[this] lazy val connection: Cancelable = + private lazy val connection: Cancelable = source.unsafeSubscribeFn(Subscriber(subject, s)) def connect(): Cancelable = @@ -72,8 +73,8 @@ object ConnectableObservable { def multicast[A, B](source: Observable[A], recipe: Pipe[A, B])(implicit s: Scheduler): ConnectableObservable[B] = { new ConnectableObservable[B] { - private[this] val (input, output) = recipe.multicast(s) - private[this] lazy val connection = { + private val (input, output) = recipe.multicast(s) + private lazy val connection = { source.subscribe(input) } @@ -92,16 +93,17 @@ object ConnectableObservable { */ @UnsafeBecauseImpure def cacheUntilConnect[A, B](source: Observable[A], subject: Subject[A, B])( - implicit s: Scheduler): ConnectableObservable[B] = { + implicit s: Scheduler + ): ConnectableObservable[B] = { new ConnectableObservable[B] { - private[this] val (connectable, cancelRef) = { + private val (connectable, cancelRef) = { val ref = CacheUntilConnectSubscriber(Subscriber(subject, s)) val c = source.unsafeSubscribeFn(ref) // connects immediately (ref, c) } - private[this] lazy val connection = { + private lazy val connection = { val connecting = connectable.connect() Cancelable { () => try cancelRef.cancel() diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/observables/GroupedObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/observables/GroupedObservable.scala index 5e3e9f42e..1aadbbd10 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/observables/GroupedObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/observables/GroupedObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,9 +18,9 @@ package monix.reactive.observables import monix.execution.exceptions.APIContractViolationException -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.Observable -import monix.reactive.observers.{CacheUntilConnectSubscriber, Subscriber} +import monix.reactive.observers.{ CacheUntilConnectSubscriber, Subscriber } import scala.concurrent.Future @@ -41,7 +41,8 @@ abstract class GroupedObservable[K, +V] extends Observable[V] { self => object GroupedObservable { /** Builder returning an input+output pair */ private[monix] def broadcast[K, V](key: K, onCancel: Cancelable)( - implicit s: Scheduler): (Subscriber[V], GroupedObservable[K, V]) = { + implicit s: Scheduler + ): (Subscriber[V], GroupedObservable[K, V]) = { val ref = new Implementation[K, V](key, onCancel) (ref, ref) @@ -52,11 +53,11 @@ object GroupedObservable { extends GroupedObservable[K, V] with Subscriber[V] { self => // needs to be set upon subscription - private[this] var ref: Subscriber[V] = _ - private[this] val underlying = { + private var ref: Subscriber[V] = null.asInstanceOf[Subscriber[V]] + private val underlying = { val o = new Subscriber[V] { implicit val scheduler: Scheduler = self.scheduler - private[this] var isDone = false + private var isDone = false def onNext(elem: V) = { val cache = ref diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/observables/RefCountObservable.scala b/monix-reactive/shared/src/main/scala/monix/reactive/observables/RefCountObservable.scala index 206b40140..346cf5460 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/observables/RefCountObservable.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/observables/RefCountObservable.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,8 @@ package monix.reactive.observables -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable } +import monix.execution.Scheduler import monix.reactive.Observable import monix.reactive.observers.Subscriber import monix.execution.atomic.Atomic @@ -34,8 +35,8 @@ import scala.concurrent.Future */ final class RefCountObservable[+A] private (source: ConnectableObservable[A]) extends Observable[A] { - private[this] val refs = Atomic(-1) - private[this] lazy val connection: Cancelable = + private val refs = Atomic(-1) + private lazy val connection: Cancelable = source.connect() @tailrec @@ -58,7 +59,7 @@ final class RefCountObservable[+A] private (source: ConnectableObservable[A]) ex val countdown = Cancelable(() => countDownToConnectionCancel()) // Subscribing and triggering connect() if this is the first subscription val ret = source.unsafeSubscribeFn(wrap(subscriber, countdown)) - if (current == -1) connection // triggers connect() + if (current == -1) { val _ = connection } // triggers connect() // A composite that both cancels this subscription and does the countdown Cancelable { () => try ret.cancel() @@ -89,7 +90,7 @@ final class RefCountObservable[+A] private (source: ConnectableObservable[A]) ex } @tailrec - private[this] def countDownToConnectionCancel(): Unit = refs.get() match { + private def countDownToConnectionCancel(): Unit = refs.get() match { case x if x > 0 => val update = x - 1 if (!refs.compareAndSet(x, update)) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/observers/BufferedSubscriber.scala b/monix-reactive/shared/src/main/scala/monix/reactive/observers/BufferedSubscriber.scala index 4b80a43f5..423215628 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/observers/BufferedSubscriber.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/observers/BufferedSubscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -72,7 +72,8 @@ private[reactive] trait Builders { def apply[A]( subscriber: Subscriber[A], bufferPolicy: OverflowStrategy[A], - producerType: ChannelType.ProducerSide = MultiProducer): Subscriber[A] + producerType: ChannelType.ProducerSide = MultiProducer + ): Subscriber[A] /** Given an synchronous [[OverflowStrategy overflow strategy]] wraps * a [[Subscriber]] into a buffered subscriber. @@ -80,7 +81,8 @@ private[reactive] trait Builders { def synchronous[A]( subscriber: Subscriber[A], bufferPolicy: OverflowStrategy.Synchronous[A], - producerType: ChannelType.ProducerSide = MultiProducer): Subscriber.Sync[A] + producerType: ChannelType.ProducerSide = MultiProducer + ): Subscriber.Sync[A] /** Builds a batched buffered subscriber. * @@ -97,7 +99,8 @@ private[reactive] trait Builders { def batched[A]( underlying: Subscriber[List[A]], bufferSize: Int, - producerType: ChannelType.ProducerSide = MultiProducer): Subscriber[A] + producerType: ChannelType.ProducerSide = MultiProducer + ): Subscriber[A] } object BufferedSubscriber extends Builders with BuildersImpl diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/observers/CacheUntilConnectSubscriber.scala b/monix-reactive/shared/src/main/scala/monix/reactive/observers/CacheUntilConnectSubscriber.scala index d0469e020..0bd79819e 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/observers/CacheUntilConnectSubscriber.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/observers/CacheUntilConnectSubscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,13 +17,15 @@ package monix.reactive.observers -import monix.execution.Ack.{Continue, Stop} -import monix.execution.{Ack, CancelableFuture, Scheduler} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.{ Ack, CancelableFuture } +import monix.execution.Scheduler import monix.reactive.Observable import scala.collection.mutable -import scala.concurrent.{Future, Promise} -import scala.util.{Failure, Success} +import scala.concurrent.{ Future, Promise } +import scala.util.{ Failure, Success } +import scala.annotation.unchecked.uncheckedVariance /** Wraps an `underlying` [[Subscriber]] into an implementation that caches * all events until the call to `connect()` happens. After being connected, @@ -33,26 +35,26 @@ import scala.util.{Failure, Success} final class CacheUntilConnectSubscriber[-A] private (downstream: Subscriber[A]) extends Subscriber[A] { self => implicit val scheduler: Scheduler = downstream.scheduler // MUST BE synchronized by `self`, only available if isConnected == false - private[this] var queue = mutable.ArrayBuffer.empty[A] + private var queue: mutable.ArrayBuffer[A @uncheckedVariance] = mutable.ArrayBuffer.empty // MUST BE synchronized by `self` - private[this] var isConnectionStarted = false + private var isConnectionStarted = false // MUST BE synchronized by `self`, as long as isConnected == false - private[this] var wasCanceled = false + private var wasCanceled = false // Promise guaranteed to be fulfilled once isConnected is // seen as true and used for back-pressure. // MUST BE synchronized by `self`, only available if isConnected == false - private[this] var connectedPromise = Promise[Ack]() - private[this] var connectedFuture = connectedPromise.future + private var connectedPromise = Promise[Ack]() + private var connectedFuture = connectedPromise.future // Volatile that is set to true once the buffer is drained. // Once visible as true, it implies that the queue is empty // and has been drained and thus the onNext/onError/onComplete // can take the fast path - @volatile private[this] var isConnected = false + @volatile private var isConnected = false // Only accessible in `connect()` - private[this] var connectionRef: CancelableFuture[Ack] = _ + private var connectionRef: CancelableFuture[Ack] = null.asInstanceOf[CancelableFuture[Ack]] /** Connects the underling observer to the upstream publisher. * @@ -74,7 +76,7 @@ final class CacheUntilConnectSubscriber[-A] private (downstream: Subscriber[A]) .fromIterable(queue) .unsafeSubscribeFn(new Subscriber[A] { implicit val scheduler: Scheduler = downstream.scheduler - private[this] var ack: Future[Ack] = Continue + private var ack: Future[Ack] = Continue bufferWasDrained.future.onComplete { case Success(Continue) => @@ -118,11 +120,9 @@ final class CacheUntilConnectSubscriber[-A] private (downstream: Subscriber[A]) def onComplete(): Unit = { // Applying back-pressure, otherwise the next onNext might // break the back-pressure contract. - ack.syncOnContinue { - bufferWasDrained.trySuccess(Continue) - () + val _ = ack.syncOnContinue { + val _ = bufferWasDrained.trySuccess(Continue) } - () } def onError(ex: Throwable): Unit = { @@ -164,7 +164,8 @@ final class CacheUntilConnectSubscriber[-A] private (downstream: Subscriber[A]) connectedFuture } - } else if (!wasCanceled) { + } + else if (!wasCanceled) { // taking fast path :-) downstream.onNext(elem) } else { @@ -182,7 +183,8 @@ final class CacheUntilConnectSubscriber[-A] private (downstream: Subscriber[A]) */ def onComplete(): Unit = { // we cannot take a fast path here - connectedFuture.syncTryFlatten + val _ = connectedFuture + .syncTryFlatten .syncOnContinue(downstream.onComplete()) () } @@ -195,7 +197,8 @@ final class CacheUntilConnectSubscriber[-A] private (downstream: Subscriber[A]) */ def onError(ex: Throwable): Unit = { // we cannot take a fast path here - connectedFuture.syncTryFlatten + val _ = connectedFuture + .syncTryFlatten .syncOnContinue(downstream.onError(ex)) () } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/observers/ConnectableSubscriber.scala b/monix-reactive/shared/src/main/scala/monix/reactive/observers/ConnectableSubscriber.scala index 27eff2718..4f7a5af33 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/observers/ConnectableSubscriber.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/observers/ConnectableSubscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,13 +17,14 @@ package monix.reactive.observers -import monix.execution.Ack.{Continue, Stop} -import monix.execution.{Ack, CancelableFuture, Scheduler} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.{ Ack, CancelableFuture, Scheduler } import monix.reactive.Observable import scala.collection.mutable -import scala.concurrent.{Future, Promise} -import scala.util.{Failure, Success} +import scala.concurrent.{ Future, Promise } +import scala.util.{ Failure, Success } +import scala.annotation.unchecked.uncheckedVariance /** Wraps a [[Subscriber]] into an implementation that abstains from emitting items until the call * to `connect()` happens. Prior to `connect()` you can enqueue @@ -81,35 +82,33 @@ import scala.util.{Failure, Success} * }}} */ final class ConnectableSubscriber[-A] private (underlying: Subscriber[A]) extends Subscriber[A] { self => - - implicit val scheduler: Scheduler = - underlying.scheduler + implicit val scheduler: Scheduler = underlying.scheduler // MUST BE synchronized by `self`, only available if isConnected == false - private[this] var queue = mutable.ArrayBuffer.empty[A] + private var queue = mutable.ArrayBuffer.empty[A @uncheckedVariance] // MUST BE synchronized by `self`, only available if isConnected == false - private[this] var scheduledDone = false + private var scheduledDone = false // MUST BE synchronized by `self`, only available if isConnected == false - private[this] var scheduledError = null: Throwable + private var scheduledError = null: Throwable // MUST BE synchronized by `self` - private[this] var isConnectionStarted = false + private var isConnectionStarted = false // MUST BE synchronized by `self`, as long as isConnected == false - private[this] var wasCanceled = false + private var wasCanceled = false // Promise guaranteed to be fulfilled once isConnected is // seen as true and used for back-pressure. // MUST BE synchronized by `self`, only available if isConnected == false - private[this] var connectedPromise = Promise[Ack]() - private[this] var connectedFuture = connectedPromise.future + private var connectedPromise = Promise[Ack]() + private var connectedFuture = connectedPromise.future // Volatile that is set to true once the buffer is drained. // Once visible as true, it implies that the queue is empty // and has been drained and thus the onNext/onError/onComplete // can take the fast path - @volatile private[this] var isConnected = false + @volatile private var isConnected = false // Only accessible in `connect()` - private[this] var connectionRef: CancelableFuture[Ack] = _ + private var connectionRef: CancelableFuture[Ack] = null.asInstanceOf[CancelableFuture[Ack]] /** Connects the underling observer to the upstream publisher. * @@ -126,7 +125,7 @@ final class ConnectableSubscriber[-A] private (underlying: Subscriber[A]) extend .fromIterable(queue) .unsafeSubscribeFn(new Subscriber[A] { implicit val scheduler: Scheduler = underlying.scheduler - private[this] var ack: Future[Ack] = Continue + private var ack: Future[Ack] = Continue bufferWasDrained.future.onComplete { case Success(Continue) => @@ -169,7 +168,9 @@ final class ConnectableSubscriber[-A] private (underlying: Subscriber[A]) extend def onComplete(): Unit = { if (!scheduledDone) { - ack.syncOnContinue { bufferWasDrained.trySuccess(Continue); () } + val _ = ack.syncOnContinue { + val _ = bufferWasDrained.trySuccess(Continue) + } } else if (scheduledError ne null) { if (bufferWasDrained.trySuccess(Stop)) underlying.onError(scheduledError) @@ -307,7 +308,8 @@ final class ConnectableSubscriber[-A] private (underlying: Subscriber[A]) extend */ def onComplete(): Unit = { // we cannot take a fast path here - connectedFuture.syncTryFlatten + val _ = connectedFuture + .syncTryFlatten .syncOnContinue(underlying.onComplete()) () } @@ -320,7 +322,8 @@ final class ConnectableSubscriber[-A] private (underlying: Subscriber[A]) extend */ def onError(ex: Throwable): Unit = { // we cannot take a fast path here - connectedFuture.syncTryFlatten + val _ = connectedFuture + .syncTryFlatten .syncOnContinue(underlying.onError(ex)) () } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/observers/SafeSubscriber.scala b/monix-reactive/shared/src/main/scala/monix/reactive/observers/SafeSubscriber.scala index 253e1da87..bcf643da2 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/observers/SafeSubscriber.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/observers/SafeSubscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,13 @@ package monix.reactive.observers -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} - +import scala.annotation.nowarn +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import scala.util.control.NonFatal -import scala.concurrent.{Future, Promise} + +import scala.concurrent.{ Future, Promise } import scala.util.Try /** A safe subscriber safe guards subscriber implementations, such that: @@ -34,11 +36,12 @@ import scala.util.Try * - if downstream signals a `Stop`, the observer no longer accepts any events, * ensuring that the grammar is respected */ +@nowarn("msg=unused value of type") final class SafeSubscriber[-A] private (subscriber: Subscriber[A]) extends Subscriber[A] { implicit val scheduler: Scheduler = subscriber.scheduler - private[this] var isDone = false - private[this] var ack: Future[Ack] = Continue + private var isDone = false + private var ack: Future[Ack] = Continue def onNext(elem: A): Future[Ack] = { if (!isDone) { @@ -121,7 +124,7 @@ object SafeSubscriber { */ def apply[A](subscriber: Subscriber[A]): SafeSubscriber[A] = subscriber match { - case ref: SafeSubscriber[_] => ref.asInstanceOf[SafeSubscriber[A]] + case ref: SafeSubscriber[?] => ref.asInstanceOf[SafeSubscriber[A]] case _ => new SafeSubscriber[A](subscriber) } } diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/observers/Subscriber.scala b/monix-reactive/shared/src/main/scala/monix/reactive/observers/Subscriber.scala index 6cba0c23a..b9f3802fb 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/observers/Subscriber.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/observers/Subscriber.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,14 +18,12 @@ package monix.reactive.observers import java.io.PrintStream -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.cancelables.BooleanCancelable -import monix.execution.internal.Platform -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.Observer import monix.reactive.internal.rstreams._ -import org.reactivestreams.{Subscriber => RSubscriber} - +import org.reactivestreams.{ Subscriber => RSubscriber } import scala.concurrent.Future import scala.util.control.NonFatal @@ -42,9 +40,9 @@ object Subscriber { /** Subscriber builder */ def apply[A](observer: Observer[A], scheduler: Scheduler): Subscriber[A] = observer match { - case ref: Subscriber[_] if ref.scheduler == scheduler => + case ref: Subscriber[?] if ref.scheduler == scheduler => ref.asInstanceOf[Subscriber[A]] - case ref: Observer.Sync[_] => + case ref: Observer.Sync[?] => Subscriber.Sync(ref.asInstanceOf[Observer.Sync[A]], scheduler) case _ => new Implementation[A](observer, scheduler) @@ -61,7 +59,7 @@ object Subscriber { /** `Subscriber.Sync` builder */ def apply[A](observer: Observer.Sync[A], scheduler: Scheduler): Subscriber.Sync[A] = observer match { - case ref: Subscriber.Sync[_] if ref.scheduler == scheduler => + case ref: Subscriber.Sync[?] if ref.scheduler == scheduler => ref.asInstanceOf[Subscriber.Sync[A]] case _ => new SyncImplementation[A](observer, scheduler) @@ -110,7 +108,8 @@ object Subscriber { * Monix Rx implementation. */ def fromReactiveSubscriber[A](subscriber: RSubscriber[A], subscription: Cancelable)( - implicit s: Scheduler): Subscriber[A] = + implicit s: Scheduler + ): Subscriber[A] = ReactiveSubscriberAsMonixSubscriber(subscriber, subscription) /** Transforms the source [[Subscriber]] into a `org.reactivestreams.Subscriber` @@ -210,7 +209,7 @@ object Subscriber { Subscriber.contramap(target)(f) } - private[this] final class Implementation[-A](private val underlying: Observer[A], val scheduler: Scheduler) + private final class Implementation[-A](private val underlying: Observer[A], val scheduler: Scheduler) extends Subscriber[A] { require(underlying != null, "Observer should not be null") @@ -221,7 +220,7 @@ object Subscriber { def onComplete(): Unit = underlying.onComplete() } - private[this] final class SyncImplementation[-A](observer: Observer.Sync[A], val scheduler: Scheduler) + private final class SyncImplementation[-A](observer: Observer.Sync[A], val scheduler: Scheduler) extends Subscriber.Sync[A] { require(observer != null, "Observer should not be null") @@ -232,10 +231,10 @@ object Subscriber { def onComplete(): Unit = observer.onComplete() } - private[this] final class ContravariantSubscriber[A, B](source: Subscriber[A])(f: B => A) extends Subscriber[B] { + private final class ContravariantSubscriber[A, B](source: Subscriber[A])(f: B => A) extends Subscriber[B] { override implicit def scheduler: Scheduler = source.scheduler // For protecting the contract - private[this] var isDone = false + private var isDone = false override def onNext(elem: B): Future[Ack] = { if (isDone) Stop diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/observers/buffers/package.scala b/monix-reactive/shared/src/main/scala/monix/reactive/observers/buffers/package.scala index e7bba7119..a52467e8c 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/observers/buffers/package.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/observers/buffers/package.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/subjects/AsyncSubject.scala b/monix-reactive/shared/src/main/scala/monix/reactive/subjects/AsyncSubject.scala index 7557af02f..1c8c849cc 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/subjects/AsyncSubject.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/subjects/AsyncSubject.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,8 +17,9 @@ package monix.reactive.subjects -import monix.execution.Ack.{Continue, Stop} -import monix.execution.{Ack, Cancelable} +import scala.annotation.nowarn +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.{ Ack, Cancelable } import monix.reactive.observers.Subscriber import monix.reactive.subjects.PublishSubject.State import monix.execution.atomic.Atomic @@ -31,15 +32,16 @@ import scala.annotation.tailrec * items to subsequent subscribers, but will simply pass along the error * notification from the source Observable. */ +@nowarn("msg=unused value of type") final class AsyncSubject[A] extends Subject[A, A] { self => /* * NOTE: the stored vector value can be null and if it is, then * that means our subject has been terminated. */ - private[this] val stateRef = Atomic(State[A]()) + private val stateRef = Atomic(State[A]()) - private[this] var onNextHappened = false - private[this] var cachedElem: A = _ + private var onNextHappened = false + private var cachedElem: A = null.asInstanceOf[A] def size: Int = stateRef.get().subscribers.size diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/subjects/BehaviorSubject.scala b/monix-reactive/shared/src/main/scala/monix/reactive/subjects/BehaviorSubject.scala index e1278c528..0b4a07961 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/subjects/BehaviorSubject.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/subjects/BehaviorSubject.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,12 @@ package monix.reactive.subjects -import monix.execution.Ack.{Continue, Stop} -import monix.execution.{Ack, Cancelable} +import scala.annotation.nowarn +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.{ Ack, Cancelable } import monix.reactive.Observable import monix.reactive.internal.util.PromiseCounter -import monix.reactive.observers.{ConnectableSubscriber, Subscriber} +import monix.reactive.observers.{ ConnectableSubscriber, Subscriber } import monix.execution.atomic.Atomic import scala.util.control.NonFatal @@ -38,9 +39,10 @@ import scala.util.Success * * @see [[Subject]] */ +@nowarn("msg=unused value of type") final class BehaviorSubject[A] private (initialValue: A) extends Subject[A, A] { self => - private[this] val stateRef = + private val stateRef = Atomic(BehaviorSubject.State[A](initialValue)) def size: Int = @@ -186,7 +188,8 @@ object BehaviorSubject { cached: A, subscribers: Set[ConnectableSubscriber[A]] = Set.empty[ConnectableSubscriber[A]], isDone: Boolean = false, - errorThrown: Throwable = null) { + errorThrown: Throwable = null + ) { def cacheElem(elem: A): State[A] = { copy(cached = elem) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/subjects/ConcurrentSubject.scala b/monix-reactive/shared/src/main/scala/monix/reactive/subjects/ConcurrentSubject.scala index 3525872bf..ddb0626c4 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/subjects/ConcurrentSubject.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/subjects/ConcurrentSubject.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,11 +19,11 @@ package monix.reactive.subjects import monix.execution.ChannelType.MultiProducer import monix.execution.cancelables.SingleAssignCancelable -import monix.execution.{Ack, Cancelable, ChannelType, Scheduler} -import monix.reactive.OverflowStrategy.{Synchronous, Unbounded} -import monix.reactive.observers.{BufferedSubscriber, Subscriber} -import monix.reactive.{MulticastStrategy, Observer, OverflowStrategy} -import org.reactivestreams.{Subscription, Processor => RProcessor, Subscriber => RSubscriber} +import monix.execution.{ Ack, Cancelable, ChannelType, Scheduler } +import monix.reactive.OverflowStrategy.{ Synchronous, Unbounded } +import monix.reactive.observers.{ BufferedSubscriber, Subscriber } +import monix.reactive.{ MulticastStrategy, Observer, OverflowStrategy } +import org.reactivestreams.{ Processor => RProcessor, Subscriber => RSubscriber, Subscription } /** A concurrent subject is meant for imperative style feeding of events. * @@ -34,12 +34,13 @@ import org.reactivestreams.{Subscription, Processor => RProcessor, Subscriber => */ abstract class ConcurrentSubject[I, +O] extends Subject[I, O] with Observer.Sync[I] -object ConcurrentSubject { +object ConcurrentSubject extends monix.reactive.internal.deprecated.ConcurrentSubjectDeprecatedBuilders { def apply[A](multicast: MulticastStrategy[A])(implicit s: Scheduler): ConcurrentSubject[A, A] = apply(multicast, Unbounded)(s) def apply[A](multicast: MulticastStrategy[A], overflow: OverflowStrategy.Synchronous[A])( - implicit s: Scheduler): ConcurrentSubject[A, A] = { + implicit s: Scheduler + ): ConcurrentSubject[A, A] = { multicast match { case MulticastStrategy.Publish => @@ -69,7 +70,8 @@ object ConcurrentSubject { def from[I, O]( p: Subject[I, O], overflowStrategy: Synchronous[I], - producerType: ChannelType.ProducerSide = MultiProducer)(implicit s: Scheduler): ConcurrentSubject[I, O] = + producerType: ChannelType.ProducerSide = MultiProducer + )(implicit s: Scheduler): ConcurrentSubject[I, O] = new SubjectAsConcurrent(p, overflowStrategy, producerType, s) /** Subject recipe for building [[PublishSubject publish]] subjects. */ @@ -118,7 +120,7 @@ object ConcurrentSubject { from(BehaviorSubject[A](initial), strategy) /** Subject recipe for building [[AsyncSubject async]] subjects. */ - def async[A](implicit s: Scheduler): ConcurrentSubject[A, A] = + def async[A]: ConcurrentSubject[A, A] = new ConcurrentAsyncSubject(AsyncSubject[A]()) /** Subject recipe for building [[ReplaySubject replay]] subjects. */ @@ -140,7 +142,7 @@ object ConcurrentSubject { * to subscribers before any elements emitted by the source. */ def replay[A](initial: Seq[A])(implicit s: Scheduler): ConcurrentSubject[A, A] = - from(ReplaySubject[A](initial: _*), Unbounded) + from(ReplaySubject[A](initial*), Unbounded) /** Subject recipe for building [[ReplaySubject replay]] subjects. * @@ -151,7 +153,7 @@ object ConcurrentSubject { * we're dealing with slow consumers. */ def replay[A](initial: Seq[A], strategy: Synchronous[A])(implicit s: Scheduler): ConcurrentSubject[A, A] = - from(ReplaySubject[A](initial: _*), strategy) + from(ReplaySubject[A](initial*), strategy) /** Subject recipe for building [[ReplaySubject replay]] subjects. * This variant creates a size-bounded replay subject. @@ -219,7 +221,8 @@ object ConcurrentSubject { * we're dealing with slow consumers. */ def replayLimited[A](capacity: Int, initial: Seq[A], strategy: Synchronous[A])( - implicit s: Scheduler): ConcurrentSubject[A, A] = + implicit s: Scheduler + ): ConcurrentSubject[A, A] = from(ReplaySubject.createLimited[A](capacity, initial), strategy) /** Transforms the source [[ConcurrentSubject]] into a `org.reactivestreams.Processor` @@ -232,13 +235,14 @@ object ConcurrentSubject { * the reactive streams specification */ def toReactiveProcessor[I, O](source: ConcurrentSubject[I, O], bufferSize: Int)( - implicit s: Scheduler): RProcessor[I, O] = { + implicit s: Scheduler + ): RProcessor[I, O] = { new RProcessor[I, O] { - private[this] val subscriber: RSubscriber[I] = + private val subscriber: RSubscriber[I] = Subscriber(source, s).toReactive(bufferSize) - def subscribe(subscriber: RSubscriber[_ >: O]): Unit = { + def subscribe(subscriber: RSubscriber[? >: O]): Unit = { val sub = SingleAssignCancelable() sub := source.unsafeSubscribeFn(Subscriber.fromReactiveSubscriber(subscriber, sub)) () @@ -260,10 +264,10 @@ object ConcurrentSubject { subject: Subject[I, O], overflowStrategy: OverflowStrategy.Synchronous[I], producerType: ChannelType.ProducerSide, - scheduler: Scheduler) - extends ConcurrentSubject[I, O] { + scheduler: Scheduler + ) extends ConcurrentSubject[I, O] { - private[this] val in: Subscriber.Sync[I] = + private val in: Subscriber.Sync[I] = BufferedSubscriber.synchronous(Subscriber(subject, scheduler), overflowStrategy, producerType) def size: Int = diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/subjects/PublishSubject.scala b/monix-reactive/shared/src/main/scala/monix/reactive/subjects/PublishSubject.scala index ed372134f..e04093318 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/subjects/PublishSubject.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/subjects/PublishSubject.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,11 @@ package monix.reactive.subjects -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.atomic.Atomic import monix.execution.atomic.PaddingStrategy.LeftRight128 import scala.util.control.NonFatal -import monix.execution.{Ack, Cancelable} +import monix.execution.{ Ack, Cancelable } import monix.reactive.internal.util.PromiseCounter import monix.reactive.observers.Subscriber import monix.reactive.subjects.PublishSubject.State @@ -43,7 +43,7 @@ final class PublishSubject[A] private () extends Subject[A, A] { self => * NOTE: the stored vector value can be null and if it is, then * that means our subject has been terminated. */ - private[this] val stateRef = Atomic.withPadding(State[A](), LeftRight128) + private val stateRef = Atomic.withPadding(State[A](), LeftRight128) private def onSubscribeCompleted(subscriber: Subscriber[A], ex: Throwable): Cancelable = { if (ex != null) subscriber.onError(ex) @@ -78,7 +78,9 @@ final class PublishSubject[A] private () extends Subject[A, A] { self => if (!stateRef.compareAndSet(state, update)) unsafeSubscribeFn(subscriber) // repeat else - Cancelable { () => unsubscribe(subscriber); () } + Cancelable { () => + val _ = unsubscribe(subscriber) + } } } @@ -93,7 +95,7 @@ final class PublishSubject[A] private () extends Subject[A, A] { self => val update = state.refresh // If CAS fails, it means we have new subscribers; // not bothering to recreate the cache for now - stateRef.compareAndSet(state, update) + val _ = stateRef.compareAndSet(state, update) sendOnNextToAll(update.cache, elem) } } else { @@ -125,20 +127,21 @@ final class PublishSubject[A] private () extends Subject[A, A] { self => // if execution is synchronous, takes the fast-path if (ack.isCompleted) { // subscriber canceled or triggered an error? Then remove! - if (ack != Continue && ack.value.get != Continue.AsSuccess) - unsubscribe(subscriber) + if (ack != Continue && ack.value.get != Continue.AsSuccess) { + val _ = unsubscribe(subscriber) + } } else { // going async, so we've got to count active futures for final Ack // the counter starts from 1 because zero implies isCompleted if (result == null) result = PromiseCounter(Continue, 1) result.acquire() - ack.onComplete { + val _ = ack.onComplete { case Continue.AsSuccess => result.countdown() case _ => // subscriber canceled or triggered an error? then remove - unsubscribe(subscriber) + val _ = unsubscribe(subscriber) result.countdown() } } @@ -209,7 +212,8 @@ object PublishSubject { private[subjects] final case class State[A]( subscribers: Set[Subscriber[A]] = Set.empty[Subscriber[A]], cache: Array[Subscriber[A]] = null, - errorThrown: Throwable = null) { + errorThrown: Throwable = null + ) { def refresh: State[A] = copy(cache = subscribers.toArray) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/subjects/PublishToOneSubject.scala b/monix-reactive/shared/src/main/scala/monix/reactive/subjects/PublishToOneSubject.scala index dae388c19..fdda57cda 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/subjects/PublishToOneSubject.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/subjects/PublishToOneSubject.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,15 +17,15 @@ package monix.reactive.subjects -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.atomic.Atomic import monix.execution.cancelables.BooleanCancelable import monix.execution.exceptions.APIContractViolationException -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.reactive.observers.Subscriber import scala.annotation.tailrec -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } /** `PublishToOneSubject` is a [[monix.reactive.subjects.PublishSubject]] * that can be subscribed at most once. @@ -39,11 +39,11 @@ import scala.concurrent.{Future, Promise} * one can also be notified when the subscription finally happens. */ final class PublishToOneSubject[A] private () extends Subject[A, A] with BooleanCancelable { - import PublishToOneSubject.{canceledState, pendingCompleteState} + import PublishToOneSubject.{ canceledState, pendingCompleteState } - private[this] val subscriptionP = Promise[Ack]() - private[this] var errorThrown: Throwable = _ - private[this] val ref = Atomic(null: Subscriber[A]) + private val subscriptionP = Promise[Ack]() + private var errorThrown: Throwable = null.asInstanceOf[Throwable] + private val ref = Atomic(null: Subscriber[A]) /** A `Future` that signals when the subscription happened * with a `Continue`, or with a `Stop` if the subscription diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/subjects/ReplaySubject.scala b/monix-reactive/shared/src/main/scala/monix/reactive/subjects/ReplaySubject.scala index a72130354..41a689580 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/subjects/ReplaySubject.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/subjects/ReplaySubject.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,12 @@ package monix.reactive.subjects -import monix.execution.Ack.{Continue, Stop} -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.{ Ack, Cancelable } +import monix.execution.Scheduler import monix.reactive.Observable import monix.reactive.internal.util.PromiseCounter -import monix.reactive.observers.{ConnectableSubscriber, Subscriber} +import monix.reactive.observers.{ ConnectableSubscriber, Subscriber } import monix.execution.atomic.Atomic import scala.util.control.NonFatal @@ -34,7 +35,7 @@ import scala.concurrent.Future */ final class ReplaySubject[A] private (initialState: ReplaySubject.State[A]) extends Subject[A, A] { self => - private[this] val stateRef = Atomic(initialState) + private val stateRef = Atomic(initialState) def size: Int = stateRef.get().subscribers.size @@ -74,7 +75,7 @@ final class ReplaySubject[A] private (initialState: ReplaySubject.State[A]) exte import subscriber.scheduler val connecting = c.connect() - connecting.syncOnStopOrFailure(_ => removeSubscriber(c)) + val _ = connecting.syncOnStopOrFailure(_ => removeSubscriber(c)) Cancelable { () => try removeSubscriber(c) @@ -215,7 +216,7 @@ object ReplaySubject { def createLimited[A](capacity: Int, initial: Seq[A]): ReplaySubject[A] = { require(capacity > 0, "capacity must be strictly positive") val elems = initial.takeRight(capacity) - new ReplaySubject[A](State[A](Queue(elems: _*), capacity)) + new ReplaySubject[A](State[A](Queue(elems*), capacity)) } /** Internal state for [[monix.reactive.subjects.ReplaySubject]] */ @@ -225,7 +226,8 @@ object ReplaySubject { subscribers: Set[ConnectableSubscriber[A]] = Set.empty[ConnectableSubscriber[A]], length: Int = 0, isDone: Boolean = false, - errorThrown: Throwable = null) { + errorThrown: Throwable = null + ) { def appendElem(elem: A): State[A] = { if (capacity == 0) diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/subjects/Subject.scala b/monix-reactive/shared/src/main/scala/monix/reactive/subjects/Subject.scala index 0cb8b39d3..f6403b896 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/subjects/Subject.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/subjects/Subject.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,8 +23,8 @@ import monix.execution.cancelables.SingleAssignCancelable import monix.execution.internal.Platform import monix.reactive.instances.CatsProfunctorForSubject import monix.reactive.observers.Subscriber -import monix.reactive.{Observable, Observer} -import org.reactivestreams.{Subscription, Processor => RProcessor, Subscriber => RSubscriber} +import monix.reactive.{ Observable, Observer } +import org.reactivestreams.{ Processor => RProcessor, Subscriber => RSubscriber, Subscription } /** A `Subject` is a sort of bridge or proxy that acts both as an * [[Observer]] and as an [[Observable]] and that must respect @@ -66,10 +66,10 @@ object Subject { */ def toReactiveProcessor[I, O](source: Subject[I, O], bufferSize: Int)(implicit s: Scheduler): RProcessor[I, O] = { new RProcessor[I, O] { - private[this] val subscriber: RSubscriber[I] = + private val subscriber: RSubscriber[I] = Subscriber(source, s).toReactive(bufferSize) - def subscribe(subscriber: RSubscriber[_ >: O]): Unit = { + def subscribe(subscriber: RSubscriber[? >: O]): Unit = { val sub = SingleAssignCancelable() sub := source.unsafeSubscribeFn(Subscriber.fromReactiveSubscriber(subscriber, sub)) () diff --git a/monix-reactive/shared/src/main/scala/monix/reactive/subjects/Var.scala b/monix-reactive/shared/src/main/scala/monix/reactive/subjects/Var.scala index e44177496..6d72e4159 100644 --- a/monix-reactive/shared/src/main/scala/monix/reactive/subjects/Var.scala +++ b/monix-reactive/shared/src/main/scala/monix/reactive/subjects/Var.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,8 +17,8 @@ package monix.reactive.subjects -import monix.execution.{Ack, Cancelable, Scheduler} -import monix.reactive.{Observable, OverflowStrategy} +import monix.execution.{ Ack, Cancelable, Scheduler } +import monix.reactive.{ Observable, OverflowStrategy } import monix.reactive.observers.Subscriber /** `Var` when subscribed, will emit the most recently emitted item by the source, @@ -55,8 +55,8 @@ import monix.reactive.observers.Subscriber */ final class Var[A] private (initial: A)(implicit s: Scheduler) extends Observable[A] { self => - private[this] var value: A = initial - private[this] val underlying = ConcurrentSubject.behavior(initial, OverflowStrategy.Unbounded) + private var value: A = initial + private val underlying = ConcurrentSubject.behavior(initial, OverflowStrategy.Unbounded) def unsafeSubscribeFn(subscriber: Subscriber[A]): Cancelable = underlying.unsafeSubscribeFn(subscriber) diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/BaseTestSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/BaseTestSuite.scala index cc9e0aec3..eb6cdc99f 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/BaseTestSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/BaseTestSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,16 +19,16 @@ package monix.reactive import cats.Eq import cats.Monoid -import minitest.{SimpleTestSuite, TestSuite} +import minitest.{ SimpleTestSuite, TestSuite } import minitest.laws.Checkers import monix.eval.Task import monix.execution.internal.Platform import monix.execution.schedulers.TestScheduler -import monix.reactive.Notification.{OnComplete, OnError, OnNext} +import monix.reactive.Notification.{ OnComplete, OnError, OnNext } import monix.reactive.observables.CombineObservable import monix.reactive.subjects._ import org.scalacheck.Test.Parameters -import org.scalacheck.{Arbitrary, Cogen, Gen, Prop} +import org.scalacheck.{ Arbitrary, Cogen, Gen, Prop } import org.typelevel.discipline.Laws import scala.concurrent.duration._ @@ -141,7 +141,7 @@ trait ArbitraryInstancesBase extends monix.eval.ArbitraryInstancesBase { } implicit def arbitraryCombineObservable[A: Arbitrary]: Arbitrary[CombineObservable.Type[A]] = { - import CombineObservable.{apply => wrap} + import CombineObservable.{ apply => wrap } Arbitrary { implicitly[Arbitrary[List[A]]].arbitrary .map(list => wrap(Observable.fromIterable(list))) diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/ObservableLikeConversionsSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/ObservableLikeConversionsSuite.scala index 7b667a9d4..9e42503db 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/ObservableLikeConversionsSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/ObservableLikeConversionsSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,15 +18,15 @@ package monix.reactive import cats.Eval -import cats.effect.{ContextShift, IO, SyncIO} +import cats.effect.{ ContextShift, IO, SyncIO } import monix.catnap.SchedulerEffect -import monix.eval.TaskConversionsSuite.{CIO, CustomConcurrentEffect, CustomEffect} -import monix.eval.{Coeval, Task} +import monix.eval.TaskConversionsSuite.{ CIO, CustomConcurrentEffect, CustomEffect } +import monix.eval.{ Coeval, Task } import monix.execution.exceptions.DummyException -import org.reactivestreams.{Publisher, Subscriber, Subscription} +import org.reactivestreams.{ Publisher, Subscriber, Subscription } import scala.concurrent.Promise -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } object ObservableLikeConversionsSuite extends BaseTestSuite { test("Observable.from(future)") { implicit s => @@ -279,7 +279,7 @@ object ObservableLikeConversionsSuite extends BaseTestSuite { test("Observable.from(ReactivePublisher)") { implicit s => val pub = new Publisher[Int] { - def subscribe(s: Subscriber[_ >: Int]): Unit = { + def subscribe(s: Subscriber[? >: Int]): Unit = { s.onSubscribe(new Subscription { var isActive = true def request(n: Long): Unit = { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/PipeSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/PipeSuite.scala index 04ee1c63b..e61871ead 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/PipeSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/PipeSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/TypeClassLawsForConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/TypeClassLawsForConsumerSuite.scala index 411a51e4e..56d40139f 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/TypeClassLawsForConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/TypeClassLawsForConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.reactive -import cats.laws.discipline.{ContravariantTests, ProfunctorTests} +import cats.laws.discipline.{ ContravariantTests, ProfunctorTests } object TypeClassLawsForConsumerSuite extends BaseLawsTestSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/TypeClassLawsForObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/TypeClassLawsForObservableSuite.scala index 6cc63df22..1bfa6e923 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/TypeClassLawsForObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/TypeClassLawsForObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,14 @@ package monix.reactive import cats.effect.laws.discipline.BracketTests import cats.laws.discipline.arbitrary.catsLawsArbitraryForPartialFunction -import cats.laws.discipline.{AlternativeTests, ApplyTests, CoflatMapTests, FunctorFilterTests, MonoidKTests, NonEmptyParallelTests} +import cats.laws.discipline.{ + AlternativeTests, + ApplyTests, + CoflatMapTests, + FunctorFilterTests, + MonoidKTests, + NonEmptyParallelTests +} import monix.reactive.observables.CombineObservable object TypeClassLawsForObservableSuite extends BaseLawsTestSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/TypeClassLawsForSubjectSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/TypeClassLawsForSubjectSuite.scala index 8c9ab2866..27b4f252a 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/TypeClassLawsForSubjectSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/TypeClassLawsForSubjectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/CancelConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/CancelConsumerSuite.scala index 7ddcd8faa..f2ac0b60c 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/CancelConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/CancelConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ import monix.execution.Ack.Stop import monix.execution.Cancelable import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler -import monix.reactive.{Consumer, Observable} +import monix.reactive.{ Consumer, Observable } import scala.concurrent.Promise import scala.util.Success diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/CompleteConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/CompleteConsumerSuite.scala index 249a1fd7f..38b9a5a64 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/CompleteConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/CompleteConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,10 +20,10 @@ package monix.reactive.consumers import minitest.TestSuite import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler -import monix.reactive.{Consumer, Observable} +import monix.reactive.{ Consumer, Observable } import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object CompleteConsumerSuite extends TestSuite[TestScheduler] { def setup(): TestScheduler = TestScheduler() diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ContramapConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ContramapConsumerSuite.scala index 5944adfcd..40145bd7e 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ContramapConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ContramapConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.consumers import cats.laws._ import cats.laws.discipline._ import monix.execution.exceptions.DummyException -import monix.reactive.{BaseTestSuite, Consumer, Observable} +import monix.reactive.{ BaseTestSuite, Consumer, Observable } import scala.util.Failure object ContramapConsumerSuite extends BaseTestSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/FirstNotificationConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/FirstNotificationConsumerSuite.scala index 9077a7336..67256fde8 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/FirstNotificationConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/FirstNotificationConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,8 +21,8 @@ import cats.effect.IO import minitest.TestSuite import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler -import monix.reactive.Notification.{OnComplete, OnError, OnNext} -import monix.reactive.{Consumer, Observable} +import monix.reactive.Notification.{ OnComplete, OnError, OnNext } +import monix.reactive.{ Consumer, Observable } import scala.util.Success object FirstNotificationConsumerSuite extends TestSuite[TestScheduler] { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/FoldLeftConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/FoldLeftConsumerSuite.scala index 16f63906c..dc284f79b 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/FoldLeftConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/FoldLeftConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,8 +20,8 @@ package monix.reactive.consumers import minitest.TestSuite import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler -import monix.reactive.{Consumer, Observable} -import scala.util.{Failure, Success} +import monix.reactive.{ Consumer, Observable } +import scala.util.{ Failure, Success } object FoldLeftConsumerSuite extends TestSuite[TestScheduler] { def setup(): TestScheduler = TestScheduler() diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/FoldLeftTaskConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/FoldLeftTaskConsumerSuite.scala index 1b6239338..7f5ef964c 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/FoldLeftTaskConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/FoldLeftTaskConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,8 +22,8 @@ import cats.laws.discipline._ import cats.effect.IO import monix.eval.Task import monix.execution.exceptions.DummyException -import monix.reactive.{BaseTestSuite, Consumer, Observable} -import scala.util.{Failure, Success} +import monix.reactive.{ BaseTestSuite, Consumer, Observable } +import scala.util.{ Failure, Success } object FoldLeftTaskConsumerSuite extends BaseTestSuite { test("should sum a long stream") { implicit s => @@ -32,7 +32,8 @@ object FoldLeftTaskConsumerSuite extends BaseTestSuite { val f = obs .consumeWith( Consumer - .foldLeftTask(0L)((s, a) => Task.evalAsync(s + a))) + .foldLeftTask(0L)((s, a) => Task.evalAsync(s + a)) + ) .runToFuture s.tick() @@ -45,7 +46,8 @@ object FoldLeftTaskConsumerSuite extends BaseTestSuite { val f = obs .consumeWith( Consumer - .foldLeftTask(0L)((s, a) => Task.evalAsync(s + a))) + .foldLeftTask(0L)((s, a) => Task.evalAsync(s + a)) + ) .runToFuture s.tick() @@ -89,7 +91,8 @@ object FoldLeftTaskConsumerSuite extends BaseTestSuite { .consumeWith(Consumer.foldLeftTask(0L)((_, _) => Task.never.doOnCancel(Task { cancelled = true - }))) + }) + )) .runToFuture s.tick() diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ForeachAsyncConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ForeachAsyncConsumerSuite.scala index 4ce4f098a..69064f6bb 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ForeachAsyncConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ForeachAsyncConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,10 +22,10 @@ import minitest.TestSuite import monix.eval.Task import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler -import monix.reactive.{Consumer, Observable} +import monix.reactive.{ Consumer, Observable } import scala.concurrent.Future -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object ForeachAsyncConsumerSuite extends TestSuite[TestScheduler] { def setup(): TestScheduler = TestScheduler() @@ -40,7 +40,8 @@ object ForeachAsyncConsumerSuite extends TestSuite[TestScheduler] { val f = obs .consumeWith( Consumer - .foreachEval(x => IO(sum += x))) + .foreachEval(x => IO(sum += x)) + ) .runToFuture s.tick() @@ -55,7 +56,8 @@ object ForeachAsyncConsumerSuite extends TestSuite[TestScheduler] { val f = obs .consumeWith( Consumer - .foreachTask(x => Task.evalAsync(sum += x))) + .foreachTask(x => Task.evalAsync(sum += x)) + ) .runToFuture s.tick() @@ -70,7 +72,8 @@ object ForeachAsyncConsumerSuite extends TestSuite[TestScheduler] { val f = obs .consumeWith( Consumer - .foreachTask(x => Task.evalAsync(sum += x))) + .foreachTask(x => Task.evalAsync(sum += x)) + ) .runToFuture s.tick() @@ -94,7 +97,8 @@ object ForeachAsyncConsumerSuite extends TestSuite[TestScheduler] { .consumeWith(Consumer.foreachTask(_ => Task.never.doOnCancel(Task { cancelled = true - }))) + }) + )) .runToFuture s.tick() diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ForeachConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ForeachConsumerSuite.scala index d58ea687f..4c22b4b73 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ForeachConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ForeachConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,8 +20,8 @@ package monix.reactive.consumers import minitest.TestSuite import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler -import monix.reactive.{Consumer, Observable} -import scala.util.{Failure, Success} +import monix.reactive.{ Consumer, Observable } +import scala.util.{ Failure, Success } object ForeachConsumerSuite extends TestSuite[TestScheduler] { def setup(): TestScheduler = TestScheduler() diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ForeachParallelAsyncConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ForeachParallelAsyncConsumerSuite.scala index 8a0a331a7..325a64831 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ForeachParallelAsyncConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ForeachParallelAsyncConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,9 +25,9 @@ import monix.execution.Cancelable import monix.execution.atomic.Atomic import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler -import monix.reactive.{Consumer, Observable} +import monix.reactive.{ Consumer, Observable } import scala.concurrent.Promise -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object ForeachParallelAsyncConsumerSuite extends TestSuite[TestScheduler] { def setup(): TestScheduler = TestScheduler() @@ -42,7 +42,8 @@ object ForeachParallelAsyncConsumerSuite extends TestSuite[TestScheduler] { val f = obs .consumeWith( Consumer - .foreachParallelTask(10)(x => Task.evalAsync(sum.add(x)))) + .foreachParallelTask(10)(x => Task.evalAsync(sum.add(x))) + ) .runToFuture s.tick() @@ -57,7 +58,8 @@ object ForeachParallelAsyncConsumerSuite extends TestSuite[TestScheduler] { val f = obs .consumeWith( Consumer - .foreachParallelTask(10)(x => Task.evalAsync(sum.add(x)))) + .foreachParallelTask(10)(x => Task.evalAsync(sum.add(x))) + ) .runToFuture s.tick() diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ForeachParallelConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ForeachParallelConsumerSuite.scala index 029a135f0..f826f99b7 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ForeachParallelConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ForeachParallelConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,10 +24,10 @@ import monix.execution.Cancelable import monix.execution.atomic.Atomic import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler -import monix.reactive.{Consumer, Observable} +import monix.reactive.{ Consumer, Observable } import scala.concurrent.Promise -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object ForeachParallelConsumerSuite extends TestSuite[TestScheduler] { def setup(): TestScheduler = TestScheduler() diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/FromObserverConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/FromObserverConsumerSuite.scala index 19927bf84..c85a06e3e 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/FromObserverConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/FromObserverConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,10 +23,10 @@ import monix.execution.{Callback, Scheduler} import monix.eval.Task import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException -import monix.reactive.{BaseTestSuite, Consumer, Observable, Observer} +import monix.reactive.{ BaseTestSuite, Consumer, Observable, Observer } import scala.concurrent.Promise -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object FromObserverConsumerSuite extends BaseTestSuite { test("convert an observer into a consumer") { implicit s => @@ -43,7 +43,8 @@ object FromObserverConsumerSuite extends BaseTestSuite { def onNext(elem: Int) = { sum += elem; Continue } - }) + } + ) val onFinish = Promise[Unit]() val (out, _) = consumer.createSubscriber(Callback.fromPromise(onFinish), s) @@ -69,7 +70,8 @@ object FromObserverConsumerSuite extends BaseTestSuite { def onError(ex: Throwable): Unit = throw ex def onComplete(): Unit = () def onNext(elem: Int) = Continue - }) + } + ) val (out, _) = consumer.createSubscriber(cb, s) source.endWithError(ex).unsafeSubscribeFn(out) diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/HeadConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/HeadConsumerSuite.scala index fdca6262e..cddbad805 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/HeadConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/HeadConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,9 +21,9 @@ import minitest.TestSuite import monix.eval.Task import monix.execution.schedulers.TestScheduler import monix.execution.exceptions.DummyException -import monix.reactive.{Consumer, Observable} +import monix.reactive.{ Consumer, Observable } -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object HeadConsumerSuite extends TestSuite[TestScheduler] { def setup(): TestScheduler = TestScheduler() @@ -62,7 +62,8 @@ object HeadConsumerSuite extends TestSuite[TestScheduler] { assert(wasCompleted, "wasCompleted") assert( f.value.isDefined && f.value.get.isFailure && - f.value.get.failed.get.isInstanceOf[NoSuchElementException]) + f.value.get.failed.get.isInstanceOf[NoSuchElementException] + ) } test("on error") { implicit s => diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/HeadOptionConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/HeadOptionConsumerSuite.scala index 304dc6a58..69374a055 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/HeadOptionConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/HeadOptionConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,9 +21,9 @@ import cats.effect.IO import minitest.TestSuite import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler -import monix.reactive.{Consumer, Observable} +import monix.reactive.{ Consumer, Observable } -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object HeadOptionConsumerSuite extends TestSuite[TestScheduler] { def setup(): TestScheduler = TestScheduler() diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ListConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ListConsumerSuite.scala index 723ccf1b5..7f5f88e3b 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ListConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/ListConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,9 +21,9 @@ import minitest.TestSuite import monix.execution.CancelableFuture import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler -import monix.reactive.{Consumer, Observable} +import monix.reactive.{ Consumer, Observable } -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object ListConsumerSuite extends TestSuite[TestScheduler] { def setup(): TestScheduler = TestScheduler() diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/LoadBalanceConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/LoadBalanceConsumerSuite.scala index c492f97d4..ccb23857b 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/LoadBalanceConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/LoadBalanceConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,17 +21,17 @@ import cats.laws._ import cats.laws.discipline._ import monix.execution.Callback -import monix.execution.Ack.{Continue, Stop} -import monix.execution.atomic.{Atomic, AtomicInt, AtomicLong} -import monix.execution.cancelables.{AssignableCancelable, BooleanCancelable, CompositeCancelable} -import monix.execution.{Ack, Cancelable, Scheduler} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.atomic.{ Atomic, AtomicInt, AtomicLong } +import monix.execution.cancelables.{ AssignableCancelable, BooleanCancelable, CompositeCancelable } +import monix.execution.{ Ack, Cancelable, Scheduler } import monix.execution.exceptions.DummyException import monix.reactive.internal.consumers.LoadBalanceConsumer import monix.reactive.observers.Subscriber -import monix.reactive.{BaseTestSuite, Consumer, Observable, Observer} +import monix.reactive.{ BaseTestSuite, Consumer, Observable, Observer } -import scala.concurrent.{Future, Promise} -import scala.util.{Failure, Success} +import scala.concurrent.{ Future, Promise } +import scala.util.{ Failure, Success } object LoadBalanceConsumerSuite extends BaseTestSuite { test("trigger error when parallelism < 1") { implicit s => @@ -80,7 +80,7 @@ object LoadBalanceConsumerSuite extends BaseTestSuite { val justOne = Consumer.headOption[Int].map(_.getOrElse(0).toLong) val allConsumers = for (i <- 0 until parallelism) yield if (i % 2 == 0) fold else justOne - val consumer = Consumer.loadBalance(allConsumers: _*) + val consumer = Consumer.loadBalance(allConsumers*) val task1 = source.foldLeft(0L)(_ + _).firstL val task2 = source.consumeWith(consumer).map(_.sum) task1 <-> task2 diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/MapConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/MapConsumerSuite.scala index ad3c23a97..7a51cd941 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/MapConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/MapConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.consumers import cats.laws._ import cats.laws.discipline._ import monix.execution.exceptions.DummyException -import monix.reactive.{BaseTestSuite, Consumer, Observable} +import monix.reactive.{ BaseTestSuite, Consumer, Observable } import scala.util.Failure object MapConsumerSuite extends BaseTestSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/MapEvalConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/MapEvalConsumerSuite.scala index a5a1cfa80..64d18c7ee 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/MapEvalConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/MapEvalConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import cats.laws._ import cats.laws.discipline._ import cats.effect.IO import monix.execution.exceptions.DummyException -import monix.reactive.{BaseTestSuite, Consumer, Observable} +import monix.reactive.{ BaseTestSuite, Consumer, Observable } import scala.util.Failure object MapEvalConsumerSuite extends BaseTestSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/MapTaskConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/MapTaskConsumerSuite.scala index a67a77147..3c3cebe78 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/MapTaskConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/MapTaskConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import cats.laws._ import cats.laws.discipline._ import monix.eval.Task import monix.execution.exceptions.DummyException -import monix.reactive.{BaseTestSuite, Consumer, Observable} +import monix.reactive.{ BaseTestSuite, Consumer, Observable } import scala.util.Failure object MapTaskConsumerSuite extends BaseTestSuite { @@ -106,7 +106,9 @@ object MapTaskConsumerSuite extends BaseTestSuite { .never[Int] .doOnCancel(Task { taskCancelled = true - }))) + }) + ) + ) .runToFuture s.tick() diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/RaiseErrorConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/RaiseErrorConsumerSuite.scala index d03d5cdfd..db8df9d73 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/RaiseErrorConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/RaiseErrorConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import monix.execution.Callback import monix.execution.Ack.Stop import monix.execution.cancelables.BooleanCancelable import monix.execution.exceptions.DummyException -import monix.reactive.{BaseTestSuite, Consumer} +import monix.reactive.{ BaseTestSuite, Consumer } import scala.concurrent.Promise import scala.util.Failure diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/TransformInputConsumerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/TransformInputConsumerSuite.scala index 7e76b2647..2471ce2e2 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/consumers/TransformInputConsumerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/consumers/TransformInputConsumerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,7 +24,7 @@ import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.atomic.Atomic import monix.execution.exceptions.DummyException -import monix.reactive.{BaseTestSuite, Consumer, Observable, Observer} +import monix.reactive.{ BaseTestSuite, Consumer, Observable, Observer } import scala.concurrent.Future import scala.concurrent.duration._ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/AsyncStateActionObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/AsyncStateActionObservableSuite.scala index 2849e4da9..34a3b0bbc 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/AsyncStateActionObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/AsyncStateActionObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -151,7 +151,7 @@ object AsyncStateActionObservableSuite extends TestSuite[TestScheduler] { def int(seed: Long): (Int, Long) = { // `&` is bitwise AND. We use the current seed to generate a new seed. - val newSeed = (seed * 0X5DEECE66DL + 0XBL) & 0XFFFFFFFFFFFFL + val newSeed = (seed * 0x5deece66dL + 0xbL) & 0xffffffffffffL // The next state, which is an `RNG` instance created from the new seed. val nextRNG = newSeed // `>>>` is right binary shift with zero fill. The value `n` is our new pseudo-random integer. diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/BracketObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/BracketObservableSuite.scala index 2d6a41a8f..8581340d6 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/BracketObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/BracketObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,7 +24,7 @@ import monix.eval.Task import monix.execution.Ack.Continue import monix.execution.Scheduler import monix.reactive.observers.Subscriber -import monix.reactive.{BaseTestSuite, Observable} +import monix.reactive.{ BaseTestSuite, Observable } import scala.concurrent.duration._ import scala.util.Success diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/BufferedIteratorAsObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/BufferedIteratorAsObservableSuite.scala index c9b5f1987..b1b3da83d 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/BufferedIteratorAsObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/BufferedIteratorAsObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,9 +21,9 @@ import cats.effect.Resource import minitest.TestSuite import monix.eval.Task import monix.execution.Ack.Continue -import monix.execution.exceptions.{APIContractViolationException, DummyException} +import monix.execution.exceptions.{ APIContractViolationException, DummyException } import monix.execution.schedulers.TestScheduler -import monix.execution.{Ack, ExecutionModel, Scheduler} +import monix.execution.{ Ack, ExecutionModel, Scheduler } import monix.reactive.Observable import monix.reactive.observers.Subscriber @@ -362,7 +362,7 @@ object BufferedIteratorAsObservableSuite extends TestSuite[TestScheduler] { val seq = 0 until n * 4 val obs = Observable .fromIteratorBufferedUnsafe(seq.iterator, n) - .delayOnNext(1.millis) + .delayOnNext(1.millis) obs.executeAsync.unsafeSubscribeFn(new Subscriber[Seq[Int]] { implicit val scheduler: Scheduler = sc @@ -394,10 +394,12 @@ object BufferedIteratorAsObservableSuite extends TestSuite[TestScheduler] { val seq = 0 to 10 val f = Observable .fromIteratorBufferedUnsafe(seq.iterator, 4) - .toListL - .runToFuture + .toListL + .runToFuture - val expected = List(Seq(0, 1, 2, 3), Seq(4, 5, 6, 7), Seq(8, 9, 10)).map(seq => toSeq(seq.map(_.asInstanceOf[AnyRef]).toArray[AnyRef])) + val expected = List(Seq(0, 1, 2, 3), Seq(4, 5, 6, 7), Seq(8, 9, 10)).map(seq => + toSeq(seq.map(_.asInstanceOf[AnyRef]).toArray[AnyRef]) + ) s.tick() diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/CatsConversionsSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/CatsConversionsSuite.scala index 6fe957a46..34ac62b8f 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/CatsConversionsSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/CatsConversionsSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.builders import cats.Eval import cats.effect.IO -import monix.reactive.{BaseTestSuite, Observable} +import monix.reactive.{ BaseTestSuite, Observable } import scala.util.Success object CatsConversionsSuite extends BaseTestSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/CharsReaderObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/CharsReaderObservableSuite.scala index 35fc13a27..a38f5b449 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/CharsReaderObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/CharsReaderObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,23 +17,25 @@ package monix.reactive.internal.builders -import java.io.{Reader, StringReader} +import java.io.{ Reader, StringReader } + import cats.effect.ExitCase import minitest.SimpleTestSuite import minitest.laws.Checkers import monix.eval.Task import monix.execution.{Ack, Scheduler} import monix.execution.Ack.Continue -import monix.execution.ExecutionModel.{AlwaysAsyncExecution, BatchedExecution, SynchronousExecution} +import monix.execution.ExecutionModel.{ AlwaysAsyncExecution, BatchedExecution, SynchronousExecution } +import monix.execution.Scheduler import monix.execution.exceptions.APIContractViolationException import monix.execution.schedulers.TestScheduler import monix.reactive.Observable import monix.execution.exceptions.DummyException import monix.reactive.observers.Subscriber -import org.scalacheck.{Gen, Prop} +import org.scalacheck.{ Gen, Prop } import scala.collection.mutable.ArrayBuffer -import scala.util.{Failure, Random, Success} +import scala.util.{ Failure, Random, Success } object CharsReaderObservableSuite extends SimpleTestSuite with Checkers { test("fromCharsReaderUnsafe yields a single subscriber observable") { @@ -329,7 +331,7 @@ object CharsReaderObservableSuite extends SimpleTestSuite with Checkers { def inputWithError(ex: Throwable, whenToThrow: Int, onFinish: () => Unit): Reader = new Reader { - private[this] var callIdx = 0 + private var callIdx = 0 def read(cbuf: Array[Char], off: Int, len: Int): Int = { callIdx += 1 @@ -360,7 +362,8 @@ object CharsReaderObservableSuite extends SimpleTestSuite with Checkers { nLines: Int = 100, nMinLines: Int = 0, nCharsPerLine: Int = 100, - nMinCharsPerLine: Int = 0): String = { + nMinCharsPerLine: Int = 0 + ): String = { val chars = (('a' to 'z') ++ ('A' to 'Z') ++ ('0' to '9')).toVector val builder = new StringBuilder diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/CreateObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/CreateObservableSuite.scala index c2a656241..9469e290e 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/CreateObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/CreateObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/EmptyObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/EmptyObservableSuite.scala index 04a8734ea..20748ef78 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/EmptyObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/EmptyObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.builders import minitest.TestSuite import monix.execution.schedulers.TestScheduler -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } object EmptyObservableSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/ErrorObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/ErrorObservableSuite.scala index a36cda4ec..db3d99b74 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/ErrorObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/ErrorObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.builders import minitest.TestSuite import monix.execution.schedulers.TestScheduler -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import monix.execution.exceptions.DummyException object ErrorObservableSuite extends TestSuite[TestScheduler] { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/EvalAlwaysObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/EvalAlwaysObservableSuite.scala index 3311693be..885152a3b 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/EvalAlwaysObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/EvalAlwaysObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import minitest.TestSuite import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.schedulers.TestScheduler -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future object EvalAlwaysObservableSuite extends TestSuite[TestScheduler] { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/EvalObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/EvalObservableSuite.scala index b924a6794..091b117fe 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/EvalObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/EvalObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import cats.laws._ import cats.laws.discipline._ import monix.eval.Coeval import monix.execution.exceptions.DummyException -import monix.reactive.{BaseTestSuite, Observable} +import monix.reactive.{ BaseTestSuite, Observable } import scala.util.Success object EvalObservableSuite extends BaseTestSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/EvalOnceObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/EvalOnceObservableSuite.scala index 7bbcb1bbc..42ef42867 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/EvalOnceObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/EvalOnceObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/ExecuteAsyncObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/ExecuteAsyncObservableSuite.scala index 74a1124e9..e2399e471 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/ExecuteAsyncObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/ExecuteAsyncObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,8 +23,8 @@ import monix.execution.Ack.Stop import monix.execution.internal.Platform import monix.execution.ExecutionModel.SynchronousExecution import monix.execution.schedulers.TestScheduler -import monix.reactive.{Observable, Observer} -import scala.concurrent.{Future, Promise} +import monix.reactive.{ Observable, Observer } +import scala.concurrent.{ Future, Promise } import scala.util.Success object ExecuteAsyncObservableSuite extends TestSuite[TestScheduler] { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/FirstStartedObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/FirstStartedObservableSuite.scala index a199f73dc..9dc1084d9 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/FirstStartedObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/FirstStartedObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.internal.builders import cats.effect.IO import cats.laws._ import cats.laws.discipline._ -import monix.reactive.{BaseTestSuite, Observable} +import monix.reactive.{ BaseTestSuite, Observable } import scala.concurrent.duration._ object FirstStartedObservableSuite extends BaseTestSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/FromResourceObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/FromResourceObservableSuite.scala index 15e4a1abd..c6dfbfd35 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/FromResourceObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/FromResourceObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.builders import cats.effect.Resource import monix.eval.Task -import monix.reactive.{BaseTestSuite, Observable} +import monix.reactive.{ BaseTestSuite, Observable } import scala.concurrent.duration._ import scala.util.Success diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/FutureAsObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/FutureAsObservableSuite.scala index 7f2f2cc65..df46fdccc 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/FutureAsObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/FutureAsObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ import monix.execution.Ack.Continue import monix.execution.FutureUtils.extensions._ import monix.execution.schedulers.TestScheduler import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future import scala.concurrent.duration._ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/InputStreamObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/InputStreamObservableSuite.scala index 51ad68643..208fdb1ef 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/InputStreamObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/InputStreamObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,21 +17,23 @@ package monix.reactive.internal.builders -import java.io.{ByteArrayInputStream, InputStream} +import java.io.{ ByteArrayInputStream, InputStream } + import minitest.SimpleTestSuite import minitest.laws.Checkers import monix.eval.Task import monix.execution.{Ack, Scheduler} import monix.execution.Ack.Continue -import monix.execution.ExecutionModel.{AlwaysAsyncExecution, BatchedExecution, SynchronousExecution} -import monix.execution.exceptions.{APIContractViolationException, DummyException} +import monix.execution.ExecutionModel.{ AlwaysAsyncExecution, BatchedExecution, SynchronousExecution } +import monix.execution.Scheduler +import monix.execution.exceptions.{ APIContractViolationException, DummyException } import monix.execution.schedulers.TestScheduler import monix.reactive.Observable import monix.reactive.observers.Subscriber -import org.scalacheck.{Gen, Prop} +import org.scalacheck.{ Gen, Prop } import scala.collection.mutable.ListBuffer -import scala.util.{Failure, Random, Success} +import scala.util.{ Failure, Random, Success } object InputStreamObservableSuite extends SimpleTestSuite with Checkers { test("fromInputStreamUnsafe yields a single subscriber observable") { @@ -247,7 +249,7 @@ object InputStreamObservableSuite extends SimpleTestSuite with Checkers { implicit val s = TestScheduler() val gen = for { - byteSize <- Gen.choose(1, 4096) + byteSize <- Gen.choose(1, 4096) chunkSize <- Gen.choose(Math.floorDiv(byteSize, 2).max(1), byteSize * 2) } yield { (byteSize, chunkSize) @@ -289,7 +291,7 @@ object InputStreamObservableSuite extends SimpleTestSuite with Checkers { def inputWithError(ex: Throwable, whenToThrow: Int, onFinish: () => Unit): InputStream = new InputStream { - private[this] var callIdx = 0 + private var callIdx = 0 def read(): Int = { callIdx += 1 diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/IntervalObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/IntervalObservableSuite.scala index 861858acc..743415c86 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/IntervalObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/IntervalObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.FutureUtils.extensions._ import monix.execution.schedulers.TestScheduler -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future import scala.concurrent.duration._ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/IterableAsObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/IterableAsObservableSuite.scala index 50bd3071a..2484ab20f 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/IterableAsObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/IterableAsObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,13 +18,13 @@ package monix.reactive.internal.builders import minitest.TestSuite -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.FutureUtils.extensions._ import monix.execution.Scheduler import monix.execution.internal.Platform import monix.execution.schedulers.TestScheduler import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import monix.reactive.observers.Subscriber import scala.concurrent.Future diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/IteratorAsObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/IteratorAsObservableSuite.scala index 8e011abf9..18455126f 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/IteratorAsObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/IteratorAsObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ import minitest.TestSuite import monix.eval.Task import monix.execution.Ack.Continue import monix.execution.exceptions.APIContractViolationException -import monix.execution.{Ack, Scheduler} +import monix.execution.{ Ack, Scheduler } import monix.execution.schedulers.TestScheduler import monix.reactive.Observable import monix.execution.exceptions.DummyException diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/LinesReaderObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/LinesReaderObservableSuite.scala index f7bb0db40..8038e44c4 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/LinesReaderObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/LinesReaderObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,19 +17,21 @@ package monix.reactive.internal.builders -import java.io.{BufferedReader, Reader, StringReader} +import java.io.{ BufferedReader, Reader, StringReader } + import minitest.SimpleTestSuite import monix.eval.Task import monix.execution.{Ack, Scheduler} import monix.execution.Ack.Continue -import monix.execution.ExecutionModel.{AlwaysAsyncExecution, BatchedExecution, SynchronousExecution} +import monix.execution.Scheduler +import monix.execution.ExecutionModel.{ AlwaysAsyncExecution, BatchedExecution, SynchronousExecution } import monix.execution.exceptions.APIContractViolationException import monix.execution.schedulers.TestScheduler import monix.reactive.Observable import monix.execution.exceptions.DummyException import monix.reactive.observers.Subscriber -import scala.util.{Failure, Random, Success} +import scala.util.{ Failure, Random, Success } object LinesReaderObservableSuite extends SimpleTestSuite { test("fromLinesReaderUnsafe yields a single subscriber observable") { @@ -201,7 +203,7 @@ object LinesReaderObservableSuite extends SimpleTestSuite { def inputWithError(ex: Throwable, whenToThrow: Int, onFinish: () => Unit): BufferedReader = { val reader = new Reader { - private[this] var callIdx = 0 + private var callIdx = 0 def read(cbuf: Array[Char], off: Int, len: Int): Int = { callIdx += 1 diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/NeverObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/NeverObservableSuite.scala index 1fb16176a..2ed6be581 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/NeverObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/NeverObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.builders import minitest.TestSuite import monix.execution.schedulers.TestScheduler -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import concurrent.duration._ object NeverObservableSuite extends TestSuite[TestScheduler] { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/NowObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/NowObservableSuite.scala index 8f2ddc31a..86b8da0b1 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/NowObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/NowObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,10 +19,10 @@ package monix.reactive.internal.builders import minitest.TestSuite import monix.execution.Ack -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.schedulers.TestScheduler -import monix.reactive.{Observable, Observer} -import scala.concurrent.{Future, Promise} +import monix.reactive.{ Observable, Observer } +import scala.concurrent.{ Future, Promise } object NowObservableSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/PaginateEvalObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/PaginateEvalObservableSuite.scala index 76b50407d..f80dbd832 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/PaginateEvalObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/PaginateEvalObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,15 +17,12 @@ package monix.reactive.internal.builders -import cats.laws._ -import cats.laws.discipline._ import monix.eval.Task import monix.execution.Ack.Continue import monix.execution.Scheduler import monix.execution.exceptions.DummyException import monix.reactive.observers.Subscriber -import monix.reactive.{BaseTestSuite, Observable} - +import monix.reactive.{ BaseTestSuite, Observable } import scala.concurrent.duration.MILLISECONDS object PaginateEvalObservableSuite extends BaseTestSuite { @@ -46,9 +43,10 @@ object PaginateEvalObservableSuite extends BaseTestSuite { test("paginateEval should execute 11 times and then return None") { implicit s => var received = 0 - Observable.paginateEval(0)(i => if (i < 10) Task.now((i, Some(i + 1))) else Task.now((i, None))).subscribe { (_: Int) => - received += 1 - Continue + Observable.paginateEval(0)(i => if (i < 10) Task.now((i, Some(i + 1))) else Task.now((i, None))).subscribe { + (_: Int) => + received += 1 + Continue } assertEquals((0 until received).toList, (0 to 10).toList) @@ -85,7 +83,7 @@ object PaginateEvalObservableSuite extends BaseTestSuite { def int(seed: Long): (Int, Option[Long]) = { // `&` is bitwise AND. We use the current seed to generate a new seed. - val newSeed = (seed * 0X5DEECE66DL + 0XBL) & 0XFFFFFFFFFFFFL + val newSeed = (seed * 0x5deece66dL + 0xbL) & 0xffffffffffffL // The next state, which is an `RNG` instance created from the new seed. val nextRNG = newSeed // `>>>` is right binary shift with zero fill. The value `n` is our new pseudo-random integer. diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/PaginateObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/PaginateObservableSuite.scala index b9e4eb33d..3ae207099 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/PaginateObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/PaginateObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,14 +17,10 @@ package monix.reactive.internal.builders -import cats.laws._ -import cats.laws.discipline._ import monix.execution.Ack.Continue import monix.execution.Scheduler -import monix.execution.internal.Platform.recommendedBatchSize import monix.reactive.observers.Subscriber -import monix.reactive.{BaseTestSuite, Observable} - +import monix.reactive.{ BaseTestSuite, Observable } import scala.concurrent.duration.MILLISECONDS object PaginateObservableSuite extends BaseTestSuite { @@ -82,7 +78,7 @@ object PaginateObservableSuite extends BaseTestSuite { def intOption(seed: Long): (Int, Option[Long]) = { // `&` is bitwise AND. We use the current seed to generate a new seed. - val newSeed = (seed * 0X5DEECE66DL + 0XBL) & 0XFFFFFFFFFFFFL + val newSeed = (seed * 0x5deece66dL + 0xbL) & 0xffffffffffffL // The next state, which is an `RNG` instance created from the new seed. val nextRNG = newSeed // `>>>` is right binary shift with zero fill. The value `n` is our new pseudo-random integer. diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RangeObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RangeObservableSuite.scala index fc49579b7..55a8a748d 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RangeObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RangeObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,14 +18,14 @@ package monix.reactive.internal.builders import minitest.TestSuite -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.Scheduler import monix.execution.FutureUtils.extensions._ import monix.execution.Scheduler import monix.execution.internal.Platform import monix.execution.schedulers.TestScheduler import monix.reactive.observers.Subscriber -import monix.reactive.{Observable, Observer} - +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future import scala.concurrent.duration._ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RepeatEvalFSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RepeatEvalFSuite.scala index a447b0115..844c21e46 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RepeatEvalFSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RepeatEvalFSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.internal.Platform import monix.execution.schedulers.TestScheduler -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import monix.execution.FutureUtils.extensions._ import monix.execution.exceptions.DummyException diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RepeatEvalObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RepeatEvalObservableSuite.scala index 0bcc80afd..bec293ea3 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RepeatEvalObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RepeatEvalObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RepeatOneObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RepeatOneObservableSuite.scala index da8f9563d..f566cf23c 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RepeatOneObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RepeatOneObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RepeatedValueObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RepeatedValueObservableSuite.scala index 70c055f61..2f34c52ac 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RepeatedValueObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/RepeatedValueObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.FutureUtils.extensions._ import monix.execution.schedulers.TestScheduler -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future import scala.concurrent.duration._ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/ResourceCaseObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/ResourceCaseObservableSuite.scala index 52c36f031..2ed84169a 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/ResourceCaseObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/ResourceCaseObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,11 +26,11 @@ import monix.execution.Ack.Continue import monix.execution.Scheduler import monix.execution.exceptions.DummyException import monix.reactive.observers.Subscriber -import monix.reactive.{BaseTestSuite, Consumer, Observable} +import monix.reactive.{ BaseTestSuite, Consumer, Observable } import scala.concurrent.Promise import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object ResourceCaseObservableSuite extends BaseTestSuite { class Resource(var acquired: Int = 0, var released: Int = 0) { @@ -56,7 +56,8 @@ object ResourceCaseObservableSuite extends BaseTestSuite { .flatMap(_ => Observable(1, 2, 3).doOnEarlyStop(Task { earlyStopDone = true - })) + }) + ) bracketed.take(1L).completedL.runToFuture s.tick() @@ -275,7 +276,8 @@ object ResourceCaseObservableSuite extends BaseTestSuite { .resource(Task.unit)(_ => Task { released = true - }) + } + ) .flatMap { _ => Observable .resource(Task.unit)(_ => Task.raiseError(dummy)) @@ -296,7 +298,8 @@ object ResourceCaseObservableSuite extends BaseTestSuite { .resource(Task.unit)(_ => Task { released = true - }) + } + ) .flatMap { _ => Observable.suspend[Int](Observable.raiseError(dummy)) } @@ -316,7 +319,8 @@ object ResourceCaseObservableSuite extends BaseTestSuite { .resource(Task.unit)(_ => Task { released = true - }) + } + ) .flatMap(_ => Observable(1, 2, 3)) } @@ -399,7 +403,8 @@ object ResourceCaseObservableSuite extends BaseTestSuite { })(_ => Task { log :+= s"Stop: $key" - }) + } + ) .flatMap(Observable.pure) val observable = for { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/StateActionObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/StateActionObservableSuite.scala index 9375a2cb4..d07f49d84 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/StateActionObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/StateActionObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -86,7 +86,7 @@ object StateActionObservableSuite extends TestSuite[TestScheduler] { def int(seed: Long): (Int, Long) = { // `&` is bitwise AND. We use the current seed to generate a new seed. - val newSeed = (seed * 0X5DEECE66DL + 0XBL) & 0XFFFFFFFFFFFFL + val newSeed = (seed * 0x5deece66dL + 0xbL) & 0xffffffffffffL // The next state, which is an `RNG` instance created from the new seed. val nextRNG = newSeed // `>>>` is right binary shift with zero fill. The value `n` is our new pseudo-random integer. diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/UnfoldEvalObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/UnfoldEvalObservableSuite.scala index 76e054d5e..d5ce4cedc 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/UnfoldEvalObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/UnfoldEvalObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,7 +26,7 @@ import monix.execution.Scheduler import monix.execution.exceptions.DummyException import monix.execution.internal.Platform.recommendedBatchSize import monix.reactive.observers.Subscriber -import monix.reactive.{BaseTestSuite, Observable} +import monix.reactive.{ BaseTestSuite, Observable } import scala.concurrent.duration.MILLISECONDS @@ -48,7 +48,7 @@ object UnfoldEvalObservableSuite extends BaseTestSuite { test("unfoldEval and fromAsyncStateAction results should be equal given generated inputs") { implicit s => check2 { (s: Int, i: Int) => val seed = s % (recommendedBatchSize * 2) - val n = i % (recommendedBatchSize * 2) + val n = i % (recommendedBatchSize * 2) val f: Int => Task[Option[(Int, Int)]] = i => if (i < n) Task.delay(Some((i, i + 1))) else Task.now(None) val f2: Int => Task[(Int, Int)] = i => Task.delay((i, i + 1)) @@ -100,7 +100,7 @@ object UnfoldEvalObservableSuite extends BaseTestSuite { test("unfoldEvalF and fromAsyncStateActionF results should be equal given generated inputs") { implicit s => check2 { (s: Int, i: Int) => val seed = s % (recommendedBatchSize * 2) - val n = i % (recommendedBatchSize * 2) + val n = i % (recommendedBatchSize * 2) val f: Int => IO[Option[(Int, Int)]] = i => if (i < n) IO.delay(Some((i, i + 1))) else IO.pure(None) val f2: Int => IO[(Int, Int)] = i => IO.delay((i, i + 1)) @@ -142,7 +142,7 @@ object UnfoldEvalObservableSuite extends BaseTestSuite { def int(seed: Long): (Int, Long) = { // `&` is bitwise AND. We use the current seed to generate a new seed. - val newSeed = (seed * 0X5DEECE66DL + 0XBL) & 0XFFFFFFFFFFFFL + val newSeed = (seed * 0x5deece66dL + 0xbL) & 0xffffffffffffL // The next state, which is an `RNG` instance created from the new seed. val nextRNG = newSeed // `>>>` is right binary shift with zero fill. The value `n` is our new pseudo-random integer. diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/UnfoldObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/UnfoldObservableSuite.scala index 9d39ff602..1977263ee 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/UnfoldObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/UnfoldObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ import monix.execution.Ack.Continue import monix.execution.Scheduler import monix.execution.internal.Platform.recommendedBatchSize import monix.reactive.observers.Subscriber -import monix.reactive.{BaseTestSuite, Observable} +import monix.reactive.{ BaseTestSuite, Observable } import scala.concurrent.duration.MILLISECONDS @@ -83,7 +83,7 @@ object UnfoldObservableSuite extends BaseTestSuite { test("unfold and fromStateAction results should be equal given generated inputs") { implicit s => check2 { (s: Int, i: Int) => val seed = s % (recommendedBatchSize * 2) - val n = i % (recommendedBatchSize * 2) + val n = i % (recommendedBatchSize * 2) val f: Int => Option[(Int, Int)] = i => if (i < n) Some((i, i + 1)) else None val f2: Int => (Int, Int) = i => (i, i + 1) @@ -96,7 +96,7 @@ object UnfoldObservableSuite extends BaseTestSuite { def int(seed: Long): (Int, Long) = { // `&` is bitwise AND. We use the current seed to generate a new seed. - val newSeed = (seed * 0X5DEECE66DL + 0XBL) & 0XFFFFFFFFFFFFL + val newSeed = (seed * 0x5deece66dL + 0xbL) & 0xffffffffffffL // The next state, which is an `RNG` instance created from the new seed. val nextRNG = newSeed // `>>>` is right binary shift with zero fill. The value `n` is our new pseudo-random integer. diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/UnsafeCreateObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/UnsafeCreateObservableSuite.scala index ffa9bc771..eed3a1e23 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/UnsafeCreateObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/builders/UnsafeCreateObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,11 +18,11 @@ package monix.reactive.internal.builders import minitest.TestSuite -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.schedulers.TestScheduler -import monix.execution.{Ack, Cancelable} +import monix.execution.{ Ack, Cancelable } import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future import scala.util.Success diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/AsyncBoundarySuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/AsyncBoundarySuite.scala index a686cc348..c5d0ce4dd 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/AsyncBoundarySuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/AsyncBoundarySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BaseOperatorSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BaseOperatorSuite.scala index bb01992af..50669b21d 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BaseOperatorSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BaseOperatorSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,15 +17,15 @@ package monix.reactive.internal.operators -import monix.execution.{Ack, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack +import monix.execution.Ack.{ Continue, Stop } import monix.execution.FutureUtils.extensions._ +import monix.execution.Scheduler import monix.execution.exceptions.DummyException import monix.reactive.observers.Subscriber -import monix.reactive.{BaseTestSuite, Observable, Observer} - +import monix.reactive.{ BaseTestSuite, Observable, Observer } import scala.concurrent.duration._ -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.util.Random abstract class BaseOperatorSuite extends BaseTestSuite { @@ -116,7 +116,7 @@ abstract class BaseOperatorSuite extends BaseTestSuite { case None => ignore() case Some(Sample(obs, count, sum, waitForFirst, waitForNext)) => obs.unsafeSubscribeFn(new Observer[Long] { - private[this] var sum = 0L + private var sum = 0L def onNext(elem: Long): Ack = { received += 1 @@ -145,8 +145,8 @@ abstract class BaseOperatorSuite extends BaseTestSuite { case None => ignore() case Some(Sample(obs, count, sum, waitForFirst, waitForNext)) => obs.unsafeSubscribeFn(new Observer[Long] { - private[this] var sum = 0L - private[this] var ack: Future[Ack] = Continue + private var sum = 0L + private var ack: Future[Ack] = Continue def onNext(elem: Long): Future[Ack] = { assert(ack.isCompleted, s"Contact breach at elem $elem of $sourceCount, last ack is not completed") diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferIntrospectiveSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferIntrospectiveSuite.scala index dd680a221..815adf916 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferIntrospectiveSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferIntrospectiveSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,6 +21,7 @@ import minitest.TestSuite import monix.eval.Task import monix.execution.{Ack, Scheduler} import monix.execution.Ack.Continue +import monix.execution.Scheduler import monix.execution.schedulers.TestScheduler import monix.reactive.observers.Subscriber import monix.reactive.subjects.PublishSubject @@ -28,7 +29,7 @@ import monix.execution.atomic.Atomic import monix.reactive.Observable import scala.concurrent.duration._ -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.util.Success object BufferIntrospectiveSuite extends TestSuite[TestScheduler] { @@ -72,7 +73,7 @@ object BufferIntrospectiveSuite extends TestSuite[TestScheduler] { s.tick() assertEquals(sum, 6) - for (i <- 0 until 10) subject.onNext(1) + for (_ <- 0 until 10) subject.onNext(1) s.tick() assertEquals(sum, 6) diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferSlidingDropSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferSlidingDropSuite.scala index 2ce85d12b..a0dcbcb2a 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferSlidingDropSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferSlidingDropSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -38,7 +38,8 @@ object BufferSlidingDropSuite extends BaseOperatorSuite { val count = 2 + (sc - 4) / 2 val sum = count / 4 * 6 Sample(o, count, sum.toLong, waitFirst, waitNext) - } else + } + else Some { val o = Observable .now(1L) diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferSlidingOverlapSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferSlidingOverlapSuite.scala index df4836826..335e1db16 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferSlidingOverlapSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferSlidingOverlapSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -37,7 +37,8 @@ object BufferSlidingOverlapSuite extends BaseOperatorSuite { val count = 8 + (divBy4 - 8) * 2 val sum = (count / 4) * 6 Sample(o, count, sum.toLong, waitFirst, waitNext) - } else + } + else Some { val o = Observable .now(1L) diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferSlidingSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferSlidingSuite.scala index b095ea019..5441b2cf3 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferSlidingSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferSlidingSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.internal.operators import cats.laws._ import cats.laws.discipline._ import monix.eval.Task -import monix.reactive.{BaseTestSuite, Observable} +import monix.reactive.{ BaseTestSuite, Observable } import scala.concurrent.duration._ import scala.util.Success diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferTimedOrCountedSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferTimedOrCountedSuite.scala index bd4620ad8..1b270b80b 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferTimedOrCountedSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferTimedOrCountedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,9 +20,9 @@ package monix.reactive.internal.operators import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.internal.Platform -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration._ -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object BufferTimedOrCountedSuite extends BaseOperatorSuite { val waitNext = 1.second @@ -57,7 +57,8 @@ object BufferTimedOrCountedSuite extends BaseOperatorSuite { Observable .intervalAtFixedRate(100.millis, 100.millis) .take(sourceCount.toLong), - ex) + ex + ) .bufferTimedAndCounted(1.second, maxCount = 20) .map(_.sum) @@ -142,7 +143,7 @@ object BufferTimedOrCountedSuite extends BaseOperatorSuite { assert(onNextReceived) p.success(Continue) s.tick(waitForNext) - + case _ => fail() } diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferTimedSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferTimedSuite.scala index 0df0a8c4a..32bee6ace 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferTimedSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferTimedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,12 +19,13 @@ package monix.reactive.internal.operators import monix.execution.{Ack, Scheduler} import monix.execution.Ack.Continue +import monix.execution.Scheduler import monix.execution.internal.Platform import monix.reactive.observers.Subscriber -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration._ -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.util.Success object BufferTimedSuite extends BaseOperatorSuite { @@ -59,7 +60,8 @@ object BufferTimedSuite extends BaseOperatorSuite { Observable .intervalAtFixedRate(100.millis, 100.millis) .take(sourceCount.toLong), - ex) + ex + ) .bufferTimed(1.second) .map(_.sum) diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferTumblingSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferTumblingSuite.scala index 79a9f7bfc..0f664878d 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferTumblingSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferTumblingSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,9 +21,9 @@ import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.internal.Platform import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration._ -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object BufferTumblingSuite extends BaseOperatorSuite { val waitNext = Duration.Zero diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferWhileInclusiveSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferWhileInclusiveSuite.scala index 8d588cf55..834f4d598 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferWhileInclusiveSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferWhileInclusiveSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,9 +21,9 @@ import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException import monix.execution.internal.Platform -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.concurrent.duration.Duration import scala.concurrent.duration._ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferWhileSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferWhileSuite.scala index 65e5985a4..73e3fcbdb 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferWhileSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferWhileSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,9 +21,9 @@ import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException import monix.execution.internal.Platform -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.concurrent.duration.Duration import scala.concurrent.duration._ import cats.laws._ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferWithSelectorSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferWithSelectorSuite.scala index 6fe2543d7..46bb48cb6 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferWithSelectorSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/BufferWithSelectorSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import monix.reactive.Observable import monix.execution.exceptions.DummyException import scala.concurrent.duration._ -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object BufferWithSelectorSuite extends BaseOperatorSuite { val waitNext = 1.second diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CacheSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CacheSuite.scala index 2a6b830d6..60c1b8b1d 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CacheSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CacheSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CollectSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CollectSuite.scala index a747b9b25..7579fc9ad 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CollectSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CollectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,10 +21,10 @@ import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.internal.Platform import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration._ -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object CollectSuite extends BaseOperatorSuite { val waitFirst = Duration.Zero diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CollectWhileSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CollectWhileSuite.scala index 815ddfd01..ddc7a0194 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CollectWhileSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CollectWhileSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,11 +22,11 @@ import cats.laws.discipline._ import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration._ import scala.concurrent.duration.Duration.Zero -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object CollectWhileSuite extends BaseOperatorSuite { def sum(sourceCount: Int): Long = diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest2Suite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest2Suite.scala index c48f63d42..2a3a1ba72 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest2Suite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest2Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException import monix.reactive.subjects.PublishSubject -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration._ object CombineLatest2Suite extends BaseOperatorSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest3Suite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest3Suite.scala index 79b0b3add..f164f537f 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest3Suite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest3Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest4Suite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest4Suite.scala index 123a60fd4..a0ec4cb10 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest4Suite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest4Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest5Suite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest5Suite.scala index e5772844d..734b92cc6 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest5Suite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest5Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest6Suite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest6Suite.scala index 43b5263f0..4ce396519 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest6Suite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatest6Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatestListSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatestListSuite.scala index 56f60d632..038902f8f 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatestListSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CombineLatestListSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,7 +30,7 @@ object CombineLatestListSuite extends BaseOperatorSuite { val source = Observable.range(0L, sourceCount.toLong) val sources = (1 to NumberOfObservables).map(_ => Observable.now(1L)) val o: Observable[Long] = - Observable.combineLatestList((sources :+ source): _*).map { seq => + Observable.combineLatestList((sources :+ source)*).map { seq => seq.sum } @@ -45,7 +45,7 @@ object CombineLatestListSuite extends BaseOperatorSuite { val sample1 = { val sources = (0 until NumberOfObservables).map(_ => Observable.range(0, 10).delayOnNext(1.second)) - Observable.combineLatestList(sources: _*).map { seq => + Observable.combineLatestList(sources*).map { seq => seq.sum } } diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatCancellationSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatCancellationSuite.scala index 62ad85994..1cc61796c 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatCancellationSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatCancellationSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.reactive.internal.operators import monix.eval.Task -import monix.reactive.{BaseTestSuite, Observable} +import monix.reactive.{ BaseTestSuite, Observable } import scala.concurrent.duration._ /** Tests for cancelling `concat` / `concatMap` and `mapTask`. */ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatDelayErrorsSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatDelayErrorsSuite.scala index 726458679..1f1700dff 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatDelayErrorsSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatDelayErrorsSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,8 +18,8 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue -import monix.execution.exceptions.{CompositeException, DummyException} -import monix.reactive.{BaseTestSuite, Observable, Observer} +import monix.execution.exceptions.{ CompositeException, DummyException } +import monix.reactive.{ BaseTestSuite, Observable, Observer } import scala.concurrent.Future object ConcatDelayErrorsSuite extends BaseTestSuite { @@ -28,7 +28,8 @@ object ConcatDelayErrorsSuite extends BaseTestSuite { .range(0, 100) .flatMapDelayErrors(x => Observable(x, x, x) - .endWithError(DummyException(x.toString))) + .endWithError(DummyException(x.toString)) + ) var result = 0L var errorThrown: Throwable = null diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatManySuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatManySuite.scala index fea10a60e..d190d62d8 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatManySuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatManySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.internal.operators import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.internal.Platform -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration._ object ConcatManySuite extends BaseOperatorSuite { @@ -71,7 +71,8 @@ object ConcatManySuite extends BaseOperatorSuite { Observable .range(0L, sourceCount.toLong) .map(_ => 1L) - .delayExecution(1.second)) + .delayExecution(1.second) + ) val count = Platform.recommendedBatchSize * 3 Seq(Sample(o, count, count, 1.seconds, 0.seconds)) diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatMapIterableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatMapIterableSuite.scala index 8593f429e..b4158b567 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatMapIterableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatMapIterableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,11 +22,11 @@ import cats.laws.discipline._ import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration.Duration.Zero import scala.concurrent.duration._ -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object ConcatMapIterableSuite extends BaseOperatorSuite { def sum(sourceCount: Int): Long = (1 to sourceCount).flatMap(i => List(i, i * 10)).sum.toLong diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatOneSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatOneSuite.scala index 42eb7eef4..e16ff8cc9 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatOneSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ConcatOneSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,15 +20,15 @@ package monix.reactive.internal.operators import monix.eval.Task import monix.execution.Ack.Continue import monix.execution.FutureUtils.extensions._ -import monix.execution.{Ack, Scheduler} -import monix.reactive.Observable.{empty, now} +import monix.execution.{ Ack, Scheduler } +import monix.reactive.Observable.{ empty, now } import monix.execution.exceptions.DummyException import monix.reactive.subjects.PublishSubject -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future import scala.concurrent.duration._ -import scala.util.{Failure, Random, Try} +import scala.util.{ Failure, Random, Try } object ConcatOneSuite extends BaseOperatorSuite { def createObservable(sourceCount: Int) = Some { @@ -100,7 +100,7 @@ object ConcatOneSuite extends BaseOperatorSuite { createObservable(sourceCount) match { case Some(Sample(obs, count, sum, _, _)) => obs.unsafeSubscribeFn(new Observer[Long] { - private[this] var sum = 0L + private var sum = 0L def onNext(elem: Long): Ack = { received += 1 @@ -134,7 +134,7 @@ object ConcatOneSuite extends BaseOperatorSuite { test("filterEval can be expressed in terms of flatMap") { implicit s => val obs1 = Observable.range(0, 100).filterEval(i => Task.pure(i % 2 == 0)) - val obs2 = Observable.range(0, 100).flatMap(x => if (x % 2 == 0) now(x) else empty) + val obs2 = Observable.range(0, 100).flatMap(x => if (x % 2 == 0) now(x) else empty) val lst1 = toList(obs1) val lst2 = toList(obs2) @@ -146,7 +146,7 @@ object ConcatOneSuite extends BaseOperatorSuite { test("filterEvalF can be expressed in terms of flatMap") { implicit s => val obs1 = Observable.range(0, 100).filterEvalF[Try](i => Try(i % 2 == 0)) - val obs2 = Observable.range(0, 100).flatMap(x => if (x % 2 == 0) now(x) else empty) + val obs2 = Observable.range(0, 100).flatMap(x => if (x % 2 == 0) now(x) else empty) val lst1 = toList(obs1) val lst2 = toList(obs2) diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CountSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CountSuite.scala index 1059efb1b..2d24fca65 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CountSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/CountSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DebounceFlattenSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DebounceFlattenSuite.scala index 92d960e46..c62365b21 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DebounceFlattenSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DebounceFlattenSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DebounceRepeatedSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DebounceRepeatedSuite.scala index f35ff629a..ce9efca70 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DebounceRepeatedSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DebounceRepeatedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DebounceSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DebounceSuite.scala index 8203fe108..a4b2b8b0d 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DebounceSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DebounceSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -39,7 +39,8 @@ object DebounceSuite extends BaseOperatorSuite { Observable .interval(2.seconds) .take(sourceCount.toLong), - ex) + ex + ) .debounce(1.second) val count = sourceCount - 1 diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayBySelectorSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayBySelectorSuite.scala index 8d9245ccc..5de0ea134 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayBySelectorSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayBySelectorSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayByTimespanSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayByTimespanSuite.scala index 4c8db1469..831f369aa 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayByTimespanSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayByTimespanSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayExecutionSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayExecutionSuite.scala index 35e777a2c..f4f06a00b 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayExecutionSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayExecutionSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future import scala.concurrent.duration._ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayExecutionWithSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayExecutionWithSuite.scala index 73dee390e..d690055a4 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayExecutionWithSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayExecutionWithSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import monix.eval.Task import scala.concurrent.Future diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayOnCompleteSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayOnCompleteSuite.scala index a742a785b..bdc81461e 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayOnCompleteSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DelayOnCompleteSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.operators import minitest.TestSuite import monix.execution.Ack.Continue -import monix.execution.{Ack, Scheduler} +import monix.execution.{ Ack, Scheduler } import monix.execution.schedulers.TestScheduler import monix.reactive.Observable import monix.reactive.observers.Subscriber diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DematerializeSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DematerializeSuite.scala index bc755d2c4..7174438e6 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DematerializeSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DematerializeSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.internal.operators import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future import scala.concurrent.duration._ import scala.concurrent.duration.Duration.Zero diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DistinctUntilChangedByKeySuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DistinctUntilChangedByKeySuite.scala index 2d058a266..4944d7364 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DistinctUntilChangedByKeySuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DistinctUntilChangedByKeySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DistinctUntilChangedSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DistinctUntilChangedSuite.scala index d0df20f59..4ea60b0af 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DistinctUntilChangedSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DistinctUntilChangedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnCompleteSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnCompleteSuite.scala index c770d7d7d..3d9863ae1 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnCompleteSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnCompleteSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnEarlyStopSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnEarlyStopSuite.scala index d910f7239..bcea6121f 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnEarlyStopSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnEarlyStopSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import cats.effect.IO import minitest.TestSuite import monix.eval.Task import monix.execution.Ack -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.schedulers.TestScheduler import monix.reactive.Observable import monix.execution.exceptions.DummyException diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnErrorSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnErrorSuite.scala index 5658132db..229d9550e 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnErrorSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnErrorSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnNextAckSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnNextAckSuite.scala index ac88b0b1a..b835c410d 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnNextAckSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnNextAckSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnNextSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnNextSuite.scala index ba6fd02cd..fefb8039c 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnNextSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnNextSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnStartSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnStartSuite.scala index 8b8a254cf..e060c17c4 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnStartSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnStartSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnSubscribeSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnSubscribeSuite.scala index d2f5b05b3..25144d831 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnSubscribeSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnSubscribeSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,12 +17,12 @@ package monix.reactive.internal.operators -import cats.effect.{ExitCase, IO} +import cats.effect.{ ExitCase, IO } import minitest.TestSuite import monix.eval.Task import monix.execution.Ack.Continue import monix.execution.schedulers.TestScheduler -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import monix.execution.exceptions.DummyException object DoOnSubscribeSuite extends TestSuite[TestScheduler] { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnSubscriptionCancelSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnSubscriptionCancelSuite.scala index d390ceee8..1b8a9c040 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnSubscriptionCancelSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DoOnSubscriptionCancelSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropByPredicateInclusiveSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropByPredicateInclusiveSuite.scala index 8b2ad50a1..eaf18096d 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropByPredicateInclusiveSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropByPredicateInclusiveSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropByPredicateSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropByPredicateSuite.scala index 7efda5c44..e2351871e 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropByPredicateSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropByPredicateSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropByPredicateWithIndexSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropByPredicateWithIndexSuite.scala index 6e6ffe349..ad274b0f1 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropByPredicateWithIndexSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropByPredicateWithIndexSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropByTimespanSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropByTimespanSuite.scala index f5e2519fb..fe2b6b323 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropByTimespanSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropByTimespanSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropFirstSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropFirstSuite.scala index 8f17b3b35..fd0bcb5ec 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropFirstSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropFirstSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropLastSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropLastSuite.scala index 025c5135a..4d9a273d8 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropLastSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropLastSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropUntilSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropUntilSuite.scala index 7f28f4c1c..1cb206e3c 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropUntilSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DropUntilSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import monix.eval.Task import scala.concurrent.duration._ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DumpSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DumpSuite.scala index faf3e338c..8c4502e2b 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DumpSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/DumpSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.reactive.internal.operators -import java.io.{OutputStream, PrintStream} +import java.io.{ OutputStream, PrintStream } import monix.reactive.Observable import monix.execution.exceptions.DummyException diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/EchoRepeatedSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/EchoRepeatedSuite.scala index 45965381b..bae29dadf 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/EchoRepeatedSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/EchoRepeatedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.FutureUtils.extensions._ import monix.reactive.subjects.PublishSubject -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future import scala.concurrent.duration._ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/EndWithErrorSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/EndWithErrorSuite.scala index 180449d4e..a1a94fdfa 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/EndWithErrorSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/EndWithErrorSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import minitest.TestSuite import monix.execution.Ack.Continue import monix.execution.schedulers.TestScheduler import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Promise object EndWithErrorSuite extends TestSuite[TestScheduler] { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ExecuteOnObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ExecuteOnObservableSuite.scala index e8a9f5859..4d14b83c8 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ExecuteOnObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ExecuteOnObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,8 +21,8 @@ import minitest.TestSuite import monix.execution.Ack import monix.execution.Ack.Stop import monix.execution.schedulers.TestScheduler -import monix.reactive.{Observable, Observer} -import scala.concurrent.{Future, Promise} +import monix.reactive.{ Observable, Observer } +import scala.concurrent.{ Future, Promise } import scala.util.Success object ExecuteOnObservableSuite extends TestSuite[TestScheduler] { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ExecuteOnSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ExecuteOnSuite.scala index 07756e3c7..a325fe9e2 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ExecuteOnSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ExecuteOnSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.internal.operators import minitest.TestSuite import monix.eval.Task import monix.execution.Ack.Continue -import monix.execution.{Ack, Scheduler} +import monix.execution.{ Ack, Scheduler } import monix.execution.schedulers.TestScheduler import monix.reactive.Observable import monix.reactive.OverflowStrategy.Unbounded diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FilterNotSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FilterNotSuite.scala index 91407b954..0e6ab3b91 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FilterNotSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FilterNotSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,11 +20,11 @@ package monix.reactive.internal.operators import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration.Duration.Zero import scala.concurrent.duration._ -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object FilterNotSuite extends BaseOperatorSuite { def count(sourceCount: Int) = { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FilterSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FilterSuite.scala index 620043e12..7175d20e9 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FilterSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FilterSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,11 +20,11 @@ package monix.reactive.internal.operators import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration._ import scala.concurrent.duration.Duration.Zero -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.util.Success object FilterSuite extends BaseOperatorSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FlatScanDelayErrorSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FlatScanDelayErrorSuite.scala index 8352b6802..03770b31f 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FlatScanDelayErrorSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FlatScanDelayErrorSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.internal.operators import cats.laws._ import cats.laws.discipline._ import monix.eval.Task -import monix.execution.exceptions.{CompositeException, DummyException} +import monix.execution.exceptions.{ CompositeException, DummyException } import monix.reactive.Observable import scala.concurrent.duration._ import scala.concurrent.duration.Duration._ @@ -38,7 +38,8 @@ object FlatScanDelayErrorSuite extends BaseOperatorSuite { Observable .repeat(acc + elem) .take(3L) - .endWithError(SomeException(10))) + .endWithError(SomeException(10)) + ) val recovered = o.onErrorHandleWith { case composite: CompositeException => diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FlatScanSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FlatScanSuite.scala index 5a012b2d3..f2b171be2 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FlatScanSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FlatScanSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FoldLeftObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FoldLeftObservableSuite.scala index 625f21468..fe34048e4 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FoldLeftObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FoldLeftObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FoldWhileObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FoldWhileObservableSuite.scala index 8a2265484..13d89ab74 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FoldWhileObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/FoldWhileObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,7 +26,9 @@ object FoldWhileObservableSuite extends BaseOperatorSuite { def createObservable(sourceCount: Int) = Some { val n = sourceCount / 2 val obs = - Observable.range(0L, sourceCount.toLong).foldWhileLeft(0L)((acc, e) => if (e < n) Left(acc + e) else Right(acc + e)) + Observable.range(0L, sourceCount.toLong).foldWhileLeft(0L)((acc, e) => + if (e < n) Left(acc + e) else Right(acc + e) + ) Sample(obs, 1, n * (n + 1) / 2, 0.seconds, 0.seconds) } diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/GroupBySuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/GroupBySuite.scala index 5dcb76d63..1856b15e9 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/GroupBySuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/GroupBySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,9 +19,9 @@ package monix.reactive.internal.operators import monix.eval.Task import monix.execution.Ack -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.reactive.subjects.PublishSubject -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future import scala.concurrent.duration.Duration.Zero import scala.concurrent.duration._ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/GuaranteeCaseSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/GuaranteeCaseSuite.scala index a28cd2515..2cc26dfae 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/GuaranteeCaseSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/GuaranteeCaseSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,14 +17,14 @@ package monix.reactive.internal.operators -import cats.effect.{ExitCase, IO} +import cats.effect.{ ExitCase, IO } import minitest.TestSuite import monix.eval.Task import monix.execution.Ack -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.schedulers.TestScheduler import monix.reactive.Observable -import monix.execution.exceptions.{CompositeException, DummyException} +import monix.execution.exceptions.{ CompositeException, DummyException } import monix.execution.internal.Platform import monix.execution.internal.exceptions.matchError import monix.reactive.observers.Subscriber diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Interleave2Suite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Interleave2Suite.scala index 689d44a56..d6b8dadcf 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Interleave2Suite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Interleave2Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import monix.execution.Ack.Continue import monix.execution.FutureUtils.extensions._ import monix.execution.exceptions.DummyException import monix.reactive.subjects.PublishSubject -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future import scala.concurrent.duration.Duration.Zero import scala.concurrent.duration._ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/IntersperseSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/IntersperseSuite.scala index 3f976331c..cb5245faf 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/IntersperseSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/IntersperseSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue import monix.reactive.subjects.PublishSubject -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration._ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapAccumulateSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapAccumulateSuite.scala index bcdabbb6e..870635303 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapAccumulateSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapAccumulateSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapEffectSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapEffectSuite.scala index 908f9f27b..805a9d132 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapEffectSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapEffectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapParallelOrderedSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapParallelOrderedSuite.scala index 81557d88c..ac77788a3 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapParallelOrderedSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapParallelOrderedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,11 +24,11 @@ import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException import monix.execution.internal.Platform -import monix.reactive.{Observable, Observer, OverflowStrategy} +import monix.reactive.{ Observable, Observer, OverflowStrategy } -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.concurrent.duration._ -import scala.util.{Failure, Random} +import scala.util.{ Failure, Random } object MapParallelOrderedSuite extends BaseOperatorSuite { @@ -96,7 +96,8 @@ object MapParallelOrderedSuite extends BaseOperatorSuite { Task { counter += 1 x - }.delayExecution(1.second)) + }.delayExecution(1.second) + ) .toListL .runToFuture @@ -114,7 +115,7 @@ object MapParallelOrderedSuite extends BaseOperatorSuite { val obs = Observable.range(0L, sourceCount.toLong).mapParallelOrdered(parallelism = 4)(x => Task.now(x)) obs.unsafeSubscribeFn(new Observer[Long] { - private[this] var sum = 0L + private var sum = 0L def onNext(elem: Long) = { received += 1 @@ -144,7 +145,7 @@ object MapParallelOrderedSuite extends BaseOperatorSuite { val obs = Observable.range(0L, sourceCount.toLong).mapParallelOrdered(parallelism = 4)(x => Task(x)) obs.unsafeSubscribeFn(new Observer[Long] { - private[this] var sum = 0L + private var sum = 0L def onNext(elem: Long) = { received += 1 @@ -306,7 +307,7 @@ object MapParallelOrderedSuite extends BaseOperatorSuite { val p = Promise[Int]() val tasks = List.fill(8)(Task.fromFuture(p.future)) - Observable(tasks: _*) + Observable(tasks*) .doOnNext(_ => Task(initiated += 1)) .mapParallelOrdered(parallelism = 4)(x => x) .unsafeSubscribeFn(new Observer[Int] { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapParallelUnorderedSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapParallelUnorderedSuite.scala index 77e64e38c..e72f474d1 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapParallelUnorderedSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapParallelUnorderedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,11 +24,11 @@ import monix.eval.Task import monix.execution.Ack.Continue import monix.execution.internal.Platform import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer, OverflowStrategy} +import monix.reactive.{ Observable, Observer, OverflowStrategy } import scala.concurrent.Promise import scala.concurrent.duration._ -import scala.util.{Failure, Random} +import scala.util.{ Failure, Random } object MapParallelUnorderedSuite extends BaseOperatorSuite { def createObservable(sourceCount: Int) = Some { @@ -73,7 +73,7 @@ object MapParallelUnorderedSuite extends BaseOperatorSuite { val obs = Observable.range(0L, sourceCount.toLong).mapParallelUnordered(parallelism = 4)(x => Task.now(x)) obs.unsafeSubscribeFn(new Observer[Long] { - private[this] var sum = 0L + private var sum = 0L def onNext(elem: Long) = { received += 1 @@ -102,7 +102,7 @@ object MapParallelUnorderedSuite extends BaseOperatorSuite { val obs = Observable.range(0L, sourceCount.toLong).mapParallelUnordered(parallelism = 4)(x => Task.evalAsync(x)) obs.unsafeSubscribeFn(new Observer[Long] { - private[this] var sum = 0L + private var sum = 0L def onNext(elem: Long) = { received += 1 @@ -263,7 +263,7 @@ object MapParallelUnorderedSuite extends BaseOperatorSuite { val p = Promise[Int]() val tasks = List.fill(8)(Task.fromFuture(p.future)) - Observable(tasks: _*) + Observable(tasks*) .doOnNext(_ => Task { initiated += 1 }) .mapParallelUnordered(parallelism = 4)(x => x) .unsafeSubscribeFn(new Observer[Int] { @@ -335,7 +335,8 @@ object MapParallelUnorderedSuite extends BaseOperatorSuite { .range(0, totalCount.toLong) .doOnNext(_ => Task { initiated += 1 }) .mapParallelUnordered(parallelism = 4)(x => Task.evalAsync(x))( - OverflowStrategy.DropNew(Platform.recommendedBatchSize)) + OverflowStrategy.DropNew(Platform.recommendedBatchSize) + ) .unsafeSubscribeFn(new Observer[Long] { def onNext(elem: Long) = { received += 1 diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapSuite.scala index 9813dd8cd..3a0a185f7 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,10 +20,10 @@ package monix.reactive.internal.operators import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration.Duration.Zero -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.concurrent.duration._ object MapSuite extends BaseOperatorSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapTaskSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapTaskSuite.scala index bb55d6b93..2ca374a1a 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapTaskSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MapTaskSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,12 +25,12 @@ import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.FutureUtils.extensions._ import monix.execution.Scheduler -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import monix.execution.exceptions.DummyException import scala.concurrent.duration._ -import scala.concurrent.{Future, Promise} -import scala.util.{Failure, Random} +import scala.concurrent.{ Future, Promise } +import scala.util.{ Failure, Random } object MapTaskSuite extends BaseOperatorSuite { def createObservable(sourceCount: Int) = Some { @@ -98,7 +98,7 @@ object MapTaskSuite extends BaseOperatorSuite { val obs = Observable.range(0L, sourceCount.toLong).mapEval(x => Task.now(x)) obs.unsafeSubscribeFn(new Observer[Long] { - private[this] var sum = 0L + private var sum = 0L def onNext(elem: Long): Ack = { received += 1 @@ -121,7 +121,7 @@ object MapTaskSuite extends BaseOperatorSuite { val obs = Observable.range(0L, sourceCount.toLong).mapEval(x => Task.evalAsync(x)) obs.unsafeSubscribeFn(new Observer[Long] { - private[this] var sum = 0L + private var sum = 0L def onNext(elem: Long): Ack = { received += 1 diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MaterializeSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MaterializeSuite.scala index e9ce02aa8..c4a727d12 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MaterializeSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MaterializeSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,9 +19,9 @@ package monix.reactive.internal.operators import monix.execution.Ack import monix.execution.Ack.Continue -import monix.reactive.Notification.{OnComplete, OnError, OnNext} +import monix.reactive.Notification.{ OnComplete, OnError, OnNext } import monix.execution.exceptions.DummyException -import monix.reactive.{Notification, Observable, Observer} +import monix.reactive.{ Notification, Observable, Observer } import scala.concurrent.Future import scala.concurrent.duration._ import scala.concurrent.duration.Duration.Zero diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MaxBySuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MaxBySuite.scala index 65d03356a..aec9fd268 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MaxBySuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MaxBySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration.Duration.Zero object MaxBySuite extends BaseOperatorSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MaxSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MaxSuite.scala index a33048a6f..dfb46a140 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MaxSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MaxSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration.Duration.Zero object MaxSuite extends BaseOperatorSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergeDelayErrorManySuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergeDelayErrorManySuite.scala index 854320d65..ae8312fcc 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergeDelayErrorManySuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergeDelayErrorManySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue import monix.execution.exceptions.CompositeException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration._ import scala.util.Random diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergeDelayErrorOneSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergeDelayErrorOneSuite.scala index b76e9ed1b..6463ce2cb 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergeDelayErrorOneSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergeDelayErrorOneSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue import monix.execution.exceptions.CompositeException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration._ import scala.util.Random diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergeManySuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergeManySuite.scala index 0befb8190..b8e48aa4d 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergeManySuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergeManySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.operators import monix.execution.Ack import monix.execution.Ack.Continue -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration._ import scala.concurrent.duration.Duration.Zero diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergeOneSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergeOneSuite.scala index c315fa73f..43bf15162 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergeOneSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergeOneSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,10 +21,10 @@ import monix.eval.Task import monix.execution.Ack.Continue import monix.execution.FutureUtils.extensions._ import monix.execution.Scheduler -import monix.reactive.Observable.{empty, now} +import monix.reactive.Observable.{ empty, now } import monix.execution.exceptions.DummyException import monix.reactive.subjects.PublishSubject -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future import scala.concurrent.duration.Duration.Zero diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergePrioritizedListSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergePrioritizedListSuite.scala index 2726f8e3a..0abefb0a4 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergePrioritizedListSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MergePrioritizedListSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,10 +18,10 @@ package monix.reactive.internal.operators import monix.eval.Task -import monix.execution.{Ack, Cancelable, Scheduler} -import monix.execution.Ack.{Continue, Stop} +import monix.execution.{ Ack, Cancelable, Scheduler } +import monix.execution.Ack.{ Continue, Stop } import monix.reactive.observers.Subscriber -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future import scala.concurrent.duration.Duration.Zero @@ -31,7 +31,7 @@ object MergePrioritizedListSuite extends BaseOperatorSuite { def createObservable(sourceCount: Int) = Some { val sources = (1 to sourceCount).map(i => (i, Observable.fromIterable(Seq.fill(4)(i.toLong)))) - val o = Observable.mergePrioritizedList(sources: _*) + val o = Observable.mergePrioritizedList(sources*) Sample(o, count(sourceCount), sum(sourceCount), Zero, Zero) } @@ -51,7 +51,7 @@ object MergePrioritizedListSuite extends BaseOperatorSuite { override def cancelableObservables(): Seq[Sample] = { val sources1 = (1 to 100).map(i => (i, Observable.range(0, 100).delayExecution(2.second))) - val sample1 = Observable.mergePrioritizedList(sources1: _*) + val sample1 = Observable.mergePrioritizedList(sources1*) Seq( Sample(sample1, 0, 0, 0.seconds, 0.seconds), Sample(sample1, 0, 0, 1.seconds, 0.seconds) @@ -64,7 +64,7 @@ object MergePrioritizedListSuite extends BaseOperatorSuite { test("should pick items in priority order") { implicit s => val sources = (1 to 10).map(i => (i, Observable.now(i * 1L))) - val source = Observable.mergePrioritizedList(sources: _*) + val source = Observable.mergePrioritizedList(sources*) var last = 0L source.unsafeSubscribeFn(new Observer[Long] { def onNext(elem: Long): Future[Ack] = { @@ -116,7 +116,7 @@ object MergePrioritizedListSuite extends BaseOperatorSuite { test("should complete all upstream onNext promises when downstream stops early") { implicit s => val sources = (1 to 10).map(i => (i, new OnNextExposingObservable(i * 1L))) - val source = Observable.mergePrioritizedList(sources: _*) + val source = Observable.mergePrioritizedList(sources*) source.unsafeSubscribeFn(new Observer[Long] { def onNext(elem: Long): Future[Ack] = { @@ -137,7 +137,7 @@ object MergePrioritizedListSuite extends BaseOperatorSuite { test("should complete all upstream onNext promises when downstream errors early") { implicit s => val sources = (1 to 10).map(i => (i, new OnNextExposingObservable(i * 1L))) - val source = Observable.mergePrioritizedList(sources: _*) + val source = Observable.mergePrioritizedList(sources*) source.unsafeSubscribeFn(new Observer[Long] { def onNext(elem: Long): Future[Ack] = { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MinBySuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MinBySuite.scala index 3eb2f2265..3cf6b2348 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MinBySuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MinBySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration.Duration.Zero object MinBySuite extends BaseOperatorSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MinSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MinSuite.scala index 0439896b5..1aee0ac33 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MinSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MinSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration.Duration.Zero object MinSuite extends BaseOperatorSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscCompleteSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscCompleteSuite.scala index d07b4aab6..84d751675 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscCompleteSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscCompleteSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import minitest.TestSuite import monix.execution.Ack.Continue import monix.execution.schedulers.TestScheduler import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } object MiscCompleteSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscDefaultIfEmptySuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscDefaultIfEmptySuite.scala index 64fb9b235..b566df0d6 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscDefaultIfEmptySuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscDefaultIfEmptySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration._ import scala.concurrent.duration.Duration.Zero diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscFailedSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscFailedSuite.scala index 0e2198e13..64ad9f46b 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscFailedSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscFailedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import minitest.TestSuite import monix.execution.Ack.Continue import monix.execution.schedulers.TestScheduler import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Promise object MiscFailedSuite extends TestSuite[TestScheduler] { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscIsEmptySuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscIsEmptySuite.scala index f0d84ad54..2a9ff817e 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscIsEmptySuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscIsEmptySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscNonEmptySuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscNonEmptySuite.scala index 0bfd8995d..a991095f0 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscNonEmptySuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/MiscNonEmptySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ObservableOpsReturningTaskSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ObservableOpsReturningTaskSuite.scala index 3bf35c4d7..7ee473e7f 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ObservableOpsReturningTaskSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ObservableOpsReturningTaskSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,9 +24,9 @@ import monix.execution.Ack.Stop import monix.execution.FutureUtils.extensions._ import monix.execution.Scheduler import monix.execution.atomic.Atomic -import monix.reactive.{BaseTestSuite, Observable, Observer} -import scala.concurrent.{Future, Promise} -import scala.util.{Success, Try} +import monix.reactive.{ BaseTestSuite, Observable, Observer } +import scala.concurrent.{ Future, Promise } +import scala.util.{ Success, Try } object ObservableOpsReturningTaskSuite extends BaseTestSuite { def first[A](obs: Observable[A])(implicit s: Scheduler): Future[Try[Option[A]]] = { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ObserveOnSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ObserveOnSuite.scala index b6ef8ea95..5e53524e5 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ObserveOnSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ObserveOnSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,7 +24,7 @@ import monix.execution.exceptions.DummyException import monix.execution.internal.Platform import monix.execution.schedulers.TestScheduler import monix.reactive.OverflowStrategy.Unbounded -import monix.reactive.{BaseTestSuite, Observable} +import monix.reactive.{ BaseTestSuite, Observable } object ObserveOnSuite extends BaseTestSuite { test("equivalence with the source") { implicit s => diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnCancelTriggerErrorSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnCancelTriggerErrorSuite.scala index f1e81a919..71389b367 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnCancelTriggerErrorSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnCancelTriggerErrorSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,11 +18,11 @@ package monix.reactive.internal.operators import minitest.TestSuite -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.schedulers.TestScheduler import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} -import scala.concurrent.{CancellationException, Future} +import monix.reactive.{ Observable, Observer } +import scala.concurrent.{ CancellationException, Future } import scala.concurrent.duration._ object OnCancelTriggerErrorSuite extends TestSuite[TestScheduler] { @@ -46,7 +46,8 @@ object OnCancelTriggerErrorSuite extends TestSuite[TestScheduler] { assertEquals(effect, 0) assert( errorThrow != null && errorThrow.isInstanceOf[CancellationException], - "errorThrow should be CancellationException") + "errorThrow should be CancellationException" + ) } test("cannot cancel after complete") { implicit s => diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorFallbackToSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorFallbackToSuite.scala index 60baf00c4..da1018a2a 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorFallbackToSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorFallbackToSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorRecoverWithSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorRecoverWithSuite.scala index 04c5acf1d..4f20b9d2a 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorRecoverWithSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorRecoverWithSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorRetryCountedSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorRetryCountedSuite.scala index dd29989b1..37b07aa8f 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorRetryCountedSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorRetryCountedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.operators import monix.reactive.Observable import monix.execution.exceptions.DummyException -import scala.concurrent.duration.{Duration, _} +import scala.concurrent.duration.{ Duration, _ } object OnErrorRetryCountedSuite extends BaseOperatorSuite { def createObservable(sourceCount: Int) = Some { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorRetryIfSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorRetryIfSuite.scala index 96921b797..a9b627989 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorRetryIfSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorRetryIfSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.internal.operators import monix.reactive.Observable import monix.execution.atomic.Atomic import monix.execution.exceptions.DummyException -import scala.concurrent.duration.{Duration, _} +import scala.concurrent.duration.{ Duration, _ } object OnErrorRetryIfSuite extends BaseOperatorSuite { def createObservable(sourceCount: Int) = Some { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorRetryUnlimitedSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorRetryUnlimitedSuite.scala index ae442e40e..b68010857 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorRetryUnlimitedSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/OnErrorRetryUnlimitedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/PipeThroughSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/PipeThroughSuite.scala index 92e87088e..2e3a53154 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/PipeThroughSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/PipeThroughSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.reactive.internal.operators import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Pipe} +import monix.reactive.{ Observable, Pipe } import scala.concurrent.duration.Duration.Zero import scala.concurrent.duration._ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/PublishSelectorSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/PublishSelectorSuite.scala index c3c75ba6b..b61d1db10 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/PublishSelectorSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/PublishSelectorSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.operators import cats.effect.IO import monix.execution.atomic.Atomic -import monix.reactive.{BaseTestSuite, Observable, OverflowStrategy} +import monix.reactive.{ BaseTestSuite, Observable, OverflowStrategy } import scala.util.Success object PublishSelectorSuite extends BaseTestSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/RecursiveConcatSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/RecursiveConcatSuite.scala index d28b7d938..37c931ffd 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/RecursiveConcatSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/RecursiveConcatSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/RecursiveConsSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/RecursiveConsSuite.scala index a4b74208b..ba2be2ced 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/RecursiveConsSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/RecursiveConsSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ReduceSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ReduceSuite.scala index 2704e7069..fac34efa9 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ReduceSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ReduceSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/RepeatSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/RepeatSuite.scala index df56b7326..a1eea2450 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/RepeatSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/RepeatSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SampleOnceSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SampleOnceSuite.scala index 142ff33b3..36d3dd184 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SampleOnceSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SampleOnceSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue import monix.execution.FutureUtils.extensions._ import monix.reactive.subjects.PublishSubject -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future import scala.concurrent.duration._ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SampleRepeatedSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SampleRepeatedSuite.scala index f115fb7d4..f8abf55a0 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SampleRepeatedSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SampleRepeatedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ScanEffectSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ScanEffectSuite.scala index 65a8f2e03..d97e94c3c 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ScanEffectSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ScanEffectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ScanMapSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ScanMapSuite.scala index 306f9d2fd..d2b4fa02a 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ScanMapSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ScanMapSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import cats.Monoid import cats.laws._ import cats.laws.discipline._ import monix.eval.Task -import monix.reactive.{BaseTestSuite, Observable} +import monix.reactive.{ BaseTestSuite, Observable } object ScanMapSuite extends BaseTestSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ScanSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ScanSuite.scala index f5ab2dbfe..63e4ae6e5 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ScanSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ScanSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ScanTaskSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ScanTaskSuite.scala index 24ba339fd..e72c34851 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ScanTaskSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ScanTaskSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -208,9 +208,7 @@ object ScanTaskSuite extends BaseOperatorSuite { test("error in task after user cancelled") { implicit s => def delay[A](ex: Throwable): Task[A] = Task.async0 { (sc, cb) => - sc.scheduleOnce(1, TimeUnit.SECONDS, new Runnable { - def run() = cb.onError(ex) - }) + sc.scheduleOnce(1, TimeUnit.SECONDS, () => cb.onError(ex)) () } diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SumSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SumSuite.scala index e65674a22..ebbbb83bd 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SumSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SumSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SwitchIfEmptySuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SwitchIfEmptySuite.scala index 89ac98ffc..a4b2cdb25 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SwitchIfEmptySuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SwitchIfEmptySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SwitchMapSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SwitchMapSuite.scala index 6fcf28e6e..d52239224 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SwitchMapSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/SwitchMapSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeByPredicateInclusiveSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeByPredicateInclusiveSuite.scala index 0697efa7a..f48b4167b 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeByPredicateInclusiveSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeByPredicateInclusiveSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,11 +20,11 @@ package monix.reactive.internal.operators import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration._ import scala.concurrent.duration.Duration.Zero -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object TakeByPredicateInclusiveSuite extends BaseOperatorSuite { def sum(sourceCount: Int): Long = diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeByPredicateSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeByPredicateSuite.scala index 992e425ea..60cd25d58 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeByPredicateSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeByPredicateSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,10 +20,10 @@ package monix.reactive.internal.operators import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration._ import scala.concurrent.duration.Duration.Zero -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object TakeByPredicateSuite extends BaseOperatorSuite { def sum(sourceCount: Int): Long = diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeByTimespanSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeByTimespanSuite.scala index 986b14310..08e0117d4 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeByTimespanSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeByTimespanSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,9 @@ package monix.reactive.internal.operators -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.FutureUtils.extensions._ -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future import scala.concurrent.duration._ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeEveryNthOperatorSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeEveryNthOperatorSuite.scala index 13bb780d6..2b7ea8eb1 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeEveryNthOperatorSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeEveryNthOperatorSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeLastSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeLastSuite.scala index cb1e99647..604e06727 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeLastSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeLastSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeLeftSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeLeftSuite.scala index 24c9fe971..59f98f94f 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeLeftSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeLeftSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,10 +19,10 @@ package monix.reactive.internal.operators import monix.execution.Ack import monix.execution.Ack.Continue -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.duration._ import scala.concurrent.duration.Duration.Zero -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object TakeLeftSuite extends BaseOperatorSuite { def sum(sourceCount: Int): Long = sourceCount.toLong * (sourceCount + 1) / 2 diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeUntilObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeUntilObservableSuite.scala index ba33f8375..ead9544a5 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeUntilObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeUntilObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,11 +19,11 @@ package monix.reactive.internal.operators import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Task, TaskLike} +import monix.eval.{ Task, TaskLike } import monix.reactive.Observable import concurrent.duration._ -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.util.Success object TakeUntilObservableSuite extends BaseOperatorSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeWhileNotCanceledSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeWhileNotCanceledSuite.scala index bb6764104..4eeb66448 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeWhileNotCanceledSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TakeWhileNotCanceledSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -38,7 +38,8 @@ object TakeWhileNotCanceledSuite extends BaseOperatorSuite { if (sourceCount == 1) Observable.range(1, 10).takeWhileNotCanceled(c).map { x => c.cancel(); x - } else + } + else Observable.range(1L, sourceCount.toLong * 2).takeWhileNotCanceled(c).map { x => if (x == sourceCount) c.cancel(); x } diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ThrottleFirstSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ThrottleFirstSuite.scala index 7435093ab..13164c19b 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ThrottleFirstSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ThrottleFirstSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ThrottleLatestSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ThrottleLatestSuite.scala index c6e4ea4e0..b2ea1dcf9 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ThrottleLatestSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ThrottleLatestSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue import monix.reactive.subjects.PublishSubject -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import monix.execution.FutureUtils.extensions._ import scala.collection.mutable.ArrayBuffer @@ -27,8 +27,8 @@ import scala.concurrent.Future import scala.concurrent.duration._ object ThrottleLatestSuite extends BaseOperatorSuite { - def count(sourceCount: Int):Int = { - sourceCount/2 + def count(sourceCount: Int): Int = { + sourceCount / 2 } def sum(sourceCount: Int): Int = { @@ -37,7 +37,7 @@ object ThrottleLatestSuite extends BaseOperatorSuite { def createObservable(sourceCount: Int) = Some { val elemsToTake = sourceCount.toLong - 1 - val o:Observable[Long] = { + val o: Observable[Long] = { Observable(1L).delayOnComplete(100.millisecond) ++ Observable.intervalAtFixedRate(500.millisecond).take(elemsToTake) } @@ -57,13 +57,15 @@ object ThrottleLatestSuite extends BaseOperatorSuite { } test("should emit last element onComplete if emitLast is set to true") { implicit s => - val source: Observable[Long] = Observable.intervalAtFixedRate(110.millisecond).take(30).throttleLatest(1.second, true) + val source: Observable[Long] = + Observable.intervalAtFixedRate(110.millisecond).take(30).throttleLatest(1.second, true) var wasCompleted = false val elements = ArrayBuffer[Long]() source.unsafeSubscribeFn(new Observer[Long] { def onNext(elem: Long) = { elements.append(elem) - Continue } + Continue + } def onError(ex: Throwable) = () def onComplete() = { wasCompleted = true } }) @@ -74,13 +76,15 @@ object ThrottleLatestSuite extends BaseOperatorSuite { } test("should not emit last element onComplete if emitLast is set to false") { implicit s => - val source: Observable[Long] = Observable.intervalAtFixedRate(110.millisecond).take(30).throttleLatest(1.second, false) + val source: Observable[Long] = + Observable.intervalAtFixedRate(110.millisecond).take(30).throttleLatest(1.second, false) var wasCompleted = false val elements = ArrayBuffer[Long]() source.unsafeSubscribeFn(new Observer[Long] { def onNext(elem: Long) = { elements.append(elem) - Continue } + Continue + } def onError(ex: Throwable) = () def onComplete() = { wasCompleted = true } }) diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ThrottleSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ThrottleSuite.scala index e6f12f14e..8f9ad0a3b 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ThrottleSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ThrottleSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TimeoutOnSlowDownstreamSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TimeoutOnSlowDownstreamSuite.scala index ecd9ea785..f05780a04 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TimeoutOnSlowDownstreamSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TimeoutOnSlowDownstreamSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TimeoutOnSlowUpstreamSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TimeoutOnSlowUpstreamSuite.scala index de59c4ec7..d9604f877 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TimeoutOnSlowUpstreamSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TimeoutOnSlowUpstreamSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.operators import monix.execution.Ack.Continue import monix.execution.exceptions.UpstreamTimeoutException -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import monix.execution.exceptions.DummyException import monix.reactive.subjects.PublishSubject import scala.concurrent.TimeoutException @@ -83,6 +83,7 @@ object TimeoutOnSlowUpstreamSuite extends BaseOperatorSuite { s.tick(1.second) assert( errorThrown != null && errorThrown.isInstanceOf[TimeoutException], - "errorThrown should be a TimeoutException") + "errorThrown should be a TimeoutException" + ) } } diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TransformerSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TransformerSuite.scala index 455d53756..48575b011 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TransformerSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/TransformerSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,9 +34,9 @@ object TransformerSuite extends BaseOperatorSuite { def createObservable(sourceCount: Int) = Some { val o = - Observable - .range(0L, sourceCount.toLong) - .transform(dummyTransformer) + Observable + .range(0L, sourceCount.toLong) + .transform(dummyTransformer) Sample(o, count(sourceCount), sum(sourceCount), Zero, Zero) } @@ -50,7 +50,7 @@ object TransformerSuite extends BaseOperatorSuite { createObservableEndingInError(Observable.now(1L), ex).transform(dummyTransformer) else createObservableEndingInError(Observable.range(1, sourceCount.toLong + 1, 1), ex) - .transform(dummyTransformer) + .transform(dummyTransformer) Sample(o, count(sourceCount), sum(sourceCount), Zero, Zero) } diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/UncancelableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/UncancelableSuite.scala index aac69cc32..1d316beff 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/UncancelableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/UncancelableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.internal.operators import monix.eval.Task import monix.execution.internal.Platform -import monix.reactive.{BaseTestSuite, Observable} +import monix.reactive.{ BaseTestSuite, Observable } import concurrent.duration._ import scala.util.Success diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WhileBusyAggregateEventsOperatorSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WhileBusyAggregateEventsOperatorSuite.scala index d69d613d6..f529d156e 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WhileBusyAggregateEventsOperatorSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WhileBusyAggregateEventsOperatorSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -68,14 +68,15 @@ object WhileBusyAggregateEventsOperatorSuite extends BaseOperatorSuite { require(sourceCount > 0, "sourceCount should be strictly positive") val o = Observable - .range(0, sourceCount.toLong) - .whileBusyAggregateEvents{ elem => - if (sourceCount == 1) throw ex else elem - }{ case (acc, elem) => + .range(0, sourceCount.toLong) + .whileBusyAggregateEvents { elem => + if (sourceCount == 1) throw ex else elem + } { + case (acc, elem) => if (elem == sourceCount - 1) throw ex else elem + acc - } - .throttle(waitNext, 1) + } + .throttle(waitNext, 1) Sample(o, 0, 0, waitNext, waitNext) } @@ -119,7 +120,7 @@ object WhileBusyAggregateEventsOperatorSuite extends BaseOperatorSuite { s.tick(10.seconds) // 21,24,27 seconds - elements 6,7,8 s.tick(10.seconds) - assertEquals(result.value, Some(Success(List(Chain(0), Chain(1, 2), Chain(3, 4 , 5), Chain(6, 7, 8))))) + assertEquals(result.value, Some(Success(List(Chain(0), Chain(1, 2), Chain(3, 4, 5), Chain(6, 7, 8))))) } test("performs conflation when upstream is unbounded and downstream is slow") { implicit s => diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WhileBusyDropEventsAndSignalOverflowSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WhileBusyDropEventsAndSignalOverflowSuite.scala index d763abb22..0c1533a21 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WhileBusyDropEventsAndSignalOverflowSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WhileBusyDropEventsAndSignalOverflowSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import minitest.TestSuite import monix.execution.Ack.Continue import monix.execution.schedulers.TestScheduler import monix.reactive.subjects.PublishSubject -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Promise import scala.util.Success diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WhileBusyDropEventsSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WhileBusyDropEventsSuite.scala index 96e542f4f..19cf4cc66 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WhileBusyDropEventsSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WhileBusyDropEventsSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ import monix.execution.Ack.Continue import monix.execution.schedulers.TestScheduler import monix.execution.exceptions.DummyException import monix.reactive.subjects.PublishSubject -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Promise import scala.util.Success diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom2Suite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom2Suite.scala index 0029754ae..922ac793d 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom2Suite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom2Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom3Suite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom3Suite.scala index 50b4dd269..1d326b53a 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom3Suite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom3Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom4Suite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom4Suite.scala index 7087a54ca..fb4d1a8ab 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom4Suite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom4Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom5Suite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom5Suite.scala index 83eead3ab..af2a8df3d 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom5Suite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom5Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom6Suite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom6Suite.scala index 0e8d23f4b..5aa64dbe2 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom6Suite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFrom6Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFromSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFromSuite.scala index bcc4db70e..83fb5d482 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFromSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/WithLatestFromSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip2Suite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip2Suite.scala index bfa75748d..4686f6f6d 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip2Suite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip2Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import monix.execution.Ack.Continue import monix.execution.FutureUtils.extensions._ import monix.execution.exceptions.DummyException import monix.reactive.subjects.PublishSubject -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future import scala.concurrent.duration.Duration.Zero import scala.concurrent.duration._ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip3Suite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip3Suite.scala index cac53ad50..571df973c 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip3Suite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip3Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip4Suite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip4Suite.scala index 4808619f5..5289d2179 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip4Suite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip4Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip5Suite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip5Suite.scala index e67282bd7..cecd8042c 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip5Suite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip5Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip6Suite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip6Suite.scala index ef6ec76bb..3fd578efa 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip6Suite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/Zip6Suite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ZipListSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ZipListSuite.scala index 78b4df13a..a57793c8d 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ZipListSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ZipListSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ZipWithIndexSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ZipWithIndexSuite.scala index b093aaeeb..60507adfb 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ZipWithIndexSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/operators/ZipWithIndexSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/rstreams/MonixSubscriberAsReactiveSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/rstreams/MonixSubscriberAsReactiveSuite.scala index 4badfdff6..e1cb4d2fb 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/rstreams/MonixSubscriberAsReactiveSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/rstreams/MonixSubscriberAsReactiveSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,9 +18,9 @@ package monix.reactive.internal.rstreams import minitest.TestSuite -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.schedulers.TestScheduler -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future @@ -236,7 +236,7 @@ object MonixSubscriberAsReactiveSuite extends TestSuite[TestScheduler] { var sum = 0L val observer = new Observer[Long] { - private[this] var received = 0 + private var received = 0 def onNext(elem: Long) = Future { received += 1 @@ -273,12 +273,12 @@ object MonixSubscriberAsReactiveSuite extends TestSuite[TestScheduler] { } test("should cancel precisely with requests of size 1") { implicit s => - for (i <- 0 until 100) { + for (_ <- 0 until 100) { var completed = 0 var sum = 0L val observer = new Observer[Long] { - private[this] var received = 0 + private var received = 0 def onNext(elem: Long) = Future { received += 1 @@ -320,7 +320,7 @@ object MonixSubscriberAsReactiveSuite extends TestSuite[TestScheduler] { var sum = 0L val observer = new Observer[Long] { - private[this] var received = 0 + private var received = 0 def onNext(elem: Long) = Future { received += 1 @@ -353,7 +353,7 @@ object MonixSubscriberAsReactiveSuite extends TestSuite[TestScheduler] { var sum = 0L val observer = new Observer[Long] { - private[this] var received = 0 + private var received = 0 def onNext(elem: Long) = Future { received += 1 diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/rstreams/ObservableIsPublisherSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/rstreams/ObservableIsPublisherSuite.scala index b49704589..6dd67ad08 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/rstreams/ObservableIsPublisherSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/rstreams/ObservableIsPublisherSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,7 +24,7 @@ import monix.execution.rstreams.SingleAssignSubscription import monix.execution.schedulers.TestScheduler import monix.reactive.Observable import monix.reactive.subjects.PublishSubject -import org.reactivestreams.{Subscriber, Subscription} +import org.reactivestreams.{ Subscriber, Subscription } import scala.util.Success @@ -47,7 +47,7 @@ object ObservableIsPublisherSuite extends TestSuite[TestScheduler] { .range(0, 10000) .toReactivePublisher .subscribe(new Subscriber[Long] { - private[this] var s = null: Subscription + private var s = null: Subscription def onSubscribe(s: Subscription): Unit = { this.s = s @@ -150,8 +150,8 @@ object ObservableIsPublisherSuite extends TestSuite[TestScheduler] { .range(0, range) .toReactivePublisher .subscribe(new Subscriber[Long] { - private[this] var s = null: Subscription - private[this] var requested = chunkSize + private var s = null: Subscription + private var requested = chunkSize def onSubscribe(s: Subscription): Unit = { this.s = s @@ -193,8 +193,8 @@ object ObservableIsPublisherSuite extends TestSuite[TestScheduler] { .range(0, range) .toReactivePublisher .subscribe(new Subscriber[Long] { - private[this] var s = null: Subscription - private[this] var requested = chunkSize + private var s = null: Subscription + private var requested = chunkSize def onSubscribe(s: Subscription): Unit = { this.s = s diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/rstreams/PublisherIsObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/rstreams/PublisherIsObservableSuite.scala index 80370780b..2b37e3777 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/rstreams/PublisherIsObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/rstreams/PublisherIsObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,14 +18,14 @@ package monix.reactive.internal.rstreams import minitest.TestSuite -import monix.execution.Ack.{Continue, Stop} -import monix.execution.atomic.{Atomic, AtomicBoolean, AtomicInt} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.atomic.{ Atomic, AtomicBoolean, AtomicInt } import monix.execution.schedulers.TestScheduler -import monix.execution.{Ack, Cancelable, Scheduler} -import monix.reactive.{Observable, Observer} -import org.reactivestreams.{Publisher, Subscriber, Subscription} +import monix.execution.{ Ack, Cancelable, Scheduler } +import monix.reactive.{ Observable, Observer } +import org.reactivestreams.{ Publisher, Subscriber, Subscription } -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object PublisherIsObservableSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() @@ -115,7 +115,8 @@ object PublisherIsObservableSuite extends TestSuite[TestScheduler] { requestSize: Int, ack: Atomic[Promise[Ack]], active: AtomicBoolean, - received: AtomicInt)(implicit s: Scheduler): Cancelable = { + received: AtomicInt + )(implicit s: Scheduler): Cancelable = { Observable .fromReactivePublisher(p, requestSize) @@ -128,25 +129,27 @@ object PublisherIsObservableSuite extends TestSuite[TestScheduler] { def onError(ex: Throwable): Unit = throw ex def onComplete(): Unit = - active := false + active.set(false) }) } private def createPublisher(isPublisherActive: AtomicBoolean, requested: AtomicInt, requestSize: Int)( - implicit s: Scheduler): Publisher[Long] = { + implicit s: Scheduler + ): Publisher[Long] = { new Publisher[Long] { - override def subscribe(subscriber: Subscriber[_ >: Long]): Unit = + override def subscribe(subscriber: Subscriber[? >: Long]): Unit = subscriber.onSubscribe(new Subscription { override def cancel(): Unit = - isPublisherActive := false + isPublisherActive.set(false) override def request(n: Long): Unit = { assertEquals(n, requestSize.toLong) requested.increment(requestSize) if (isPublisherActive.get()) { s.executeTrampolined { () => - for (_ <- 0 until n.toInt) subscriber.onNext(1L) + for (_ <- 0 until n.toInt) + subscriber.onNext(1L) } } } diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/internal/subscribers/ObservableForeachSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/internal/subscribers/ObservableForeachSuite.scala index 3cf19a30d..100a4c6c1 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/internal/subscribers/ObservableForeachSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/internal/subscribers/ObservableForeachSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,9 +19,9 @@ package monix.reactive.internal.subscribers import monix.execution.ExecutionModel.SynchronousExecution import monix.execution.exceptions.DummyException -import monix.reactive.{BaseTestSuite, Observable} +import monix.reactive.{ BaseTestSuite, Observable } -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object ObservableForeachSuite extends BaseTestSuite { test("foreach subscribes immediately") { scheduler => diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observables/ChainedObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observables/ChainedObservableSuite.scala index 59addef8c..2ea8b3895 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observables/ChainedObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observables/ChainedObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observables/ConnectableObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observables/ConnectableObservableSuite.scala index d3aa221b5..2a5ad8f6c 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observables/ConnectableObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observables/ConnectableObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import minitest.TestSuite import monix.execution.Ack.Continue import monix.execution.schedulers.TestScheduler import monix.reactive.subjects.ConcurrentSubject -import monix.reactive.{Consumer, Observable} +import monix.reactive.{ Consumer, Observable } import scala.util.Success diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observables/RefCountObservableSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observables/RefCountObservableSuite.scala index 536b47a2e..f89b1eb45 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observables/RefCountObservableSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observables/RefCountObservableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,7 +24,7 @@ import monix.execution.schedulers.TestScheduler import monix.reactive.OverflowStrategy.Unbounded import monix.execution.exceptions.DummyException import monix.reactive.subjects.ConcurrentSubject -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.concurrent.Future import scala.concurrent.duration._ diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observers/ConnectableSubscriberSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observers/ConnectableSubscriberSuite.scala index 7db551302..90af3f861 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observers/ConnectableSubscriberSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observers/ConnectableSubscriberSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observers/ContramapObserverSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observers/ContramapObserverSuite.scala index 1ebc06261..f6a23f2d4 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observers/ContramapObserverSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observers/ContramapObserverSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,9 @@ package monix.reactive.observers -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.exceptions.DummyException -import monix.reactive.{BaseTestSuite, Observer} +import monix.reactive.{ BaseTestSuite, Observer } object ContramapObserverSuite extends BaseTestSuite { test("Observer.contramap equivalence with plain Observer") { implicit s => diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observers/ContramapSubscriberSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observers/ContramapSubscriberSuite.scala index cdcc25e1f..8e9acfe5f 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observers/ContramapSubscriberSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observers/ContramapSubscriberSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.reactive.observers -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.Scheduler import monix.execution.exceptions.DummyException import monix.reactive.BaseTestSuite diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observers/DumpObserverSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observers/DumpObserverSuite.scala index d2aa9c65b..298af2a7b 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observers/DumpObserverSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observers/DumpObserverSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.reactive.observers -import java.io.{OutputStream, PrintStream} +import java.io.{ OutputStream, PrintStream } import minitest.SimpleTestSuite import monix.execution.Ack.Continue diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observers/ObserverFeedSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observers/ObserverFeedSuite.scala index 7933f22f1..1ca618150 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observers/ObserverFeedSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observers/ObserverFeedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +17,9 @@ package monix.reactive.observers -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.cancelables.BooleanCancelable -import monix.reactive.{BaseTestSuite, Observer} +import monix.reactive.{ BaseTestSuite, Observer } import scala.concurrent.Future import scala.util.Success diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyBackPressureBatchedSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyBackPressureBatchedSuite.scala index 26a307256..a5a8f8fee 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyBackPressureBatchedSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyBackPressureBatchedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,12 +19,12 @@ package monix.reactive.observers import minitest.TestSuite import monix.execution.Ack -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.ChannelType.MultiProducer import monix.execution.schedulers.TestScheduler import monix.execution.exceptions.DummyException -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.util.Success object OverflowStrategyBackPressureBatchedSuite extends TestSuite[TestScheduler] { @@ -136,7 +136,8 @@ object OverflowStrategyBackPressureBatchedSuite extends TestSuite[TestScheduler] if (n > 0) s.execute { () => buffer.onNext(n); loop(n - 1) - } else + } + else buffer.onComplete() loop(10000) @@ -174,7 +175,8 @@ object OverflowStrategyBackPressureBatchedSuite extends TestSuite[TestScheduler] if (n > 0) s.execute { () => buffer.onNext(n); loop(n - 1) - } else + } + else buffer.onComplete() loop(10000) diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyBackPressureSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyBackPressureSuite.scala index d29ada18a..00b5770ba 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyBackPressureSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyBackPressureSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,12 +19,12 @@ package monix.reactive.observers import minitest.TestSuite import monix.execution.Ack -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.internal.Platform import monix.execution.schedulers.TestScheduler import monix.reactive.OverflowStrategy.BackPressure import monix.execution.exceptions.DummyException -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object OverflowStrategyBackPressureSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() @@ -133,7 +133,8 @@ object OverflowStrategyBackPressureSuite extends TestSuite[TestScheduler] { if (n > 0) s.execute { () => buffer.onNext(n); loop(n - 1) - } else + } + else buffer.onComplete() loop(10000) @@ -171,7 +172,8 @@ object OverflowStrategyBackPressureSuite extends TestSuite[TestScheduler] { if (n > 0) s.execute { () => buffer.onNext(n); loop(n - 1) - } else + } + else buffer.onComplete() loop(10000) diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyClearBufferAndSignalSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyClearBufferAndSignalSuite.scala index f6756c1b8..9b6831869 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyClearBufferAndSignalSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyClearBufferAndSignalSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,16 +19,16 @@ package monix.reactive.observers import minitest.TestSuite import monix.eval.Coeval -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.atomic.AtomicLong -import monix.execution.internal.{Platform, RunnableAction} +import monix.execution.internal.{ Platform, RunnableAction } import monix.execution.schedulers.TestScheduler -import monix.execution.{Ack, Scheduler} +import monix.execution.{ Ack, Scheduler } import monix.reactive.Observer import monix.reactive.OverflowStrategy.ClearBufferAndSignal import monix.execution.exceptions.DummyException -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object OverflowStrategyClearBufferAndSignalSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() @@ -45,7 +45,8 @@ object OverflowStrategyClearBufferAndSignalSuite extends TestSuite[TestScheduler BufferedSubscriber[Int]( Subscriber(underlying, s), - ClearBufferAndSignal(bufferSize, nr => Coeval { log.set(nr); None })) + ClearBufferAndSignal(bufferSize, nr => Coeval { log.set(nr); None }) + ) } test("should not lose events, test 1") { implicit s => @@ -220,13 +221,16 @@ object OverflowStrategyClearBufferAndSignalSuite extends TestSuite[TestScheduler test("should send onError when in flight") { implicit s => var errorThrown: Throwable = null - val buffer = buildNewWithSignal(5, new Observer[Int] { - def onError(ex: Throwable) = { - errorThrown = ex + val buffer = buildNewWithSignal( + 5, + new Observer[Int] { + def onError(ex: Throwable) = { + errorThrown = ex + } + def onNext(elem: Int) = Continue + def onComplete() = throw new IllegalStateException() } - def onNext(elem: Int) = Continue - def onComplete() = throw new IllegalStateException() - }) + ) buffer.onNext(1) buffer.onError(DummyException("dummy")) @@ -239,13 +243,16 @@ object OverflowStrategyClearBufferAndSignalSuite extends TestSuite[TestScheduler var errorThrown: Throwable = null val promise = Promise[Ack]() - val buffer = buildNewWithSignal(5, new Observer[Int] { - def onError(ex: Throwable) = { - errorThrown = ex + val buffer = buildNewWithSignal( + 5, + new Observer[Int] { + def onError(ex: Throwable) = { + errorThrown = ex + } + def onNext(elem: Int) = promise.future + def onComplete() = throw new IllegalStateException() } - def onNext(elem: Int) = promise.future - def onComplete() = throw new IllegalStateException() - }) + ) for (i <- 1 to 10) assertEquals(buffer.onNext(i), Continue) buffer.onError(DummyException("dummy")) @@ -261,14 +268,17 @@ object OverflowStrategyClearBufferAndSignalSuite extends TestSuite[TestScheduler var wasCompleted = false val startConsuming = Promise[Continue.type]() - val buffer = buildNewWithSignal(10000, new Observer[Int] { - def onNext(elem: Int) = { - sum += elem - startConsuming.future + val buffer = buildNewWithSignal( + 10000, + new Observer[Int] { + def onNext(elem: Int) = { + sum += elem + startConsuming.future + } + def onError(ex: Throwable) = throw ex + def onComplete() = wasCompleted = true } - def onError(ex: Throwable) = throw ex - def onComplete() = wasCompleted = true - }) + ) (0 until 9999).foreach { x => buffer.onNext(x); () } buffer.onComplete() @@ -283,14 +293,17 @@ object OverflowStrategyClearBufferAndSignalSuite extends TestSuite[TestScheduler var sum = 0L var wasCompleted = false - val buffer = buildNewWithSignal(10000, new Observer[Int] { - def onNext(elem: Int) = { - sum += elem - Continue + val buffer = buildNewWithSignal( + 10000, + new Observer[Int] { + def onNext(elem: Int) = { + sum += elem + Continue + } + def onError(ex: Throwable) = throw ex + def onComplete() = wasCompleted = true } - def onError(ex: Throwable) = throw ex - def onComplete() = wasCompleted = true - }) + ) (0 until 9999).foreach { x => buffer.onNext(x); () } buffer.onComplete() @@ -330,14 +343,17 @@ object OverflowStrategyClearBufferAndSignalSuite extends TestSuite[TestScheduler var sum = 0L var errorThrown: Throwable = null - val buffer = buildNewWithSignal(10000, new Observer[Int] { - def onNext(elem: Int) = { - sum += elem - Continue + val buffer = buildNewWithSignal( + 10000, + new Observer[Int] { + def onNext(elem: Int) = { + sum += elem + Continue + } + def onError(ex: Throwable) = errorThrown = ex + def onComplete() = throw new IllegalStateException() } - def onError(ex: Throwable) = errorThrown = ex - def onComplete() = throw new IllegalStateException() - }) + ) (0 until 9999).foreach { x => buffer.onNext(x); () } buffer.onError(DummyException("dummy")) diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyClearBufferSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyClearBufferSuite.scala index 817b13b1a..3440cc7ea 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyClearBufferSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyClearBufferSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,14 +19,14 @@ package monix.reactive.observers import minitest.TestSuite import monix.execution.Ack -import monix.execution.Ack.{Continue, Stop} -import monix.execution.internal.{Platform, RunnableAction} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.internal.{ Platform, RunnableAction } import monix.execution.schedulers.TestScheduler import monix.reactive.Observer import monix.reactive.OverflowStrategy.ClearBuffer import monix.execution.exceptions.DummyException import monix.reactive.observers.OverflowStrategyClearBufferAndSignalSuite._ -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object OverflowStrategyClearBufferSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyDropNewAndSignalSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyDropNewAndSignalSuite.scala index 0a93d55c4..9f2079f90 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyDropNewAndSignalSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyDropNewAndSignalSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,11 +19,11 @@ package monix.reactive.observers import minitest.TestSuite import monix.eval.Coeval -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.atomic.AtomicLong import monix.execution.internal.Platform import monix.execution.schedulers.TestScheduler -import monix.execution.{Ack, Scheduler} +import monix.execution.{ Ack, Scheduler } import monix.reactive.Observer import monix.reactive.OverflowStrategy.DropNewAndSignal import monix.execution.exceptions.DummyException @@ -100,7 +100,8 @@ object OverflowStrategyDropNewAndSignalSuite extends TestSuite[TestScheduler] { if (n > 0) s.execute { () => buffer.onNext(n); loop(n - 1) - } else + } + else buffer.onComplete() loop(10000) @@ -219,13 +220,16 @@ object OverflowStrategyDropNewAndSignalSuite extends TestSuite[TestScheduler] { test("should send onError when in flight") { implicit s => var errorThrown: Throwable = null - val buffer = buildNewForIntWithSignal(5, new Observer[Int] { - def onError(ex: Throwable) = { - errorThrown = ex + val buffer = buildNewForIntWithSignal( + 5, + new Observer[Int] { + def onError(ex: Throwable) = { + errorThrown = ex + } + def onNext(elem: Int) = Continue + def onComplete() = throw new IllegalStateException() } - def onNext(elem: Int) = Continue - def onComplete() = throw new IllegalStateException() - }) + ) buffer.onNext(1) buffer.onError(DummyException("dummy")) @@ -238,13 +242,16 @@ object OverflowStrategyDropNewAndSignalSuite extends TestSuite[TestScheduler] { var errorThrown: Throwable = null val promise = Promise[Ack]() - val buffer = buildNewForIntWithSignal(5, new Observer[Int] { - def onError(ex: Throwable) = { - errorThrown = ex + val buffer = buildNewForIntWithSignal( + 5, + new Observer[Int] { + def onError(ex: Throwable) = { + errorThrown = ex + } + def onNext(elem: Int) = promise.future + def onComplete() = throw new IllegalStateException() } - def onNext(elem: Int) = promise.future - def onComplete() = throw new IllegalStateException() - }) + ) buffer.onNext(1) buffer.onNext(2) @@ -264,14 +271,17 @@ object OverflowStrategyDropNewAndSignalSuite extends TestSuite[TestScheduler] { var wasCompleted = false val startConsuming = Promise[Continue.type]() - val buffer = buildNewForLongWithSignal(10000, new Observer[Long] { - def onNext(elem: Long) = { - sum += elem - startConsuming.future + val buffer = buildNewForLongWithSignal( + 10000, + new Observer[Long] { + def onNext(elem: Long) = { + sum += elem + startConsuming.future + } + def onError(ex: Throwable) = throw ex + def onComplete() = wasCompleted = true } - def onError(ex: Throwable) = throw ex - def onComplete() = wasCompleted = true - }) + ) (0 until 9999).foreach { x => buffer.onNext(x.toLong); () } buffer.onComplete() @@ -286,14 +296,17 @@ object OverflowStrategyDropNewAndSignalSuite extends TestSuite[TestScheduler] { var sum = 0L var wasCompleted = false - val buffer = buildNewForLongWithSignal(10000, new Observer[Long] { - def onNext(elem: Long) = { - sum += elem - Continue + val buffer = buildNewForLongWithSignal( + 10000, + new Observer[Long] { + def onNext(elem: Long) = { + sum += elem + Continue + } + def onError(ex: Throwable) = throw ex + def onComplete() = wasCompleted = true } - def onError(ex: Throwable) = throw ex - def onComplete() = wasCompleted = true - }) + ) (0 until 9999).foreach { x => buffer.onNext(x.toLong); () } buffer.onComplete() diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyDropNewSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyDropNewSuite.scala index f07910735..0df5f55bf 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyDropNewSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyDropNewSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,12 +19,12 @@ package monix.reactive.observers import minitest.TestSuite import monix.execution.Ack -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.schedulers.TestScheduler import monix.reactive.Observer import monix.reactive.OverflowStrategy.DropNew import monix.execution.exceptions.DummyException -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object OverflowStrategyDropNewSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() @@ -86,7 +86,8 @@ object OverflowStrategyDropNewSuite extends TestSuite[TestScheduler] { if (n > 0) s.execute { () => buffer.onNext(n); loop(n - 1) - } else + } + else buffer.onComplete() loop(10000) @@ -148,7 +149,8 @@ object OverflowStrategyDropNewSuite extends TestSuite[TestScheduler] { if (n > 0) s.execute { () => buffer.onNext(n); loop(n - 1) - } else + } + else buffer.onComplete() loop(10000) diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyDropOldAndSignalSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyDropOldAndSignalSuite.scala index 2140109dd..d4b6e02e3 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyDropOldAndSignalSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyDropOldAndSignalSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,17 +19,17 @@ package monix.reactive.observers import minitest.TestSuite import monix.eval.Coeval -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.ChannelType.MultiProducer import monix.execution.atomic.AtomicLong -import monix.execution.internal.{Platform, RunnableAction} +import monix.execution.internal.{ Platform, RunnableAction } import monix.execution.schedulers.TestScheduler -import monix.execution.{Ack, Scheduler} +import monix.execution.{ Ack, Scheduler } import monix.reactive.Observer import monix.reactive.OverflowStrategy.DropOldAndSignal import monix.execution.exceptions.DummyException -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object OverflowStrategyDropOldAndSignalSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() @@ -233,13 +233,16 @@ object OverflowStrategyDropOldAndSignalSuite extends TestSuite[TestScheduler] { test("should send onError when in flight") { implicit s => var errorThrown: Throwable = null - val buffer = buildNewWithSignal(5, new Observer[Int] { - def onError(ex: Throwable) = { - errorThrown = ex + val buffer = buildNewWithSignal( + 5, + new Observer[Int] { + def onError(ex: Throwable) = { + errorThrown = ex + } + def onNext(elem: Int) = Continue + def onComplete() = throw new IllegalStateException() } - def onNext(elem: Int) = Continue - def onComplete() = throw new IllegalStateException() - }) + ) buffer.onNext(1) buffer.onError(DummyException("dummy")) @@ -252,13 +255,16 @@ object OverflowStrategyDropOldAndSignalSuite extends TestSuite[TestScheduler] { var errorThrown: Throwable = null val promise = Promise[Ack]() - val buffer = buildNewWithSignal(5, new Observer[Int] { - def onError(ex: Throwable) = { - errorThrown = ex + val buffer = buildNewWithSignal( + 5, + new Observer[Int] { + def onError(ex: Throwable) = { + errorThrown = ex + } + def onNext(elem: Int) = promise.future + def onComplete() = throw new IllegalStateException() } - def onNext(elem: Int) = promise.future - def onComplete() = throw new IllegalStateException() - }) + ) for (i <- 1 to 10) assertEquals(buffer.onNext(i), Continue) buffer.onError(DummyException("dummy")) @@ -274,14 +280,17 @@ object OverflowStrategyDropOldAndSignalSuite extends TestSuite[TestScheduler] { var wasCompleted = false val startConsuming = Promise[Continue.type]() - val buffer = buildNewWithSignal(10000, new Observer[Int] { - def onNext(elem: Int) = { - sum += elem - startConsuming.future + val buffer = buildNewWithSignal( + 10000, + new Observer[Int] { + def onNext(elem: Int) = { + sum += elem + startConsuming.future + } + def onError(ex: Throwable) = throw ex + def onComplete() = wasCompleted = true } - def onError(ex: Throwable) = throw ex - def onComplete() = wasCompleted = true - }) + ) (0 until 9999).foreach { x => buffer.onNext(x); () } buffer.onComplete() @@ -296,14 +305,17 @@ object OverflowStrategyDropOldAndSignalSuite extends TestSuite[TestScheduler] { var sum = 0L var wasCompleted = false - val buffer = buildNewWithSignal(10000, new Observer[Int] { - def onNext(elem: Int) = { - sum += elem - Continue + val buffer = buildNewWithSignal( + 10000, + new Observer[Int] { + def onNext(elem: Int) = { + sum += elem + Continue + } + def onError(ex: Throwable) = throw ex + def onComplete() = wasCompleted = true } - def onError(ex: Throwable) = throw ex - def onComplete() = wasCompleted = true - }) + ) (0 until 9999).foreach { x => buffer.onNext(x); () } buffer.onComplete() @@ -343,14 +355,17 @@ object OverflowStrategyDropOldAndSignalSuite extends TestSuite[TestScheduler] { var sum = 0L var errorThrown: Throwable = null - val buffer = buildNewWithSignal(10000, new Observer[Int] { - def onNext(elem: Int) = { - sum += elem - Continue + val buffer = buildNewWithSignal( + 10000, + new Observer[Int] { + def onNext(elem: Int) = { + sum += elem + Continue + } + def onError(ex: Throwable) = errorThrown = ex + def onComplete() = throw new IllegalStateException() } - def onError(ex: Throwable) = errorThrown = ex - def onComplete() = throw new IllegalStateException() - }) + ) (0 until 9999).foreach { x => buffer.onNext(x); () } buffer.onError(DummyException("dummy")) diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyDropOldSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyDropOldSuite.scala index 252ab4494..66e304228 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyDropOldSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyDropOldSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,13 +19,13 @@ package monix.reactive.observers import minitest.TestSuite import monix.execution.Ack -import monix.execution.Ack.{Continue, Stop} -import monix.execution.internal.{Platform, RunnableAction} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.internal.{ Platform, RunnableAction } import monix.execution.schedulers.TestScheduler import monix.reactive.Observer import monix.reactive.OverflowStrategy.DropOld import monix.execution.exceptions.DummyException -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object OverflowStrategyDropOldSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyFailSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyFailSuite.scala index 892c30abf..1e29677ad 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyFailSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyFailSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.observers import minitest.TestSuite import monix.execution.Ack -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.exceptions.BufferOverflowException import monix.execution.internal.Platform import monix.execution.schedulers.TestScheduler @@ -27,7 +27,7 @@ import monix.reactive.Observer import monix.reactive.OverflowStrategy.Fail import monix.execution.exceptions.DummyException -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object OverflowStrategyFailSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() @@ -89,7 +89,8 @@ object OverflowStrategyFailSuite extends TestSuite[TestScheduler] { if (n > 0) s.execute { () => buffer.onNext(n); loop(n - 1) - } else + } + else buffer.onComplete() loop(10000) diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyUnboundedSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyUnboundedSuite.scala index cee62885a..cf81d8aff 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyUnboundedSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observers/OverflowStrategyUnboundedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,14 +19,14 @@ package monix.reactive.observers import minitest.TestSuite import monix.execution.Ack -import monix.execution.Ack.{Continue, Stop} -import monix.execution.internal.{Platform, RunnableAction} +import monix.execution.Ack.{ Continue, Stop } +import monix.execution.internal.{ Platform, RunnableAction } import monix.execution.schedulers.TestScheduler import monix.reactive.Observer import monix.reactive.OverflowStrategy.Unbounded import monix.execution.exceptions.DummyException -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object OverflowStrategyUnboundedSuite extends TestSuite[TestScheduler] { def setup() = TestScheduler() @@ -354,15 +354,18 @@ object OverflowStrategyUnboundedSuite extends TestSuite[TestScheduler] { var received = 0L var wasCompleted = false - val buffer = BufferedSubscriber[Long](new Subscriber[Long] { - def onNext(elem: Long) = { - received += 1 - Continue - } - def onError(ex: Throwable) = () - def onComplete() = wasCompleted = true - val scheduler = s - }, Unbounded) + val buffer = BufferedSubscriber[Long]( + new Subscriber[Long] { + def onNext(elem: Long) = { + received += 1 + Continue + } + def onError(ex: Throwable) = () + def onComplete() = wasCompleted = true + val scheduler = s + }, + Unbounded + ) for (i <- 0 until (Platform.recommendedBatchSize * 2)) buffer.onNext(i.toLong) buffer.onComplete() diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observers/SafeSubscriberSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observers/SafeSubscriberSuite.scala index bf7db0503..93c44b4e4 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observers/SafeSubscriberSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observers/SafeSubscriberSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,9 +20,9 @@ package monix.reactive.observers import minitest.TestSuite import monix.execution.Ack import monix.execution.schedulers.TestScheduler -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.exceptions.DummyException -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } import scala.util.Success object SafeSubscriberSuite extends TestSuite[TestScheduler] { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observers/StoppedObserverSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observers/StoppedObserverSuite.scala index d1d2d93c5..742611fd9 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observers/StoppedObserverSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observers/StoppedObserverSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.observers import monix.execution.Ack.Stop import monix.execution.exceptions.DummyException -import monix.reactive.{BaseTestSuite, Observer} +import monix.reactive.{ BaseTestSuite, Observer } object StoppedObserverSuite extends BaseTestSuite { test("Observer.stopped works") { implicit s => diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/observers/SubscriberFeedSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/observers/SubscriberFeedSuite.scala index 7759f1f5d..fe1542cfe 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/observers/SubscriberFeedSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/observers/SubscriberFeedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.reactive.observers -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.Scheduler import monix.execution.cancelables.BooleanCancelable import monix.execution.compat.internal.toIterator diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/AsyncSubjectSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/AsyncSubjectSuite.scala index ddc12d153..fa5fc458b 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/AsyncSubjectSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/AsyncSubjectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.subjects import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException -import monix.reactive.{Consumer, Observable, Observer} +import monix.reactive.{ Consumer, Observable, Observer } object AsyncSubjectSuite extends BaseSubjectSuite { def alreadyTerminatedTest(expectedElems: Seq[Long]) = { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/BaseConcurrentSubjectSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/BaseConcurrentSubjectSuite.scala index 78feaccd2..5e23ff56f 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/BaseConcurrentSubjectSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/BaseConcurrentSubjectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ import monix.execution.exceptions.DummyException import monix.execution.Ack.Continue import monix.execution.Scheduler import monix.execution.schedulers.TestScheduler -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.util.Random diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/BaseSubjectSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/BaseSubjectSuite.scala index 65fb557a1..154e7aa8c 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/BaseSubjectSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/BaseSubjectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,10 +19,10 @@ package monix.reactive.subjects import minitest.TestSuite import monix.eval.Task -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler -import monix.reactive.{Observable, Observer} +import monix.reactive.{ Observable, Observer } import scala.util.Random diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/BehaviorSubjectSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/BehaviorSubjectSuite.scala index 0b05bc2e9..d0072fd50 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/BehaviorSubjectSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/BehaviorSubjectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.subjects import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException -import monix.reactive.{Consumer, Observable, Observer} +import monix.reactive.{ Consumer, Observable, Observer } import scala.concurrent.Future import scala.util.Success @@ -41,7 +41,7 @@ object BehaviorSubjectSuite extends BaseSubjectSuite { var received = 0 var wasCompleted = 0 - for (i <- 0 until 10) + for (_ <- 0 until 10) subject.unsafeSubscribeFn(new Observer[Int] { def onNext(elem: Int): Future[Ack] = { received += elem @@ -67,7 +67,7 @@ object BehaviorSubjectSuite extends BaseSubjectSuite { var received = 0 var wasCompleted = 0 - for (i <- 0 until 10) + for (_ <- 0 until 10) subject.unsafeSubscribeFn(new Observer[Int] { def onNext(elem: Int) = Future { received += elem diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentAsyncSubjectSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentAsyncSubjectSuite.scala index 69b76d936..5f9b3489c 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentAsyncSubjectSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentAsyncSubjectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.subjects import monix.execution.Ack.Continue import monix.execution.Scheduler import monix.execution.exceptions.DummyException -import monix.reactive.{MulticastStrategy, Observer} +import monix.reactive.{ MulticastStrategy, Observer } object ConcurrentAsyncSubjectSuite extends BaseConcurrentSubjectSuite { def alreadyTerminatedTest(expectedElems: Seq[Long])(implicit s: Scheduler) = { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentBehaviorSubjectSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentBehaviorSubjectSuite.scala index 2dce297d4..bf7ad7758 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentBehaviorSubjectSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentBehaviorSubjectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.reactive.subjects import monix.execution.Scheduler -import monix.reactive.{MulticastStrategy, OverflowStrategy} +import monix.reactive.{ MulticastStrategy, OverflowStrategy } import OverflowStrategy.Unbounded object ConcurrentBehaviorSubjectSuite extends BaseConcurrentSubjectSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentPublishSubjectSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentPublishSubjectSuite.scala index bd663f5c7..eedfe6a0b 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentPublishSubjectSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentPublishSubjectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.reactive.subjects import monix.execution.Scheduler -import monix.reactive.{MulticastStrategy, OverflowStrategy} +import monix.reactive.{ MulticastStrategy, OverflowStrategy } import OverflowStrategy.Unbounded object ConcurrentPublishSubjectSuite extends BaseConcurrentSubjectSuite { diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentReplayLimitedSubjectSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentReplayLimitedSubjectSuite.scala index a6f3e38d2..f4e13ac99 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentReplayLimitedSubjectSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentReplayLimitedSubjectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentReplaySubjectSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentReplaySubjectSuite.scala index 68d0fe64c..d4ff99d23 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentReplaySubjectSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ConcurrentReplaySubjectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ProfunctorSubjectSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ProfunctorSubjectSuite.scala index b70ac332b..7460a02e8 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ProfunctorSubjectSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ProfunctorSubjectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.reactive.subjects import cats.implicits._ import monix.execution.Ack -import monix.execution.Ack.{Continue, Stop} +import monix.execution.Ack.{ Continue, Stop } import monix.execution.exceptions.DummyException import monix.reactive.Observer @@ -44,7 +44,7 @@ object ProfunctorSubjectSuite extends BaseSubjectSuite { var wasCompleted = 0 var errorThrown: Throwable = null - for (i <- 0 until 10) + for (_ <- 0 until 10) subject.unsafeSubscribeFn(new Observer[Int] { def onNext(elem: Int): Future[Ack] = { received += elem @@ -71,7 +71,7 @@ object ProfunctorSubjectSuite extends BaseSubjectSuite { var wasCompleted = 0 var errorThrown: Throwable = null - for (i <- 0 until 10) + for (_ <- 0 until 10) subject.unsafeSubscribeFn(new Observer[Int] { def onNext(elem: Int): Future[Ack] = { received += elem @@ -98,7 +98,7 @@ object ProfunctorSubjectSuite extends BaseSubjectSuite { var received = 0 var wasCompleted = 0 - for (i <- 0 until 10) + for (_ <- 0 until 10) subject.unsafeSubscribeFn(new Observer[Int] { def onNext(elem: Int): Future[Ack] = { received += elem @@ -124,7 +124,7 @@ object ProfunctorSubjectSuite extends BaseSubjectSuite { var received = 0 var wasCompleted = 0 - for (i <- 0 until 10) + for (_ <- 0 until 10) subject.unsafeSubscribeFn(new Observer[Int] { def onNext(elem: Int) = Future { received += elem diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/PublishSubjectSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/PublishSubjectSuite.scala index 67f8810fa..bae6a7328 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/PublishSubjectSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/PublishSubjectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.subjects import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException -import monix.reactive.{Observable, Observer, OverflowStrategy} +import monix.reactive.{ Observable, Observer, OverflowStrategy } import scala.concurrent.Future import scala.util.Success @@ -94,7 +94,7 @@ object PublishSubjectSuite extends BaseSubjectSuite { var received = 0 var wasCompleted = 0 - for (i <- 0 until 10) + for (_ <- 0 until 10) subject.unsafeSubscribeFn(new Observer[Int] { def onNext(elem: Int): Future[Ack] = { received += elem @@ -119,7 +119,7 @@ object PublishSubjectSuite extends BaseSubjectSuite { var received = 0 var wasCompleted = 0 - for (i <- 0 until 10) + for (_ <- 0 until 10) subject.unsafeSubscribeFn(new Observer[Int] { def onNext(elem: Int) = Future { received += elem diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ReplaySubjectSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ReplaySubjectSuite.scala index 8a4bda2f6..7748eb09a 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ReplaySubjectSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/ReplaySubjectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.reactive.subjects import monix.execution.Ack import monix.execution.Ack.Continue import monix.execution.exceptions.DummyException -import monix.reactive.{Consumer, Observable, Observer} +import monix.reactive.{ Consumer, Observable, Observer } import scala.concurrent.Future import scala.util.Success @@ -77,7 +77,7 @@ object ReplaySubjectSuite extends BaseSubjectSuite { var received = 0 var wasCompleted = 0 - for (i <- 0 until 10) + for (_ <- 0 until 10) subject.unsafeSubscribeFn(new Observer[Int] { def onNext(elem: Int): Future[Ack] = { received += elem @@ -104,7 +104,7 @@ object ReplaySubjectSuite extends BaseSubjectSuite { var received = 0 var wasCompleted = 0 - for (i <- 0 until 10) + for (_ <- 0 until 10) subject.unsafeSubscribeFn(new Observer[Int] { def onNext(elem: Int) = Future { received += elem diff --git a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/VarSuite.scala b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/VarSuite.scala index 0fe376d31..2adf1da86 100644 --- a/monix-reactive/shared/src/test/scala/monix/reactive/subjects/VarSuite.scala +++ b/monix-reactive/shared/src/test/scala/monix/reactive/subjects/VarSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/Iterant.scala b/monix-tail/shared/src/main/scala/monix/tail/Iterant.scala index 8f11f7c2f..740723860 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/Iterant.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/Iterant.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.tail import java.io.PrintStream import cats.implicits._ -import cats.effect.{Async, Effect, Sync, _} +import cats.effect.{ Async, Effect, Sync, _ } import cats.{ ~>, Applicative, @@ -36,23 +36,23 @@ import cats.{ Parallel, StackSafeMonad } -import monix.catnap.{ConcurrentChannel, ConsumerF} +import monix.catnap.{ ConcurrentChannel, ConsumerF } import monix.execution.BufferCapacity.Bounded -import monix.execution.{BufferCapacity, ChannelType} -import monix.execution.ChannelType.{MultiProducer, SingleConsumer} +import monix.execution.{ BufferCapacity, ChannelType } +import monix.execution.ChannelType.{ MultiProducer, SingleConsumer } import monix.execution.annotations.UnsafeProtocol import monix.execution.compat.internal._ import scala.util.control.NonFatal -import monix.execution.internal.Platform.{recommendedBatchSize, recommendedBufferChunkSize} -import monix.tail.batches.{Batch, BatchCursor} +import monix.execution.internal.Platform.{ recommendedBatchSize, recommendedBufferChunkSize } +import monix.tail.batches.{ Batch, BatchCursor } import monix.tail.internal._ import monix.tail.internal.Constants.emptyRef import org.reactivestreams.Publisher import scala.collection.immutable.LinearSeq import scala.collection.mutable -import scala.concurrent.duration.{Duration, FiniteDuration} +import scala.concurrent.duration.{ Duration, FiniteDuration } /** The `Iterant` is a type that describes lazy, possibly asynchronous * streaming of elements using a pull-based protocol. @@ -1504,7 +1504,8 @@ sealed abstract class Iterant[F[_], A] extends Product with Serializable { * throws an error. */ final def onErrorRecoverWith[B >: A](pf: PartialFunction[Throwable, Iterant[F, B]])( - implicit F: Sync[F]): Iterant[F, B] = + implicit F: Sync[F] + ): Iterant[F, B] = onErrorHandleWith { ex => if (pf.isDefinedAt(ex)) pf(ex) else Iterant.raiseError[F, B](ex) @@ -1621,7 +1622,7 @@ sealed abstract class Iterant[F[_], A] extends Product with Serializable { * right hand side) */ final def parZip[B](rhs: Iterant[F, B])(implicit F: Sync[F], P: Parallel[F]): Iterant[F, (A, B)] = - (self parZipMap rhs)((a, b) => (a, b)) + (self.parZipMap(rhs))((a, b) => (a, b)) /** Lazily zip two iterants together, in parallel, using the given * function `f` to produce output values. @@ -1865,7 +1866,8 @@ sealed abstract class Iterant[F[_], A] extends Product with Serializable { */ @UnsafeProtocol final def consumeWithConfig(config: ConsumerF.Config)( - implicit F: Concurrent[F], + implicit + F: Concurrent[F], cs: ContextShift[F] ): Resource[F, Consumer[F, A]] = { IterantConsume(self, config)(F, cs) @@ -1901,8 +1903,8 @@ sealed abstract class Iterant[F[_], A] extends Product with Serializable { * val sub = SingleAssignSubscription() * * source.subscribe(new Subscriber[Int] { - * private[this] var requested = 0L - * private[this] var sum = 0L + * private var requested = 0L + * private var sum = 0L * * def onSubscribe(s: Subscription): Unit = { * sub := s @@ -2184,7 +2186,7 @@ sealed abstract class Iterant[F[_], A] extends Product with Serializable { * right hand side) */ final def zip[B](rhs: Iterant[F, B])(implicit F: Sync[F]): Iterant[F, (A, B)] = - (self zipMap rhs)((a, b) => (a, b)) + (self.zipMap(rhs))((a, b) => (a, b)) /** Lazily zip two iterants together, using the given function `f` to * produce output values. @@ -2484,7 +2486,8 @@ object Iterant extends IterantInstances { * @param release function that releases the acquired resource */ def resourceCase[F[_], A](acquire: F[A])(release: (A, ExitCase[Throwable]) => F[Unit])( - implicit F: Sync[F]): Iterant[F, A] = { + implicit F: Sync[F] + ): Iterant[F, A] = { Scope[F, A, A](acquire, a => F.pure(Iterant.pure(a)), release) } @@ -2569,9 +2572,9 @@ object Iterant extends IterantInstances { /** Converts any `scala.collection.Seq` into a stream. */ def fromSeq[F[_], A](xs: Seq[A])(implicit F: Applicative[F]): Iterant[F, A] = xs match { - case ref: LinearSeq[_] => + case ref: LinearSeq[?] => fromList[F, A](ref.asInstanceOf[LinearSeq[A]])(F) - case ref: IndexedSeq[_] => + case ref: IndexedSeq[?] => fromIndexedSeq[F, A](ref.asInstanceOf[IndexedSeq[A]])(F) case _ => fromIterable(xs)(F) @@ -2633,7 +2636,8 @@ object Iterant extends IterantInstances { def fromReactivePublisher[F[_], A]( publisher: Publisher[A], requestCount: Int = recommendedBufferChunkSize, - eagerBuffer: Boolean = true)( + eagerBuffer: Boolean = true + )( implicit F: Async[F] ): Iterant[F, A] = { IterantFromReactivePublisher(publisher, requestCount, eagerBuffer) @@ -2723,7 +2727,8 @@ object Iterant extends IterantInstances { * items can be pulled from the queue and processed in batches */ def fromConsumer[F[_], A](consumer: Consumer[F, A], maxBatchSize: Int = recommendedBufferChunkSize)( - implicit F: Async[F]): Iterant[F, A] = { + implicit F: Async[F] + ): Iterant[F, A] = { IterantFromConsumer(consumer, maxBatchSize) } @@ -2747,7 +2752,8 @@ object Iterant extends IterantInstances { def fromChannel[F[_], A]( channel: Channel[F, A], bufferCapacity: BufferCapacity = Bounded(recommendedBufferChunkSize), - maxBatchSize: Int = recommendedBufferChunkSize)(implicit F: Async[F]): Iterant[F, A] = { + maxBatchSize: Int = recommendedBufferChunkSize + )(implicit F: Async[F]): Iterant[F, A] = { val config = ConsumerF.Config( capacity = Some(bufferCapacity), @@ -2839,9 +2845,12 @@ object Iterant extends IterantInstances { def channel[F[_], A]( bufferCapacity: BufferCapacity = Bounded(recommendedBufferChunkSize), maxBatchSize: Int = recommendedBufferChunkSize, - producerType: ChannelType.ProducerSide = MultiProducer)( - implicit F: Concurrent[F], - cs: ContextShift[F]): F[(Producer[F, A], Iterant[F, A])] = { + producerType: ChannelType.ProducerSide = MultiProducer + )( + implicit + F: Concurrent[F], + cs: ContextShift[F] + ): F[(Producer[F, A], Iterant[F, A])] = { val channelF = ConcurrentChannel[F].withConfig[Option[Throwable], A]( producerType = producerType @@ -2880,7 +2889,7 @@ object Iterant extends IterantInstances { result case _ => var result: Iterant[F, A] = null - result = NextBatch(Batch(elems: _*), F.delay(result)) + result = NextBatch(Batch(elems*), F.delay(result)) result } @@ -2941,8 +2950,10 @@ object Iterant extends IterantInstances { * delays and to fetch the current time */ def intervalAtFixedRate[F[_]](initialDelay: FiniteDuration, period: FiniteDuration)( - implicit F: Async[F], - timer: Timer[F]): Iterant[F, Long] = + implicit + F: Async[F], + timer: Timer[F] + ): Iterant[F, Long] = IterantIntervalAtFixedRate(initialDelay, period) /** $intervalWithFixedDelayDesc @@ -2965,8 +2976,10 @@ object Iterant extends IterantInstances { * delays and to fetch the current time */ def intervalWithFixedDelay[F[_]](initialDelay: FiniteDuration, delay: FiniteDuration)( - implicit F: Async[F], - timer: Timer[F]): Iterant[F, Long] = + implicit + F: Async[F], + timer: Timer[F] + ): Iterant[F, Long] = IterantIntervalWithFixedDelay(initialDelay, delay) /** Concatenates list of Iterants into a single stream @@ -2974,8 +2987,8 @@ object Iterant extends IterantInstances { def concat[F[_], A](xs: Iterant[F, A]*)(implicit F: Sync[F]): Iterant[F, A] = xs.foldLeft(Iterant.empty[F, A])((acc, e) => IterantConcat.concat(acc, F.pure(e))(F)) - //------------------------------------------------------------------ - //-- Data constructors + // ------------------------------------------------------------------ + // -- Data constructors /** Data constructor for building a [[Iterant.Next]] value. * @@ -3036,7 +3049,8 @@ object Iterant extends IterantInstances { def scopeS[F[_], A, B]( acquire: F[A], use: A => F[Iterant[F, B]], - release: (A, ExitCase[Throwable]) => F[Unit]): Iterant[F, B] = + release: (A, ExitCase[Throwable]) => F[Unit] + ): Iterant[F, B] = Scope(acquire, use, release) /** Builds a stream state equivalent with [[Iterant.Concat]]. @@ -3126,8 +3140,8 @@ object Iterant extends IterantInstances { final case class Scope[F[_], A, B]( acquire: F[A], use: A => F[Iterant[F, B]], - release: (A, ExitCase[Throwable]) => F[Unit]) - extends Iterant[F, B] { + release: (A, ExitCase[Throwable]) => F[Unit] + ) extends Iterant[F, B] { def accept[R](visitor: Visitor[F, B, R]): R = visitor.visit(this) diff --git a/monix-tail/shared/src/main/scala/monix/tail/IterantBuilders.scala b/monix-tail/shared/src/main/scala/monix/tail/IterantBuilders.scala index 5b6d02681..8b3d917a6 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/IterantBuilders.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/IterantBuilders.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,13 +19,14 @@ package monix.tail import cats.Applicative import cats.effect._ -import monix.catnap.{ConsumerF, ProducerF} +import monix.catnap.{ ConsumerF, ProducerF } import monix.execution.BufferCapacity.Bounded import monix.execution.ChannelType.MultiProducer import monix.execution.internal.Platform.recommendedBufferChunkSize -import monix.execution.{BufferCapacity, ChannelType} +import monix.execution.{ BufferCapacity, ChannelType } import monix.tail.Iterant.Channel -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.batches.{ Batch, BatchCursor } +import monix.tail.internal.deprecated.IterantDeprecatedBuilders import org.reactivestreams.Publisher import scala.collection.immutable.LinearSeq @@ -58,7 +59,7 @@ object IterantBuilders { * Class defined inside object due to Scala's limitations on declaring * `AnyVal` classes. */ - final class Apply[F[_]](val v: Boolean = true) extends AnyVal { + final class Apply[F[_]](val v: Boolean = true) extends AnyVal with IterantDeprecatedBuilders[F] { /** Aliased builder, see documentation for [[Iterant.now]]. */ def now[A](a: A): Iterant[F, A] = Iterant.now(a) @@ -91,7 +92,8 @@ object IterantBuilders { def scopeS[A, B]( acquire: F[A], use: A => F[Iterant[F, B]], - close: (A, ExitCase[Throwable]) => F[Unit]): Iterant[F, B] = + close: (A, ExitCase[Throwable]) => F[Unit] + ): Iterant[F, B] = Iterant.scopeS(acquire, use, close) /** Aliased builder, see documentation for [[Iterant.lastS]]. */ @@ -110,6 +112,10 @@ object IterantBuilders { def raiseError[A](ex: Throwable): Iterant[F, A] = Iterant.raiseError(ex) + /** Aliased builder, see documentation for [[Iterant.suspend[F[_],A](rest* Iterant.suspend]]. */ + def suspend[A](rest: F[Iterant[F, A]]): Iterant[F, A] = + Iterant.suspend(rest) + // ----------------------------------------------------------------- // -- Requiring Applicative @@ -121,10 +127,6 @@ object IterantBuilders { def liftF[A](a: F[A])(implicit F: Applicative[F]): Iterant[F, A] = Iterant.liftF(a) - /** Aliased builder, see documentation for [[Iterant.suspend[F[_],A](rest* Iterant.suspend]]. */ - def suspend[A](rest: F[Iterant[F, A]])(implicit F: Applicative[F]): Iterant[F, A] = - Iterant.suspend(rest) - /** Aliased builder, see documentation for [[Iterant.fromArray]]. */ def fromArray[A](xs: Array[A])(implicit F: Applicative[F]): Iterant[F, A] = Iterant.fromArray(xs) @@ -178,7 +180,8 @@ object IterantBuilders { /** Aliased builder, see documentation for [[Iterant.resourceCase]]. */ def resourceCase[A](acquire: F[A])(release: (A, ExitCase[Throwable]) => F[Unit])( - implicit F: Sync[F]): Iterant[F, A] = + implicit F: Sync[F] + ): Iterant[F, A] = Iterant.resourceCase(acquire)(release) /** Aliased builder, see documentation for [[Iterant.fromResource]]. */ @@ -207,7 +210,7 @@ object IterantBuilders { /** Aliased builder, see documentation for [[Iterant.repeat]]. */ def repeat[A](elems: A*)(implicit F: Sync[F]): Iterant[F, A] = - Iterant.repeat(elems: _*) + Iterant.repeat(elems*) /** Aliased builder, see documentation for [[Iterant.repeatEval]]. */ def repeatEval[A](thunk: => A)(implicit F: Sync[F]): Iterant[F, A] = @@ -236,8 +239,10 @@ object IterantBuilders { * [[[Iterant.intervalAtFixedRate[F[_]](initialDelay* Iterant.intervalAtFixedRate]]]. */ def intervalAtFixedRate(initialDelay: FiniteDuration, period: FiniteDuration)( - implicit F: Async[F], - timer: Timer[F]): Iterant[F, Long] = + implicit + F: Async[F], + timer: Timer[F] + ): Iterant[F, Long] = Iterant.intervalAtFixedRate(initialDelay, period) /** @@ -252,36 +257,44 @@ object IterantBuilders { * [[[Iterant.intervalWithFixedDelay[F[_]](initialDelay* Iterant.intervalAtFixedRate]]]. */ def intervalWithFixedDelay(initialDelay: FiniteDuration, delay: FiniteDuration)( - implicit F: Async[F], - timer: Timer[F]): Iterant[F, Long] = + implicit + F: Async[F], + timer: Timer[F] + ): Iterant[F, Long] = Iterant.intervalWithFixedDelay(initialDelay, delay) /** Aliased builder, see documentation for [[Iterant.fromReactivePublisher]]. */ def fromReactivePublisher[A]( publisher: Publisher[A], requestCount: Int = recommendedBufferChunkSize, - eagerBuffer: Boolean = true)(implicit F: Async[F]): Iterant[F, A] = + eagerBuffer: Boolean = true + )(implicit F: Async[F]): Iterant[F, A] = Iterant.fromReactivePublisher(publisher, requestCount, eagerBuffer) /** Aliased builder, see documentation for [[Iterant.fromConsumer]]. */ def fromConsumer[A](consumer: ConsumerF[F, Option[Throwable], A], maxBatchSize: Int = recommendedBufferChunkSize)( - implicit F: Async[F]): Iterant[F, A] = + implicit F: Async[F] + ): Iterant[F, A] = Iterant.fromConsumer(consumer, maxBatchSize) /** Aliased builder, see documentation for [[Iterant.fromChannel]]. */ def fromChannel[A]( channel: Channel[F, A], bufferCapacity: BufferCapacity = Bounded(recommendedBufferChunkSize), - maxBatchSize: Int = recommendedBufferChunkSize)(implicit F: Async[F]): Iterant[F, A] = + maxBatchSize: Int = recommendedBufferChunkSize + )(implicit F: Async[F]): Iterant[F, A] = Iterant.fromChannel(channel, bufferCapacity, maxBatchSize) /** Aliased builder, see documentation for [[Iterant.channel]]. */ def channel[A]( bufferCapacity: BufferCapacity = Bounded(recommendedBufferChunkSize), maxBatchSize: Int = recommendedBufferChunkSize, - producerType: ChannelType.ProducerSide = MultiProducer)( - implicit F: Concurrent[F], - cs: ContextShift[F]): F[(ProducerF[F, Option[Throwable], A], Iterant[F, A])] = + producerType: ChannelType.ProducerSide = MultiProducer + )( + implicit + F: Concurrent[F], + cs: ContextShift[F] + ): F[(ProducerF[F, Option[Throwable], A], Iterant[F, A])] = Iterant.channel(bufferCapacity, maxBatchSize, producerType) } } diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/ArrayBatch.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/ArrayBatch.scala index 8ef91a450..f80b19a77 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/ArrayBatch.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/ArrayBatch.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,8 +28,8 @@ final class ArrayBatch[@specialized(Boolean, Byte, Char, Int, Long, Double) A]( ref: Array[A], offset: Int, length: Int, - newBuilder: () => ArrayBuilder[A]) - extends Batch[A] { + newBuilder: () => ArrayBuilder[A] +) extends Batch[A] { def this(ref: Array[A], offset: Int, length: Int)(implicit tag: ClassTag[A]) = this(ref, offset, length, () => ArrayBuilder.make[A]) diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/ArrayCursor.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/ArrayCursor.scala index 8bd3653a3..fd1919d4e 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/ArrayCursor.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/ArrayCursor.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,8 +32,8 @@ final class ArrayCursor[@specialized(Boolean, Byte, Char, Int, Long, Double) A]( _array: Array[A], _offset: Int, _length: Int, - newBuilder: () => ArrayBuilder[A]) - extends BatchCursor[A] { self => + newBuilder: () => ArrayBuilder[A] +) extends BatchCursor[A] { self => require(_offset + _length <= _array.length, "offset + length <= array.length") require(0 <= _offset && _offset <= _array.length, "0 <= offset <= length") @@ -46,8 +46,8 @@ final class ArrayCursor[@specialized(Boolean, Byte, Char, Int, Long, Double) A]( // Int.MaxValue means that arrays can be processed whole override val recommendedBatchSize: Int = Int.MaxValue - private[this] val limit = _offset + _length - private[this] var index: Int = -1 + private val limit = _offset + _length + private var index: Int = -1 def array: Array[A] = _array def offset: Int = _offset diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/Batch.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/Batch.scala index e3274d130..bbf35e226 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/Batch.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/Batch.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -158,7 +158,8 @@ object Batch { */ def fromArray[A](array: Array[A], offset: Int, length: Int): ArrayBatch[A] = { val tp = ClassTag[A](array.getClass.getComponentType) - new ArrayBatch[A](array, offset, length)(tp) + implicit val ct: ClassTag[A] = tp + new ArrayBatch[A](array, offset, length) } /** Converts a Scala [[scala.collection.Iterable Iterable]] into a [[Batch]]. */ diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/BatchCursor.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/BatchCursor.scala index 0bfb5d9f5..df3092a77 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/BatchCursor.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/BatchCursor.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package batches import monix.execution.compat.internal._ import monix.execution.internal.Platform.recommendedBatchSize -import scala.collection.mutable.{ArrayBuffer, ListBuffer} +import scala.collection.mutable.{ ArrayBuffer, ListBuffer } import scala.reflect.ClassTag /** Similar to Java's and Scala's `Iterator`, the `BatchCursor` type can @@ -319,7 +319,8 @@ object BatchCursor { */ def fromArray[A](array: Array[A], offset: Int, length: Int): ArrayCursor[A] = { val tp = ClassTag[A](array.getClass.getComponentType) - new ArrayCursor[A](array, offset, length)(tp) + implicit val ct: ClassTag[A] = tp + new ArrayCursor[A](array, offset, length) } /** $fromAnyArrayDesc @@ -328,14 +329,14 @@ object BatchCursor { * @param offset $paramArrayOffset * @param length $paramArrayLength */ - def fromAnyArray[A](array: Array[_], offset: Int, length: Int): ArrayCursor[A] = + def fromAnyArray[A](array: Array[?], offset: Int, length: Int): ArrayCursor[A] = fromArray(array, offset, length).asInstanceOf[ArrayCursor[A]] /** $fromAnyArrayDesc * * @param array $paramArray */ - def fromAnyArray[A](array: Array[_]): ArrayCursor[A] = + def fromAnyArray[A](array: Array[?]): ArrayCursor[A] = fromAnyArray(array, 0, array.length) /** Builds a [[BatchCursor]] from a Scala `Seq`, with lazy diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/BooleansBatch.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/BooleansBatch.scala index 06c94db2c..3ba1d9b69 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/BooleansBatch.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/BooleansBatch.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/BooleansCursor.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/BooleansCursor.scala index f83c51b7d..af8ebde6c 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/BooleansCursor.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/BooleansCursor.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/BytesBatch.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/BytesBatch.scala index 6ec56d442..08b12529d 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/BytesBatch.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/BytesBatch.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/BytesCursor.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/BytesCursor.scala index 0b0a6f52c..46898b2f3 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/BytesCursor.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/BytesCursor.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/CharsBatch.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/CharsBatch.scala index 208a74226..c490c43a5 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/CharsBatch.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/CharsBatch.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/CharsCursor.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/CharsCursor.scala index 7d7270539..c4a1aa182 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/CharsCursor.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/CharsCursor.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/DoublesBatch.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/DoublesBatch.scala index b4dda98c4..5f8b2f7eb 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/DoublesBatch.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/DoublesBatch.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/DoublesCursor.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/DoublesCursor.scala index b1b5beb8b..166c4bb0a 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/DoublesCursor.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/DoublesCursor.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/EmptyBatch.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/EmptyBatch.scala index 171e1ffee..e9d2903b4 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/EmptyBatch.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/EmptyBatch.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/EmptyCursor.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/EmptyCursor.scala index ce313d939..7d7ce6396 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/EmptyCursor.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/EmptyCursor.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/GenericBatch.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/GenericBatch.scala index 1a4c8feb7..6c8cb2fad 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/GenericBatch.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/GenericBatch.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/GenericCursor.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/GenericCursor.scala index 321ba349a..2a0b8bb46 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/GenericCursor.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/GenericCursor.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,7 +27,7 @@ abstract class GenericCursor[+A] extends BatchCursor[A] { self => if (n <= 0) BatchCursor.empty else new GenericCursor[A] { - private[this] var taken = 0 + private var taken = 0 def hasNext(): Boolean = taken < n && self.hasNext() @@ -46,7 +46,7 @@ abstract class GenericCursor[+A] extends BatchCursor[A] { self => if (n <= 0) self else new GenericCursor[A] { - private[this] var dropped = false + private var dropped = false def hasNext(): Boolean = { if (!dropped) { @@ -54,7 +54,7 @@ abstract class GenericCursor[+A] extends BatchCursor[A] { self => var count = 0 while (count < n) { if (!self.hasNext()) return false - self.next() + val _ = self.next() count += 1 } } @@ -84,8 +84,8 @@ abstract class GenericCursor[+A] extends BatchCursor[A] { self => def filter(p: A => Boolean): BatchCursor[A] = new GenericCursor[A] { - private[this] var item: A = _ - private[this] var hasItem: Boolean = false + private var item: A = null.asInstanceOf[A] + private var hasItem: Boolean = false def hasNext(): Boolean = hasItem || { var continue = true @@ -113,8 +113,8 @@ abstract class GenericCursor[+A] extends BatchCursor[A] { self => def collect[B](pf: PartialFunction[A, B]): BatchCursor[B] = new GenericCursor[B] { - private[this] var item: A = _ - private[this] var hasItem: Boolean = false + private var item: A = null.asInstanceOf[A] + private var hasItem: Boolean = false def hasNext(): Boolean = hasItem || { var continue = true diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/IntegersBatch.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/IntegersBatch.scala index c7c0b5163..514973d4a 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/IntegersBatch.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/IntegersBatch.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/IntegersCursor.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/IntegersCursor.scala index 5a368db9e..a42f29627 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/IntegersCursor.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/IntegersCursor.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/IteratorCursor.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/IteratorCursor.scala index f92c987fa..72266fb92 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/IteratorCursor.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/IteratorCursor.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/LongsBatch.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/LongsBatch.scala index 8562fd357..c5f354f16 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/LongsBatch.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/LongsBatch.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/LongsCursor.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/LongsCursor.scala index 78f76b466..7e9047ccb 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/LongsCursor.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/LongsCursor.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/batches/SeqBatch.scala b/monix-tail/shared/src/main/scala/monix/tail/batches/SeqBatch.scala index 707cdad3f..cdf415ca5 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/batches/SeqBatch.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/batches/SeqBatch.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/AndThen.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/AndThen.scala index 69eb7926b..5abbb782b 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/AndThen.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/AndThen.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/Constants.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/Constants.scala index 67618c162..8ff7c09e0 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/Constants.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/Constants.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantAttempt.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantAttempt.scala index 6b97c528b..4bd468136 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantAttempt.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantAttempt.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,10 +21,10 @@ import cats.effect.Sync import cats.syntax.all._ import monix.execution.atomic.Atomic import monix.execution.internal.Platform -import monix.execution.UncaughtExceptionReporter.{default => Logger} +import monix.execution.UncaughtExceptionReporter.{ default => Logger } import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } +import monix.tail.batches.{ Batch, BatchCursor } import scala.annotation.tailrec import scala.collection.mutable.ArrayBuffer @@ -46,8 +46,8 @@ private[tail] object IterantAttempt { type Attempt = Either[Throwable, A] - private[this] var wasErrorHandled = false - private[this] val handleError = (e: Throwable) => { + private var wasErrorHandled = false + private val handleError = (e: Throwable) => { self.wasErrorHandled = true Left(e): Attempt } @@ -75,12 +75,15 @@ private[tail] object IterantAttempt { Suspend(continueWith(ref.rest)) def visit(ref: Concat[F, A]): Iterant[F, Either[Throwable, A]] = - Concat(ref.lh.map(this), F.defer { - if (self.wasErrorHandled) - F.pure(Iterant.empty[F, Attempt]) - else - ref.rh.map(this) - }) + Concat( + ref.lh.map(this), + F.defer { + if (self.wasErrorHandled) + F.pure(Iterant.empty[F, Attempt]) + else + ref.rh.map(this) + } + ) def visit[S](ref: Scope[F, S, A]): Iterant[F, Attempt] = { val Scope(acquire, use, release) = ref @@ -114,8 +117,9 @@ private[tail] object IterantAttempt { case Left(_) => F.unit case Right(s) => try F.handleError(release(s, exit)) { e => - pushError(errors, e) - } catch { + pushError(errors, e) + } + catch { case NonFatal(e) => F.delay(pushError(errors, e)) } @@ -154,7 +158,7 @@ private[tail] object IterantAttempt { def fail(e: Throwable): Iterant[F, Either[Throwable, A]] = Iterant.raiseError(e) - private[this] val continueMapRef: Either[Throwable, Iterant[F, A]] => Iterant[F, Attempt] = { + private val continueMapRef: Either[Throwable, Iterant[F, A]] => Iterant[F, Attempt] = { case Left(e) => Iterant.now(handleError(e)) case Right(iter) => @@ -167,7 +171,8 @@ private[tail] object IterantAttempt { private def handleCursor( node: NextCursor[F, A], cursor: BatchCursor[A], - rest: F[Iterant[F, A]]): Iterant[F, Attempt] = { + rest: F[Iterant[F, A]] + ): Iterant[F, Attempt] = { try { val array = extractFromCursor(cursor) diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantBuffer.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantBuffer.scala index d72c2743a..649338594 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantBuffer.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantBuffer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ package internal import cats.effect.Sync import cats.syntax.all._ import monix.execution.internal.collection.ChunkedArrayStack -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } import monix.tail.batches.Batch private[tail] object IterantBuffer { @@ -39,7 +39,8 @@ private[tail] object IterantBuffer { count, count, (seq, rest) => NextBatch(Batch.fromArray(seq), rest), - seq => NextBatch(Batch.fromArray(seq), F.pure(Iterant.empty))) + seq => NextBatch(Batch.fromArray(seq), F.pure(Iterant.empty)) + ) } private def build[F[_], A, B]( @@ -47,7 +48,8 @@ private[tail] object IterantBuffer { count: Int, skip: Int, f: (Array[A], F[Iterant[F, B]]) => Iterant[F, B], - last: Array[A] => Iterant[F, B])(implicit F: Sync[F]): Iterant[F, B] = { + last: Array[A] => Iterant[F, B] + )(implicit F: Sync[F]): Iterant[F, B] = { Suspend(F.defer(new BatchVisitor(count, skip, f, last).apply(self))) } @@ -56,11 +58,12 @@ private[tail] object IterantBuffer { count: Int, skip: Int, f: (Array[A], F[Iterant[F, B]]) => Iterant[F, B], - last: Array[A] => Iterant[F, B])(implicit F: Sync[F]) + last: Array[A] => Iterant[F, B] + )(implicit F: Sync[F]) extends Iterant.Visitor[F, A, F[Iterant[F, B]]] { loop => - private[this] val buffer = new Buffer[A](count, skip) - private[this] val stack = ChunkedArrayStack[F[Iterant[F, A]]]() + private val buffer = new Buffer[A](count, skip) + private val stack = ChunkedArrayStack[F[Iterant[F, A]]]() def visit(ref: Next[F, A]): F[Iterant[F, B]] = { val seq = buffer.push(ref.item) @@ -141,13 +144,13 @@ private[tail] object IterantBuffer { } private final class Buffer[A](count: Int, skip: Int) { - private[this] val toDrop = if (count > skip) 0 else skip - count - private[this] val toRepeat = if (skip > count) 0 else count - skip + private val toDrop = if (count > skip) 0 else skip - count + private val toRepeat = if (skip > count) 0 else count - skip - private[this] var isBufferNew = true - private[this] var buffer = new Array[AnyRef](count) - private[this] var dropped = 0 - private[this] var length = 0 + private var isBufferNew = true + private var buffer = new Array[AnyRef](count) + private var dropped = 0 + private var length = 0 def push(elem: A): Array[A] = { if (dropped > 0) { diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantCollect.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantCollect.scala index b644f1d05..bde829862 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantCollect.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantCollect.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantCompleteL.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantCompleteL.scala index 9cd64a870..cf3217994 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantCompleteL.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantCompleteL.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import cats.effect.Sync import cats.syntax.all._ import monix.execution.internal.collection.ChunkedArrayStack import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } import monix.tail.batches.BatchCursor private[tail] object IterantCompleteL { @@ -35,9 +35,9 @@ private[tail] object IterantCompleteL { private final class Loop[F[_], A](implicit F: Sync[F]) extends Iterant.Visitor[F, A, F[Unit]] { - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Used in visit(Concat) - private[this] var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = _ + private var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = null.asInstanceOf[ChunkedArrayStack[F[Iterant[F, A]]]] private def stackPush(item: F[Iterant[F, A]]): Unit = { if (stackRef == null) stackRef = ChunkedArrayStack() @@ -49,13 +49,13 @@ private[tail] object IterantCompleteL { else null.asInstanceOf[F[Iterant[F, A]]] } - private[this] val concatContinue: (Unit => F[Unit]) = + private val concatContinue: (Unit => F[Unit]) = _ => stackPop() match { case null => F.unit case xs => xs.flatMap(this) } - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= def visit(ref: Next[F, A]): F[Unit] = ref.rest.flatMap(this) @@ -90,7 +90,9 @@ private[tail] object IterantCompleteL { F.raiseError(e) private def processCursor(cursor: BatchCursor[A], rest: F[Iterant[F, A]]) = { - while (cursor.hasNext()) cursor.next() + while (cursor.hasNext()) { + val _ = cursor.next() + } rest.flatMap(this) } } diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantConcat.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantConcat.scala index c3bf35212..bc597ca70 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantConcat.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantConcat.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.tail.internal import cats.effect.Sync import cats.syntax.all._ import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } import monix.tail.batches.BatchCursor import scala.util.control.NonFatal diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantConsume.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantConsume.scala index 351c35f47..81f4e7b2a 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantConsume.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantConsume.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,8 +19,8 @@ package monix.tail package internal import cats.implicits._ -import cats.effect.{Concurrent, ContextShift, Resource} -import monix.catnap.{ConcurrentChannel, ConsumerF} +import cats.effect.{ Concurrent, ContextShift, Resource } +import monix.catnap.{ ConcurrentChannel, ConsumerF } import monix.execution.ChannelType.SingleProducer import monix.tail.Iterant.Consumer @@ -29,8 +29,10 @@ private[tail] object IterantConsume { * Implementation for [[Iterant.consume]]. */ def apply[F[_], A](self: Iterant[F, A], cfg: ConsumerF.Config)( - implicit F: Concurrent[F], - cs: ContextShift[F]): Resource[F, Consumer[F, A]] = { + implicit + F: Concurrent[F], + cs: ContextShift[F] + ): Resource[F, Consumer[F, A]] = { /*_*/ val res = Resource.apply { diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDeprecated.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDeprecated.scala index 95120b8aa..862e3624f 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDeprecated.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDeprecated.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDeprecatedBuilders.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDeprecatedBuilders.scala new file mode 100644 index 000000000..c73fa45d6 --- /dev/null +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDeprecatedBuilders.scala @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2014-2022 Monix Contributors. + * See the project homepage at: https://monix.io + * + * 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 monix.tail +package internal +package deprecated + +import cats.Applicative + +private[tail] trait IterantDeprecatedBuilders[F[_]] extends Any { + self: IterantBuilders.Apply[F] => + + /** Binary-compatibility shim — the `Applicative[F]` constraint is no longer needed. + * + * In 3.4.0, `suspend(rest)` required an implicit `Applicative[F]`; in 3.5.0 it does not. + * This overload preserves the old JVM bytecode descriptor so that pre-compiled + * 3.4.0 call-sites remain link-compatible at runtime. + * + * @deprecated Use Iterant.suspend without the implicit instead. + */ + @deprecated("The Applicative[F] constraint is no longer needed; use suspend without it.", "3.5.0") + private[deprecated] def suspend[A](rest: F[Iterant[F, A]])(implicit F: Applicative[F]): Iterant[F, A] = { + // $COVERAGE-OFF$ + Iterant.suspend(rest) + // $COVERAGE-ON$ + } +} diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDistinctUntilChanged.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDistinctUntilChanged.scala index ef81168f9..b97b96923 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDistinctUntilChanged.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDistinctUntilChanged.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import cats.Eq import cats.effect.Sync import cats.syntax.all._ import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } import monix.tail.batches.BatchCursor import scala.collection.mutable.ArrayBuffer @@ -36,7 +36,7 @@ private[tail] object IterantDistinctUntilChanged { private class Loop[F[_], A, K](f: A => K)(implicit F: Sync[F], K: Eq[K]) extends Iterant.Visitor[F, A, Iterant[F, A]] { - private[this] var current: K = null.asInstanceOf[K] + private var current: K = null.asInstanceOf[K] def visit(ref: Next[F, A]): Iterant[F, A] = { val a = ref.item diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDrop.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDrop.scala index 1032acfc4..bdbafb503 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDrop.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDrop.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.tail.internal import cats.effect.Sync import cats.syntax.all._ import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } private[tail] object IterantDrop { /** @@ -32,7 +32,7 @@ private[tail] object IterantDrop { private final class Loop[F[_], A](n: Int)(implicit F: Sync[F]) extends Iterant.Visitor[F, A, Iterant[F, A]] { - private[this] var toDrop: Int = n + private var toDrop: Int = n def visit(ref: Next[F, A]): Iterant[F, A] = if (toDrop <= 0) ref @@ -85,7 +85,7 @@ private[tail] object IterantDrop { var droppedNow = 0 while (droppedNow < limit && cursor.hasNext()) { - cursor.next() + val _ = cursor.next() droppedNow += 1 toDrop -= 1 } diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDropLast.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDropLast.scala index 790ba8339..78fe45d09 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDropLast.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDropLast.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.tail.internal import cats.effect.Sync import cats.syntax.all._ import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } import monix.tail.batches.BatchCursor import scala.annotation.tailrec import scala.collection.immutable.Queue @@ -37,8 +37,8 @@ private[tail] object IterantDropLast { private final class Loop[F[_], A](n: Int)(implicit F: Sync[F]) extends Iterant.Visitor[F, A, Iterant[F, A]] { - private[this] var queue = Queue[A]() - private[this] var length = 0 + private var queue = Queue[A]() + private var length = 0 def visit(ref: Next[F, A]): Iterant[F, A] = { queue = queue.enqueue(ref.item) diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDropWhile.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDropWhile.scala index d66a0c08c..dc26b3004 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDropWhile.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDropWhile.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.tail.internal import cats.effect.Sync import cats.syntax.all._ import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } private[tail] object IterantDropWhile { /** @@ -32,7 +32,7 @@ private[tail] object IterantDropWhile { private class Loop[F[_], A](p: A => Boolean)(implicit F: Sync[F]) extends Iterant.Visitor[F, A, Iterant[F, A]] { - private[this] var dropFinished = false + private var dropFinished = false def visit(ref: Next[F, A]): Iterant[F, A] = if (dropFinished) ref diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDropWhileWithIndex.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDropWhileWithIndex.scala index f8bcf7ba9..f5e510a00 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDropWhileWithIndex.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDropWhileWithIndex.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.tail.internal import cats.effect.Sync import cats.syntax.all._ import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } private[tail] object IterantDropWhileWithIndex { /** @@ -33,8 +33,8 @@ private[tail] object IterantDropWhileWithIndex { private class Loop[F[_], A](p: (A, Int) => Boolean)(implicit F: Sync[F]) extends Iterant.Visitor[F, A, Iterant[F, A]] { loop => - private[this] var index = 0 - private[this] var dropFinished = false + private var index = 0 + private var dropFinished = false private def getAndIncrement(): Int = { val old = index diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDump.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDump.scala index 880e7133c..25657c7d7 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDump.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantDump.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,25 +18,26 @@ package monix.tail.internal import java.io.PrintStream -import cats.effect.{ExitCase, Sync} +import cats.effect.{ ExitCase, Sync } import cats.syntax.all._ import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } private[tail] object IterantDump { /** * Implementation for `Iterant#dump` */ def apply[F[_], A](source: Iterant[F, A], prefix: String, out: PrintStream = System.out)( - implicit F: Sync[F]): Iterant[F, A] = { + implicit F: Sync[F] + ): Iterant[F, A] = { Suspend(F.delay(new Loop(prefix, out).apply(source))) } private class Loop[F[_], A](prefixInit: String, out: PrintStream)(implicit F: Sync[F]) extends Iterant.Visitor[F, A, Iterant[F, A]] { loop => - private[this] var pos = 0L - private[this] var prefix = prefixInit + private var pos = 0L + private var prefix = prefixInit def visit(ref: Next[F, A]): Iterant[F, A] = { out.println(s"$pos: $prefix --> next --> ${ref.item}") @@ -74,13 +75,16 @@ private[tail] object IterantDump { out.println(s"$pos: $prefix --> concat") pos += 1 - Concat(F.defer { - prefix = s"$oldPrefix --> concat-lh ($oldPos)" - moveNext(ref.lh) - }, F.defer { - prefix = oldPrefix - moveNext(ref.rh) - }) + Concat( + F.defer { + prefix = s"$oldPrefix --> concat-lh ($oldPos)" + moveNext(ref.lh) + }, + F.defer { + prefix = oldPrefix + moveNext(ref.rh) + } + ) } def visit[S](ref: Scope[F, S, A]): Iterant[F, A] = { @@ -125,19 +129,19 @@ private[tail] object IterantDump { def moveNext(rest: F[Iterant[F, A]]): F[Iterant[F, A]] = F.guaranteeCase(rest) { - case ExitCase.Error(e) => - F.delay { - out.println(s"$pos: $prefix --> effect error --> $e") - pos += 1 - } - case ExitCase.Canceled => - F.delay { - out.println(s"$pos: $prefix --> effect cancelled") - pos += 1 - } - case ExitCase.Completed => - F.unit - } + case ExitCase.Error(e) => + F.delay { + out.println(s"$pos: $prefix --> effect error --> $e") + pos += 1 + } + case ExitCase.Canceled => + F.delay { + out.println(s"$pos: $prefix --> effect cancelled") + pos += 1 + } + case ExitCase.Completed => + F.unit + } .map(this) } } diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFilter.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFilter.scala index a9ec4aeb0..6f199052c 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFilter.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFilter.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.tail.internal import cats.syntax.all._ import cats.effect.Sync import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } private[tail] object IterantFilter { /** diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFoldLeftL.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFoldLeftL.scala index 8cae58486..3699b0157 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFoldLeftL.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFoldLeftL.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import cats.effect.Sync import cats.syntax.all._ import monix.execution.internal.collection.ChunkedArrayStack import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } import scala.collection.mutable import scala.util.control.NonFatal @@ -58,11 +58,11 @@ private[tail] object IterantFoldLeftL { extends Iterant.Visitor[F, A, F[S]] { loop => /** Current calculated state. */ - private[this] var state = seed + private var state = seed - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Used in visit(Concat) - private[this] var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = _ + private var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = null.asInstanceOf[ChunkedArrayStack[F[Iterant[F, A]]]] private def stackPush(item: F[Iterant[F, A]]): Unit = { if (stackRef == null) stackRef = ChunkedArrayStack() @@ -74,13 +74,13 @@ private[tail] object IterantFoldLeftL { else null.asInstanceOf[F[Iterant[F, A]]] } - private[this] val concatContinue: (S => F[S]) = + private val concatContinue: (S => F[S]) = state => stackPop() match { case null => F.pure(state) case xs => xs.flatMap(loop) } - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= def visit(ref: Next[F, A]): F[S] = { state = op(state, ref.item) diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFoldRightL.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFoldRightL.scala index c2995f86c..ba8bc9054 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFoldRightL.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFoldRightL.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import cats.effect.Sync import cats.syntax.all._ import monix.execution.internal.collection.ChunkedArrayStack import monix.tail.Iterant -import monix.tail.Iterant.{Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } private[tail] object IterantFoldRightL { /** Implementation for `Iterant.foldRightL`. */ @@ -31,12 +31,12 @@ private[tail] object IterantFoldRightL { private final class Loop[F[_], A, B](b: F[B], f: (A, F[B]) => F[B])(implicit F: Sync[F]) extends Iterant.Visitor[F, A, F[B]] { self => - private[this] var remainder: Iterant[F, A] = _ - private[this] var suspendRef: F[B] = _ + private var remainder: Iterant[F, A] = null.asInstanceOf[Iterant[F, A]] + private var suspendRef: F[B] = null.asInstanceOf[F[B]] - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Used in visit(Concat) - private[this] var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = _ + private var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = null.asInstanceOf[ChunkedArrayStack[F[Iterant[F, A]]]] private def stackPush(item: F[Iterant[F, A]]): Unit = { if (stackRef == null) stackRef = ChunkedArrayStack() @@ -53,7 +53,7 @@ private[tail] object IterantFoldRightL { case xs => xs.flatMap(this) } } - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= def visit(ref: Next[F, A]): F[B] = f(ref.item, ref.rest.flatMap(this)) diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFoldWhileLeftL.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFoldWhileLeftL.scala index 9cf7e27ef..c9482d9d1 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFoldWhileLeftL.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFoldWhileLeftL.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ package internal import cats.effect.Sync import cats.syntax.all._ import monix.execution.internal.collection.ChunkedArrayStack -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } import monix.tail.batches.BatchCursor private[tail] object IterantFoldWhileLeftL { @@ -54,11 +54,11 @@ private[tail] object IterantFoldWhileLeftL { private class StrictLoop[F[_], A, S](seed: S, f: (S, A) => Either[S, S])(implicit F: Sync[F]) extends Iterant.Visitor[F, A, F[Either[S, S]]] { self => - private[this] var state: S = seed + private var state: S = seed - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Used in visit(Concat) - private[this] var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = _ + private var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = null.asInstanceOf[ChunkedArrayStack[F[Iterant[F, A]]]] private def stackPush(item: F[Iterant[F, A]]): Unit = { if (stackRef == null) stackRef = ChunkedArrayStack() @@ -70,7 +70,7 @@ private[tail] object IterantFoldWhileLeftL { else null.asInstanceOf[F[Iterant[F, A]]] } - private[this] val concatContinue: (Either[S, S] => F[Either[S, S]]) = { + private val concatContinue: (Either[S, S] => F[Either[S, S]]) = { case left @ Left(_) => stackPop() match { case null => F.pure(left) @@ -79,7 +79,7 @@ private[tail] object IterantFoldWhileLeftL { case right => F.pure(right) } - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= def visit(ref: Next[F, A]): F[Either[S, S]] = f(state, ref.item) match { @@ -151,11 +151,11 @@ private[tail] object IterantFoldWhileLeftL { private class LazyLoop[F[_], A, S](seed: S, f: (S, A) => F[Either[S, S]])(implicit F: Sync[F]) extends Iterant.Visitor[F, A, F[Either[S, S]]] { self => - private[this] var state: S = seed + private var state: S = seed - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Used in visit(Concat) - private[this] var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = _ + private var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = null.asInstanceOf[ChunkedArrayStack[F[Iterant[F, A]]]] private def stackPush(item: F[Iterant[F, A]]): Unit = { if (stackRef == null) stackRef = ChunkedArrayStack() @@ -167,7 +167,7 @@ private[tail] object IterantFoldWhileLeftL { else null.asInstanceOf[F[Iterant[F, A]]] } - private[this] val concatContinue: (Either[S, S] => F[Either[S, S]]) = { + private val concatContinue: (Either[S, S] => F[Either[S, S]]) = { case left @ Left(_) => stackPop() match { case null => F.pure(left) @@ -176,7 +176,7 @@ private[tail] object IterantFoldWhileLeftL { case right => F.pure(right) } - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= def visit(ref: Next[F, A]): F[Either[S, S]] = f(state, ref.item).flatMap { diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFromConsumer.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFromConsumer.scala index 50ffca7af..6220e2184 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFromConsumer.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFromConsumer.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.tail.internal import cats.effect.Async import monix.catnap.ConsumerF import monix.tail.Iterant -import monix.tail.Iterant.{haltS, suspendS, Next, NextBatch} +import monix.tail.Iterant.{ haltS, suspendS, Next, NextBatch } import monix.tail.batches.Batch private[tail] object IterantFromConsumer { @@ -28,7 +28,8 @@ private[tail] object IterantFromConsumer { * Implementation for [[Iterant.fromConsumer]]. */ def apply[F[_], A](consumer: ConsumerF[F, Option[Throwable], A], maxBatchSize: Int)( - implicit F: Async[F]): Iterant[F, A] = { + implicit F: Async[F] + ): Iterant[F, A] = { suspendS( if (maxBatchSize > 1) @@ -47,7 +48,8 @@ private[tail] object IterantFromConsumer { } private def loopMany[F[_], A](consumer: ConsumerF[F, Option[Throwable], A], maxBatchSize: Int)( - implicit F: Async[F]): F[Iterant[F, A]] = { + implicit F: Async[F] + ): F[Iterant[F, A]] = { F.map(consumer.pullMany(1, maxBatchSize)) { case Left(e) => haltS(e) diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFromReactivePublisher.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFromReactivePublisher.scala index 17da5a9e5..0ef52faaf 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFromReactivePublisher.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantFromReactivePublisher.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,9 +22,9 @@ import monix.execution.atomic.Atomic import monix.execution.atomic.PaddingStrategy.LeftRight128 import monix.execution.rstreams.SingleAssignSubscription import monix.tail.Iterant -import monix.tail.Iterant.{Last, Next, NextBatch, Scope} +import monix.tail.Iterant.{ Last, Next, NextBatch, Scope } import monix.tail.batches.Batch -import org.reactivestreams.{Publisher, Subscriber, Subscription} +import org.reactivestreams.{ Publisher, Subscriber, Subscription } import scala.annotation.tailrec import scala.collection.immutable.Queue @@ -33,7 +33,8 @@ private[tail] object IterantFromReactivePublisher { * Implementation for `Iterant.fromReactivePublisher`. */ def apply[F[_], A](pub: Publisher[A], requestCount: Int, eagerBuffer: Boolean)( - implicit F: Async[F]): Iterant[F, A] = { + implicit F: Async[F] + ): Iterant[F, A] = { if (requestCount < 1) { Iterant.raiseError(new IllegalArgumentException("requestSize must be greater than 1")) @@ -52,8 +53,8 @@ private[tail] object IterantFromReactivePublisher { private final class IterantSubscriber[F[_], A](bufferSize: Int, eagerBuffer: Boolean)(implicit F: Async[F]) extends Subscriber[A] { - private[this] val sub = SingleAssignSubscription() - private[this] val state = Atomic.withPadding(Uninitialized: State[F, A], LeftRight128) + private val sub = SingleAssignSubscription() + private val state = Atomic.withPadding(Uninitialized: State[F, A], LeftRight128) def start: F[Iterant[F, A]] = F.async { cb => @@ -71,7 +72,7 @@ private[tail] object IterantFromReactivePublisher { private def initialize(): Boolean = state.compareAndSet(Uninitialized, Empty(bufferSize)) - private[this] val generate: (Int => F[Iterant[F, A]]) = { + private val generate: (Int => F[Iterant[F, A]]) = { if (eagerBuffer) { val task = F.async[Iterant[F, A]](take) toReceive => { @@ -105,7 +106,7 @@ private[tail] object IterantFromReactivePublisher { @tailrec def onNext(a: A): Unit = state.get() match { case Uninitialized => - initialize() + val _ = initialize() onNext(a) case current @ Enqueue(queue, length, toReceive) => @@ -130,7 +131,7 @@ private[tail] object IterantFromReactivePublisher { @tailrec private def finish(fa: Iterant[F, A]): Unit = state.get() match { case Uninitialized => - initialize() + val _ = initialize() finish(fa) case current @ Enqueue(queue, length, _) => @@ -148,7 +149,7 @@ private[tail] object IterantFromReactivePublisher { finish(fa) } - case current : Take[F, A] @unchecked => + case current: Take[F, A] @unchecked => if (state.compareAndSet(current, Stop(fa))) current.cb(Right(fa)) else @@ -170,7 +171,7 @@ private[tail] object IterantFromReactivePublisher { @tailrec private def take(cb: Either[Throwable, Iterant[F, A]] => Unit): Unit = state.get() match { case Uninitialized => - initialize() + val _ = initialize() take(cb) case current @ Enqueue(queue, length, toReceive) => diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantHeadOptionL.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantHeadOptionL.scala index dc14bba70..c1fed0b96 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantHeadOptionL.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantHeadOptionL.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import cats.effect.Sync import cats.syntax.all._ import monix.execution.internal.collection.ChunkedArrayStack import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } import monix.tail.batches.BatchCursor private[tail] object IterantHeadOptionL { @@ -40,9 +40,9 @@ private[tail] object IterantHeadOptionL { private final class Loop[F[_], A](implicit F: Sync[F]) extends Iterant.Visitor[F, A, F[Option[A]]] { - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Used in visit(Concat) - private[this] var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = _ + private var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = null.asInstanceOf[ChunkedArrayStack[F[Iterant[F, A]]]] private def stackPush(item: F[Iterant[F, A]]): Unit = { if (stackRef == null) stackRef = ChunkedArrayStack() @@ -54,7 +54,7 @@ private[tail] object IterantHeadOptionL { else null.asInstanceOf[F[Iterant[F, A]]] } - private[this] val concatContinue: (Option[A] => F[Option[A]]) = { + private val concatContinue: (Option[A] => F[Option[A]]) = { case None => stackPop() match { case null => F.pure(None) @@ -63,7 +63,7 @@ private[tail] object IterantHeadOptionL { case some => F.pure(some) } - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= def visit(ref: Next[F, A]): F[Option[A]] = F.pure(Some(ref.item)) diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantInterleave.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantInterleave.scala index 03adfe3ad..c08f63951 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantInterleave.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantInterleave.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import cats.effect.Sync import cats.syntax.all._ import monix.execution.internal.collection.ChunkedArrayStack import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } private[tail] object IterantInterleave { /** @@ -36,11 +36,11 @@ private[tail] object IterantInterleave { def apply(lh: Iterant[F, A], rh: Iterant[F, A]): Iterant[F, A] = lhLoop.visit(lh, rh) - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Used by Concat: - private[this] var _lhStack: ChunkedArrayStack[F[Iterant[F, A]]] = _ - private[this] var _rhStack: ChunkedArrayStack[F[Iterant[F, A]]] = _ + private var _lhStack: ChunkedArrayStack[F[Iterant[F, A]]] = null.asInstanceOf[ChunkedArrayStack[F[Iterant[F, A]]]] + private var _rhStack: ChunkedArrayStack[F[Iterant[F, A]]] = null.asInstanceOf[ChunkedArrayStack[F[Iterant[F, A]]]] private def lhStackPush(ref: F[Iterant[F, A]]): Unit = { if (_lhStack == null) _lhStack = ChunkedArrayStack() @@ -60,15 +60,15 @@ private[tail] object IterantInterleave { if (_rhStack == null) null.asInstanceOf[F[Iterant[F, A]]] else _rhStack.pop() - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - private[this] val lhLoop = new LHLoop - private[this] val rhLoop = new RHLoop + private val lhLoop = new LHLoop + private val rhLoop = new RHLoop - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= private final class LHLoop extends Iterant.Visitor[F, A, Iterant[F, A]] { - protected var rhRef: F[Iterant[F, A]] = _ + protected var rhRef: F[Iterant[F, A]] = null.asInstanceOf[F[Iterant[F, A]]] def continue(lh: F[Iterant[F, A]], rh: F[Iterant[F, A]]): F[Iterant[F, A]] = { rhRef = rh @@ -135,7 +135,7 @@ private[tail] object IterantInterleave { } private final class RHLoop extends Iterant.Visitor[F, A, Iterant[F, A]] { - protected var lhRef: F[Iterant[F, A]] = _ + protected var lhRef: F[Iterant[F, A]] = null.asInstanceOf[F[Iterant[F, A]]] def continue(lh: F[Iterant[F, A]], rh: F[Iterant[F, A]]): F[Iterant[F, A]] = { lhRef = lh diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantIntersperse.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantIntersperse.scala index b686ff0c6..37812c8f6 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantIntersperse.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantIntersperse.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,57 +35,58 @@ private[tail] object IterantIntersperse { } private class Loop[F[_], A](separator: A)(implicit F: Sync[F]) extends (Iterant[F, A] => Iterant[F, A]) { - private[this] var prepend = false - private[this] val stack = ChunkedArrayStack[F[Iterant[F, A]]]() + private var prepend = false + private val stack = ChunkedArrayStack[F[Iterant[F, A]]]() def apply(source: Iterant[F, A]): Iterant[F, A] = { try source match { - case halt @ Halt(opt) => - val next = stack.pop() - if (opt.nonEmpty || next == null) { - halt - } else { - Suspend(next.map(this)) - } - - case Suspend(rest) => - Suspend(rest.map(this)) - - case NextCursor(cursor, rest) if !cursor.hasNext() => - Suspend(rest.map(this)) - - case NextBatch(batch, rest) if !batch.cursor().hasNext() => - Suspend(rest.map(this)) - - case Concat(lh, rh) => - stack.push(rh) - Suspend(lh.map(this)) - - case b @ Scope(_, _, _) => - b.runMap(this) - - case _ if prepend => - prepend = false - Next(separator, F.pure(source).map(this)) - - case ref @ NextCursor(_, _) => - processNonEmptyCursor(ref) - - case NextBatch(batch, rest) => - processNonEmptyCursor(NextCursor(batch.cursor(), rest)) - - case Next(item, rest) => - prepend = true - Next(item, rest.map(this)) - - case last @ Last(a) => - stack.pop() match { - case null => last - case some => - prepend = true - Next(a, some.map(this)) - } - } catch { + case halt @ Halt(opt) => + val next = stack.pop() + if (opt.nonEmpty || next == null) { + halt + } else { + Suspend(next.map(this)) + } + + case Suspend(rest) => + Suspend(rest.map(this)) + + case NextCursor(cursor, rest) if !cursor.hasNext() => + Suspend(rest.map(this)) + + case NextBatch(batch, rest) if !batch.cursor().hasNext() => + Suspend(rest.map(this)) + + case Concat(lh, rh) => + stack.push(rh) + Suspend(lh.map(this)) + + case b @ Scope(_, _, _) => + b.runMap(this) + + case _ if prepend => + prepend = false + Next(separator, F.pure(source).map(this)) + + case ref @ NextCursor(_, _) => + processNonEmptyCursor(ref) + + case NextBatch(batch, rest) => + processNonEmptyCursor(NextCursor(batch.cursor(), rest)) + + case Next(item, rest) => + prepend = true + Next(item, rest.map(this)) + + case last @ Last(a) => + stack.pop() match { + case null => last + case some => + prepend = true + Next(a, some.map(this)) + } + } + catch { case ex if NonFatal(ex) => Halt(Some(ex)) } diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantIntervalAtFixedRate.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantIntervalAtFixedRate.scala index 6accac848..6c928a071 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantIntervalAtFixedRate.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantIntervalAtFixedRate.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.tail.internal import cats.syntax.all._ -import cats.effect.{Async, Clock, Timer} +import cats.effect.{ Async, Clock, Timer } import monix.tail.Iterant import monix.tail.Iterant.Suspend import scala.concurrent.duration._ @@ -29,7 +29,8 @@ private[tail] object IterantIntervalAtFixedRate { */ def apply[F[_]]( initialDelay: FiniteDuration, - interval: FiniteDuration)(implicit F: Async[F], timer: Timer[F], clock: Clock[F]): Iterant[F, Long] = { + interval: FiniteDuration + )(implicit F: Async[F], timer: Timer[F], clock: Clock[F]): Iterant[F, Long] = { def loop(time: F[Long], index: Long): F[Iterant[F, Long]] = time.map { startTime => diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantIntervalWithFixedDelay.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantIntervalWithFixedDelay.scala index da9168a8b..74ea61dfd 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantIntervalWithFixedDelay.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantIntervalWithFixedDelay.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.tail.internal -import cats.effect.{Async, Timer} +import cats.effect.{ Async, Timer } import monix.tail.Iterant import scala.concurrent.duration._ @@ -26,8 +26,10 @@ private[tail] object IterantIntervalWithFixedDelay { * Implementation for `Iterant.intervalWithFixedDelay`. */ def apply[F[_]](initialDelay: FiniteDuration, delay: FiniteDuration)( - implicit F: Async[F], - timer: Timer[F]): Iterant[F, Long] = { + implicit + F: Async[F], + timer: Timer[F] + ): Iterant[F, Long] = { // Recursive loop def loop(index: Long): Iterant[F, Long] = { diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantLiftMap.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantLiftMap.scala index ae7cdadf7..76fc6e358 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantLiftMap.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantLiftMap.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import cats.arrow.FunctionK import cats.effect.Sync import cats.syntax.all._ import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } private[tail] object IterantLiftMap { /** Implementation for `Iterant#liftMap`. */ @@ -52,7 +52,8 @@ private[tail] object IterantLiftMap { Scope[G, S, A]( f(ref.acquire), s => G.defer(f(ref.use(s)).map(this)), - (s, exitCase) => f(ref.release(s, exitCase))) + (s, exitCase) => f(ref.release(s, exitCase)) + ) def visit(ref: Last[F, A]): Iterant[G, A] = ref.asInstanceOf[Iterant[G, A]] diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantMap.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantMap.scala index ff8161a77..c67c0cc2b 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantMap.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantMap.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.tail.internal import cats.syntax.all._ import cats.effect.Sync import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } private[tail] object IterantMap { /** diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantMapBatch.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantMapBatch.scala index 25266e02e..849726117 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantMapBatch.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantMapBatch.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.tail.internal import cats.effect.Sync import cats.syntax.all._ import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } import monix.tail.batches.Batch private[tail] object IterantMapBatch { diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantMapEval.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantMapEval.scala index 037d1c47c..d67301de5 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantMapEval.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantMapEval.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -36,8 +36,8 @@ private[tail] object IterantMapEval { private final class Loop[F[_], A, B](ff: A => F[B])(implicit F: Sync[F]) extends Iterant.Visitor[F, A, Iterant[F, B]] { self => - private[this] var restRef: F[Iterant[F, A]] = _ - private[this] val continueRef = (b: B) => nextS(b, self.restRef.map(self)) + private var restRef: F[Iterant[F, A]] = null.asInstanceOf[F[Iterant[F, A]]] + private val continueRef = (b: B) => nextS(b, self.restRef.map(self)) private def continue(rest: F[Iterant[F, A]]) = { this.restRef = rest diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantOnErrorHandleWith.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantOnErrorHandleWith.scala index fcc4452ad..14186f7a7 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantOnErrorHandleWith.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantOnErrorHandleWith.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,8 +22,8 @@ import cats.effect.Sync import cats.syntax.all._ import monix.execution.atomic.Atomic import monix.execution.internal.Platform -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } +import monix.tail.batches.{ Batch, BatchCursor } import scala.annotation.tailrec import scala.collection.mutable.ArrayBuffer @@ -41,9 +41,9 @@ private[tail] object IterantOnErrorHandleWith { private final class Loop[F[_], A](handler: Throwable => Iterant[F, A])(implicit F: Sync[F]) extends Iterant.Visitor[F, A, Iterant[F, A]] { self => - private[this] var wasErrorHandled = false + private var wasErrorHandled = false - private[this] val f = (e: Throwable) => { + private val f = (e: Throwable) => { self.wasErrorHandled = true try handler(e) catch { @@ -89,12 +89,15 @@ private[tail] object IterantOnErrorHandleWith { Suspend(continueWith(ref.rest)) def visit(ref: Concat[F, A]): Iterant[F, A] = - Concat(ref.lh.map(this), F.defer { - if (self.wasErrorHandled) - F.pure(Iterant.empty[F, A]) - else - ref.rh.map(this) - }) + Concat( + ref.lh.map(this), + F.defer { + if (self.wasErrorHandled) + F.pure(Iterant.empty[F, A]) + else + ref.rh.map(this) + } + ) def visit[S](ref: Scope[F, S, A]): Iterant[F, A] = { val Scope(acquire, use, release) = ref @@ -128,8 +131,9 @@ private[tail] object IterantOnErrorHandleWith { case Left(_) => F.unit case Right(s) => try F.handleError(release(s, exit)) { e => - pushError(errors, e) - } catch { + pushError(errors, e) + } + catch { case NonFatal(e) => F.delay(pushError(errors, e)) } @@ -137,14 +141,17 @@ private[tail] object IterantOnErrorHandleWith { } ) - Concat(F.pure(lh), F.delay { - val err = errors.getAndSet(null) - if (err != null && !wasErrorHandled) { - f(err) - } else { - Iterant.empty + Concat( + F.pure(lh), + F.delay { + val err = errors.getAndSet(null) + if (err != null && !wasErrorHandled) { + f(err) + } else { + Iterant.empty + } } - }) + ) }) } diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantPushToChannel.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantPushToChannel.scala index e2a4757a8..db0f25254 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantPushToChannel.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantPushToChannel.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,7 +28,8 @@ private[tail] object IterantPushToChannel { * Implementation for [[Iterant.pushToChannel]]. */ def apply[F[_], A](source: Iterant[F, A], channel: ProducerF[F, Option[Throwable], A])( - implicit F: Sync[F]): F[Unit] = { + implicit F: Sync[F] + ): F[Unit] = { F.defer(new Loop(channel).apply(source)) } @@ -36,10 +37,10 @@ private[tail] object IterantPushToChannel { private final class Loop[F[_], A](channel: ProducerF[F, Option[Throwable], A])(implicit F: Sync[F]) extends Iterant.Visitor[F, A, F[Unit]] { loop => - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // For dealing with push results - private[this] val trueRef = F.pure(true) - private[this] var rest: F[Iterant[F, A]] = _ + private val trueRef = F.pure(true) + private var rest: F[Iterant[F, A]] = null.asInstanceOf[F[Iterant[F, A]]] private val bindNext = (continue: Boolean) => { if (continue) F.flatMap(rest)(loop) else F.unit @@ -50,9 +51,9 @@ private[tail] object IterantPushToChannel { F.flatMap(task)(bindNext) } - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Used in visit(Concat) - private[this] var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = _ + private var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = null.asInstanceOf[ChunkedArrayStack[F[Iterant[F, A]]]] private def stackPush(item: F[Iterant[F, A]]): Unit = { if (stackRef == null) stackRef = ChunkedArrayStack() @@ -67,13 +68,13 @@ private[tail] object IterantPushToChannel { private def isStackEmpty(): Boolean = stackRef == null || stackRef.isEmpty - private[this] val concatContinue: (Unit => F[Unit]) = + private val concatContinue: (Unit => F[Unit]) = _ => stackPop() match { case null => F.unit case xs => F.flatMap(xs)(loop) } - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= def visit(ref: Iterant.Next[F, A]): F[Unit] = process(channel.push(ref.item), ref.rest) diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantReduce.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantReduce.scala index 9880e305f..cbb13ae60 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantReduce.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantReduce.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ package internal import cats.effect.Sync import cats.syntax.all._ import monix.execution.internal.collection.ChunkedArrayStack -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } private[tail] object IterantReduce { /** Implementation for `Iterant.reduce`. */ @@ -32,12 +32,12 @@ private[tail] object IterantReduce { private class Loop[F[_], A](op: (A, A) => A)(implicit F: Sync[F]) extends Iterant.Visitor[F, A, F[Option[A]]] { - private[this] var isEmpty = true - private[this] var state: A = _ + private var isEmpty = true + private var state: A = null.asInstanceOf[A] - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Used in visit(Concat) - private[this] var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = _ + private var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = null.asInstanceOf[ChunkedArrayStack[F[Iterant[F, A]]]] private def stackPush(item: F[Iterant[F, A]]): Unit = { if (stackRef == null) stackRef = ChunkedArrayStack() @@ -49,13 +49,13 @@ private[tail] object IterantReduce { else null.asInstanceOf[F[Iterant[F, A]]] } - private[this] val concatContinue: (Option[A] => F[Option[A]]) = + private val concatContinue: (Option[A] => F[Option[A]]) = state => stackPop() match { case null => F.pure(state) case xs => xs.flatMap(this) } - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= def visit(ref: Next[F, A]): F[Option[A]] = { if (isEmpty) { diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantRepeat.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantRepeat.scala index d0e6265d9..f902152e1 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantRepeat.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantRepeat.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,8 +21,8 @@ import cats.effect.Sync import cats.syntax.all._ import monix.execution.internal.Platform import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} -import monix.tail.batches.{BatchCursor, GenericBatch, GenericCursor} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } +import monix.tail.batches.{ BatchCursor, GenericBatch, GenericCursor } private[tail] object IterantRepeat { /** @@ -52,8 +52,8 @@ private[tail] object IterantRepeat { private final class Loop[F[_], A](source: Iterant[F, A])(implicit F: Sync[F]) extends Iterant.Visitor[F, A, Iterant[F, A]] { - private[this] var hasElements = false - private[this] val repeatTask = F.delay { + private var hasElements = false + private val repeatTask = F.delay { if (hasElements) cycle() else diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantRetryIfEmpty.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantRetryIfEmpty.scala index d3dea100f..9a66ffb86 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantRetryIfEmpty.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantRetryIfEmpty.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package internal import cats.effect.Sync import cats.syntax.all._ -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } private[tail] object IterantRetryIfEmpty { /** @@ -41,9 +41,9 @@ private[tail] object IterantRetryIfEmpty { private final class Loop[F[_], A](source: Iterant[F, A], maxRetries: Option[Int])(implicit F: Sync[F]) extends Iterant.Visitor[F, A, Iterant[F, A]] { - private[this] var hasElements = false - private[this] var retriesRemaining = maxRetries.getOrElse(-1) - private[this] val retryTask = F.delay { + private var hasElements = false + private var retriesRemaining = maxRetries.getOrElse(-1) + private val retryTask = F.delay { if (hasElements || retriesRemaining == 0) Iterant.empty[F, A] else { diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantScan.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantScan.scala index a4ca09334..326bcf144 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantScan.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantScan.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ import cats.syntax.all._ import monix.execution.internal.collection.ChunkedArrayStack import scala.util.control.NonFatal -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } import monix.tail.batches.BatchCursor import scala.collection.mutable.ArrayBuffer @@ -42,8 +42,8 @@ private[tail] object IterantScan { class Loop[F[_], A, S](initial: S, f: (S, A) => S)(implicit F: Sync[F]) extends Iterant.Visitor[F, A, Iterant[F, S]] { - private[this] var state = initial - private[this] var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = _ + private var state = initial + private var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = null.asInstanceOf[ChunkedArrayStack[F[Iterant[F, A]]]] private def stackPush(item: F[Iterant[F, A]]): Unit = { if (stackRef == null) stackRef = ChunkedArrayStack() @@ -101,7 +101,7 @@ private[tail] object IterantScan { def fail(e: Throwable): Iterant[F, S] = Iterant.raiseError(e) - private[this] def processCursor(cursor: BatchCursor[A], rest: F[Iterant[F, A]]) = { + private def processCursor(cursor: BatchCursor[A], rest: F[Iterant[F, A]]) = { if (!cursor.hasNext()) { Suspend(rest.map(this)) } else if (cursor.recommendedBatchSize <= 1) { diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantScanEval.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantScanEval.scala index cfa9d2da8..904e423fd 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantScanEval.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantScanEval.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -37,8 +37,8 @@ private[tail] object IterantScanEval { private class Loop[F[_], S, A](seed: S, ff: (S, A) => F[S])(implicit F: Sync[F]) extends Iterant.Visitor[F, A, Iterant[F, S]] { - private[this] var state: S = seed - private[this] var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = _ + private var state: S = seed + private var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = null.asInstanceOf[ChunkedArrayStack[F[Iterant[F, A]]]] private def stackPush(item: F[Iterant[F, A]]): Unit = { if (stackRef == null) stackRef = ChunkedArrayStack() diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantSwitchIfEmpty.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantSwitchIfEmpty.scala index cae11fb61..1d59fc1c2 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantSwitchIfEmpty.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantSwitchIfEmpty.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -45,10 +45,10 @@ private[tail] object IterantSwitchIfEmpty { private final class Loop[F[_], A](backup: Iterant[F, A])(implicit F: Sync[F]) extends Iterant.Visitor[F, A, Iterant[F, A]] { self => - private[this] var isEmpty = true - private[this] var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = _ + private var isEmpty = true + private var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = null.asInstanceOf[ChunkedArrayStack[F[Iterant[F, A]]]] - private[this] def isStackEmpty: Boolean = + private def isStackEmpty: Boolean = stackRef == null || stackRef.isEmpty private def stackPush(item: F[Iterant[F, A]]): Unit = { diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTail.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTail.scala index f589aeffa..9bcf6c708 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTail.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTail.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.tail.internal import cats.effect.Sync import monix.tail.Iterant -import monix.tail.Iterant.{Last, Next, Suspend} +import monix.tail.Iterant.{ Last, Next, Suspend } private[tail] object IterantTail { /** diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTake.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTake.scala index ce5d19b52..cb459fda6 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTake.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTake.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.tail.internal import cats.effect.Sync import cats.syntax.all._ import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } import monix.tail.batches.BatchCursor import scala.collection.mutable.ArrayBuffer @@ -38,7 +38,7 @@ private[tail] object IterantTake { private final class Loop[F[_], A](n: Int)(implicit F: Sync[F]) extends Iterant.Visitor[F, A, Iterant[F, A]] { - private[this] var toTake = n + private var toTake = n def visit(ref: Next[F, A]): Iterant[F, A] = { toTake -= 1 @@ -85,12 +85,15 @@ private[tail] object IterantTake { Suspend(ref.rest.map(this)) def visit(ref: Concat[F, A]): Iterant[F, A] = - Concat(ref.lh.map(this), F.defer { - if (this.toTake > 0) - ref.rh.map(this) - else - F.pure(Iterant.empty) - }) + Concat( + ref.lh.map(this), + F.defer { + if (this.toTake > 0) + ref.rh.map(this) + else + F.pure(Iterant.empty) + } + ) def visit[R](ref: Scope[F, R, A]): Iterant[F, A] = ref.runMap(this) diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTakeEveryNth.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTakeEveryNth.scala index b59096c56..420efe3b6 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTakeEveryNth.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTakeEveryNth.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.tail.internal import cats.effect.Sync import cats.syntax.all._ import monix.tail.Iterant -import monix.tail.Iterant.{Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } import monix.tail.batches.BatchCursor import scala.collection.mutable.ArrayBuffer @@ -38,7 +38,7 @@ private[tail] object IterantTakeEveryNth { } private final class Loop[F[_], A](n: Int)(implicit F: Sync[F]) extends Iterant.Visitor[F, A, Iterant[F, A]] { - private[this] var index = n + private var index = n def visit(ref: Next[F, A]): Iterant[F, A] = { if (index == 1) { @@ -94,7 +94,7 @@ private[tail] object IterantTakeEveryNth { buffer += cursor.next() idx = n } else { - cursor.next() + val _ = cursor.next() idx -= 1 } toProcess -= 1 diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTakeLast.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTakeLast.scala index f53f7d75d..0136a846f 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTakeLast.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTakeLast.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,9 +19,9 @@ package monix.tail.internal import cats.effect.Sync import cats.syntax.all._ -import monix.execution.internal.collection.{ChunkedArrayStack, DropHeadOnOverflowQueue} +import monix.execution.internal.collection.{ ChunkedArrayStack, DropHeadOnOverflowQueue } import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } import monix.tail.batches.BatchCursor private[tail] object IterantTakeLast { @@ -38,7 +38,7 @@ private[tail] object IterantTakeLast { private class Loop[F[_], A](n: Int)(implicit F: Sync[F]) extends Iterant.Visitor[F, A, Iterant[F, A]] { loop => private val buffer = DropHeadOnOverflowQueue.boxed[A](n) - private[this] var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = _ + private var stackRef: ChunkedArrayStack[F[Iterant[F, A]]] = null.asInstanceOf[ChunkedArrayStack[F[Iterant[F, A]]]] private def stackPush(item: F[Iterant[F, A]]): Unit = { if (stackRef == null) stackRef = ChunkedArrayStack() @@ -51,19 +51,23 @@ private[tail] object IterantTakeLast { } def visit(ref: Next[F, A]): Iterant[F, A] = { - buffer.offer(ref.item) + val _ = buffer.offer(ref.item) Suspend(ref.rest.map(loop)) } def visit(ref: NextBatch[F, A]): Iterant[F, A] = { val cursor = ref.batch.cursor() - while (cursor.hasNext()) buffer.offer(cursor.next()) + while (cursor.hasNext()) { + val _ = buffer.offer(cursor.next()) + } Suspend(ref.rest.map(loop)) } def visit(ref: NextCursor[F, A]): Iterant[F, A] = { val cursor = ref.cursor - while (cursor.hasNext()) buffer.offer(cursor.next()) + while (cursor.hasNext()) { + val _ = buffer.offer(cursor.next()) + } Suspend(ref.rest.map(loop)) } @@ -81,7 +85,7 @@ private[tail] object IterantTakeLast { def visit(ref: Last[F, A]): Iterant[F, A] = stackPop() match { case null => - buffer.offer(ref.item) + val _ = buffer.offer(ref.item) finalCursor() case some => loop(Next(ref.item, some)) diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTakeWhile.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTakeWhile.scala index 078e73e64..612bea42b 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTakeWhile.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTakeWhile.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,7 +31,7 @@ private[tail] object IterantTakeWhile { private class Loop[F[_], A](p: A => Boolean)(implicit F: Sync[F]) extends Iterant.Visitor[F, A, Iterant[F, A]] { - private[this] var isActive = true + private var isActive = true def visit(ref: Next[F, A]): Iterant[F, A] = { val item = ref.item @@ -50,12 +50,15 @@ private[tail] object IterantTakeWhile { Suspend(ref.rest.map(this)) def visit(ref: Concat[F, A]): Iterant[F, A] = - Concat(ref.lh.map(this), F.defer { - if (isActive) - ref.rh.map(this) - else - F.pure(Iterant.empty) - }) + Concat( + ref.lh.map(this), + F.defer { + if (isActive) + ref.rh.map(this) + else + F.pure(Iterant.empty) + } + ) def visit[S](ref: Scope[F, S, A]): Iterant[F, A] = ref.runMap(this) diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTakeWhileWithIndex.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTakeWhileWithIndex.scala index bd274e2a6..65493c6f4 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTakeWhileWithIndex.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantTakeWhileWithIndex.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,8 +32,8 @@ private[tail] object IterantTakeWhileWithIndex { private class Loop[F[_], A](p: (A, Long) => Boolean)(implicit F: Sync[F]) extends Iterant.Visitor[F, A, Iterant[F, A]] { loop => - private[this] var isActive = true - private[this] var index = 0L + private var isActive = true + private var index = 0L private def getAndIncrement(): Long = { val old = index @@ -58,12 +58,15 @@ private[tail] object IterantTakeWhileWithIndex { Suspend(ref.rest.map(this)) def visit(ref: Concat[F, A]): Iterant[F, A] = - Concat(ref.lh.map(this), F.defer { - if (isActive) - ref.rh.map(this) - else - F.pure(Iterant.empty) - }) + Concat( + ref.lh.map(this), + F.defer { + if (isActive) + ref.rh.map(this) + else + F.pure(Iterant.empty) + } + ) def visit[S](ref: Scope[F, S, A]): Iterant[F, A] = ref.runMap(this) diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantToReactivePublisher.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantToReactivePublisher.scala index 34b471181..3f819395b 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantToReactivePublisher.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantToReactivePublisher.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,17 +19,17 @@ package monix.tail.internal import cats.effect.Effect import cats.implicits._ -import monix.execution.UncaughtExceptionReporter.{default => Logger} +import monix.execution.UncaughtExceptionReporter.{ default => Logger } import monix.execution.atomic.Atomic import monix.execution.atomic.PaddingStrategy.LeftRight128 import monix.execution.cancelables.SingleAssignCancelable -import monix.execution.internal.{AttemptCallback, Platform} +import monix.execution.internal.{ AttemptCallback, Platform } import monix.execution.internal.collection.ChunkedArrayStack import monix.execution.rstreams.Subscription -import monix.execution.{Cancelable, UncaughtExceptionReporter} +import monix.execution.{ Cancelable, UncaughtExceptionReporter } import monix.tail.Iterant import monix.tail.Iterant.Halt -import org.reactivestreams.{Publisher, Subscriber} +import org.reactivestreams.{ Publisher, Subscriber } import scala.annotation.tailrec import scala.util.control.NonFatal @@ -45,7 +45,7 @@ private[tail] object IterantToReactivePublisher { private final class IterantPublisher[F[_], A](source: Iterant[F, A])(implicit F: Effect[F]) extends Publisher[A] { - def subscribe(out: Subscriber[_ >: A]): Unit = { + def subscribe(out: Subscriber[? >: A]): Unit = { // Reactive Streams requirement if (out == null) throw new NullPointerException("Subscriber must not be null") @@ -65,13 +65,13 @@ private[tail] object IterantToReactivePublisher { } } - private final class IterantSubscription[F[_], A](source: Iterant[F, A], out: Subscriber[_ >: A])( - implicit F: Effect[F]) - extends Subscription { parent => + private final class IterantSubscription[F[_], A](source: Iterant[F, A], out: Subscriber[? >: A])( + implicit F: Effect[F] + ) extends Subscription { parent => - private[this] val cancelable = + private val cancelable = SingleAssignCancelable() - private[this] val state = + private val state = Atomic.withPadding(null: RequestState, LeftRight128) def request(n: Long): Unit = { @@ -107,7 +107,9 @@ private[tail] object IterantToReactivePublisher { new IllegalArgumentException( "n must be strictly positive, according to " + "the Reactive Streams contract, rule 3.9" - ))) + ) + ) + ) } else { loop(n) } @@ -152,18 +154,19 @@ private[tail] object IterantToReactivePublisher { cancelable := Cancelable(() => token.unsafeRunAsync( AttemptCallback.empty(UncaughtExceptionReporter.default) - )) + ) + ) () } private final class Loop extends Iterant.Visitor[F, A, F[Unit]] { - private[this] var requested = 0L - private[this] var haltSignal = Option.empty[Option[Throwable]] - private[this] var streamErrors = true + private var requested = 0L + private var haltSignal = Option.empty[Option[Throwable]] + private var streamErrors = true - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Used in visit(Concat) - private[this] var _stack: ChunkedArrayStack[F[Iterant[F, A]]] = _ + private var _stack: ChunkedArrayStack[F[Iterant[F, A]]] = null.asInstanceOf[ChunkedArrayStack[F[Iterant[F, A]]]] private def stackPush(item: F[Iterant[F, A]]): Unit = { if (_stack == null) _stack = ChunkedArrayStack() @@ -178,13 +181,13 @@ private[tail] object IterantToReactivePublisher { private def isStackEmpty(): Boolean = _stack == null || _stack.isEmpty - private[this] val concatContinue: (Unit => F[Unit]) = + private val concatContinue: (Unit => F[Unit]) = state => stackPop() match { case null => F.pure(state) case xs => xs.flatMap(this) } - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= private def poll(cb: Either[Throwable, Unit] => Unit = null): F[Unit] = { val ref = parent.state @@ -316,8 +319,8 @@ private[tail] object IterantToReactivePublisher { } } - private[this] var suspendedRef: Iterant[F, A] = _ - private[this] val afterPoll: Unit => F[Unit] = _ => { + private var suspendedRef: Iterant[F, A] = null.asInstanceOf[Iterant[F, A]] + private val afterPoll: Unit => F[Unit] = _ => { haltSignal match { case None => if (requested == 0) @@ -341,5 +344,5 @@ private[tail] object IterantToReactivePublisher { private final case class Interrupt(err: Option[Throwable]) extends RequestState - private[this] val rightUnit = Right(()) + private val rightUnit = Right(()) } diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantUncons.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantUncons.scala index 5e87a2b25..29f026989 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantUncons.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantUncons.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package monix.tail.internal import cats.effect.Sync import monix.tail.Iterant -import monix.tail.Iterant.{Concat, NextCursor, Suspend} +import monix.tail.Iterant.{ Concat, NextCursor, Suspend } import cats.implicits._ private[tail] object IterantUncons { diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantZipMap.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantZipMap.scala index f4b6f9bb9..bbbe2b2ad 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantZipMap.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantZipMap.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,14 +19,13 @@ package monix.tail.internal import cats.effect.Sync import cats.syntax.all._ -import cats.{Applicative, Parallel} +import cats.{ Applicative, Parallel } import monix.execution.internal.Platform import monix.catnap.internal.ParallelApplicative import monix.execution.internal.collection.ChunkedArrayStack import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} -import monix.tail.batches.{Batch, BatchCursor} - +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } +import monix.tail.batches.{ Batch, BatchCursor } import scala.collection.mutable.ArrayBuffer private[tail] object IterantZipMap { @@ -42,8 +41,10 @@ private[tail] object IterantZipMap { * Implementation for `Iterant#parZipMap` */ def par[F[_], G[_], A, B, C](lh: Iterant[F, A], rh: Iterant[F, B], f: (A, B) => C)( - implicit F: Sync[F], - P: Parallel[F]): Iterant[F, C] = { + implicit + F: Sync[F], + P: Parallel[F] + ): Iterant[F, C] = { val A = ParallelApplicative(P) Suspend(F.delay(new Loop[F, A, B, C](f)(F, A).apply(lh, rh))) @@ -55,11 +56,11 @@ private[tail] object IterantZipMap { def apply(lh: Iterant[F, A], rh: Iterant[F, B]): Iterant[F, C] = lhLoop.visit(lh, rh) - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Used by Concat: - private[this] var _lhStack: ChunkedArrayStack[F[Iterant[F, A]]] = _ - private[this] var _rhStack: ChunkedArrayStack[F[Iterant[F, B]]] = _ + private var _lhStack: ChunkedArrayStack[F[Iterant[F, A]]] = null.asInstanceOf[ChunkedArrayStack[F[Iterant[F, A]]]] + private var _rhStack: ChunkedArrayStack[F[Iterant[F, B]]] = null.asInstanceOf[ChunkedArrayStack[F[Iterant[F, B]]]] private def lhStackPush(ref: F[Iterant[F, A]]): Unit = { if (_lhStack == null) _lhStack = ChunkedArrayStack() @@ -79,38 +80,38 @@ private[tail] object IterantZipMap { if (_rhStack == null) null.asInstanceOf[F[Iterant[F, B]]] else _rhStack.pop() - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - private[this] val lhLoop = new LHLoop + private val lhLoop = new LHLoop - private[this] var _rhNextLoop: RHNextLoop = _ + private var _rhNextLoop: RHNextLoop = null.asInstanceOf[RHNextLoop] private def rhNextLoop = { if (_rhNextLoop == null) _rhNextLoop = new RHNextLoop _rhNextLoop } - private[this] var _rhNextCursorLoop: RHNextCursorLoop = _ + private var _rhNextCursorLoop: RHNextCursorLoop = null.asInstanceOf[RHNextCursorLoop] private def rhNextCursorLoop = { if (_rhNextCursorLoop == null) _rhNextCursorLoop = new RHNextCursorLoop _rhNextCursorLoop } - private[this] var _rhSuspendLoop: RHSuspendLoop = _ + private var _rhSuspendLoop: RHSuspendLoop = null.asInstanceOf[RHSuspendLoop] private def rhSuspendLoop = { if (_rhSuspendLoop == null) _rhSuspendLoop = new RHSuspendLoop _rhSuspendLoop } - private[this] var _rhLastLoop: RHLastLoop = _ + private var _rhLastLoop: RHLastLoop = null.asInstanceOf[RHLastLoop] private def rhLastLoop = { if (_rhLastLoop == null) _rhLastLoop = new RHLastLoop _rhLastLoop } - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= private final class LHLoop extends Iterant.Visitor[F, A, Iterant[F, C]] { - protected var rhRef: Iterant[F, B] = _ + protected var rhRef: Iterant[F, B] = null.asInstanceOf[Iterant[F, B]] def withRh(ref: Iterant[F, B]): LHLoop = { rhRef = ref @@ -173,7 +174,7 @@ private[tail] object IterantZipMap { private abstract class RHBaseLoop[LH <: Iterant[F, A]] extends Iterant.Visitor[F, B, Iterant[F, C]] { - protected var lhRef: LH = _ + protected var lhRef: LH = null.asInstanceOf[LH] def visit(lh: LH, rh: Iterant[F, B]): Iterant[F, C] = { lhRef = lh @@ -186,10 +187,10 @@ private[tail] object IterantZipMap { processPair(lhRef.item, lhRef.rest, ref.item, ref.rest) def visit(ref: NextBatch[F, B]): Iterant[F, C] = - processOneASeqB(lhRef, lhRef.item, lhRef.rest, ref.toNextCursor(), this) + processOneASeqB(lhRef.item, lhRef.rest, ref.toNextCursor(), this) def visit(ref: NextCursor[F, B]): Iterant[F, C] = - processOneASeqB(lhRef, lhRef.item, lhRef.rest, ref, this) + processOneASeqB(lhRef.item, lhRef.rest, ref, this) def visit(ref: Suspend[F, B]): Iterant[F, C] = Suspend(ref.rest.map(this)) @@ -349,7 +350,7 @@ private[tail] object IterantZipMap { Iterant.raiseError(e) } - //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= def processPair(a: A, restA: F[Iterant[F, A]], b: B, restB: F[Iterant[F, B]]) = { val rest = A.map2(restA, restB)(loop) @@ -357,12 +358,11 @@ private[tail] object IterantZipMap { } def processOneASeqB( - lh: Iterant[F, A], a: A, restA: F[Iterant[F, A]], refB: NextCursor[F, B], - loop: Iterant.Visitor[F, B, Iterant[F, C]]): Iterant[F, C] = { - + loop: Iterant.Visitor[F, B, Iterant[F, C]] + ): Iterant[F, C] = { val NextCursor(itemsB, restB) = refB if (!itemsB.hasNext()) Suspend(restB.map(loop)) @@ -383,7 +383,8 @@ private[tail] object IterantZipMap { refA: Last[F, A], itemsB: BatchCursor[B], restB: F[Iterant[F, B]], - loop: Iterant.Visitor[F, B, Iterant[F, C]]): Iterant[F, C] = { + loop: Iterant.Visitor[F, B, Iterant[F, C]] + ): Iterant[F, C] = { if (!itemsB.hasNext()) Suspend(restB.map(loop)) diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantZipWithIndex.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantZipWithIndex.scala index dae57c772..c94d03cc3 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/IterantZipWithIndex.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/IterantZipWithIndex.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ import cats.syntax.all._ import scala.util.control.NonFatal import monix.tail.Iterant -import monix.tail.Iterant.{Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend} +import monix.tail.Iterant.{ Concat, Halt, Last, Next, NextBatch, NextCursor, Scope, Suspend } import monix.tail.batches.BatchCursor import scala.collection.mutable.ArrayBuffer @@ -37,9 +37,9 @@ private[tail] object IterantZipWithIndex { private class Loop[F[_], A](implicit F: Sync[F]) extends (Iterant[F, A] => Iterant[F, (A, Long)]) { - private[this] var index = 0L + private var index = 0L - private[this] def processSeq(ref: NextCursor[F, A]): NextCursor[F, (A, Long)] = { + private def processSeq(ref: NextCursor[F, A]): NextCursor[F, (A, Long)] = { val NextCursor(cursor, rest) = ref val buffer = ArrayBuffer.empty[(A, Long)] @@ -61,34 +61,35 @@ private[tail] object IterantZipWithIndex { def apply(source: Iterant[F, A]): Iterant[F, (A, Long)] = { try source match { - case Next(item, rest) => - val r = Iterant.nextS((item, index), rest.map(this)) - index += 1 - r + case Next(item, rest) => + val r = Iterant.nextS((item, index), rest.map(this)) + index += 1 + r - case Last(item) => - val r = Iterant.lastS[F, (A, Long)]((item, index)) - index += 1 - r + case Last(item) => + val r = Iterant.lastS[F, (A, Long)]((item, index)) + index += 1 + r - case ref @ NextCursor(_, _) => - processSeq(ref) + case ref @ NextCursor(_, _) => + processSeq(ref) - case NextBatch(batch, rest) => - processSeq(NextCursor(batch.cursor(), rest)) + case NextBatch(batch, rest) => + processSeq(NextCursor(batch.cursor(), rest)) - case Suspend(rest) => - Suspend(rest.map(this)) + case Suspend(rest) => + Suspend(rest.map(this)) - case empty @ Halt(_) => - empty.asInstanceOf[Iterant[F, (A, Long)]] + case empty @ Halt(_) => + empty.asInstanceOf[Iterant[F, (A, Long)]] - case node @ Scope(_, _, _) => - node.runMap(this) + case node @ Scope(_, _, _) => + node.runMap(this) - case node @ Concat(_, _) => - node.runMap(this) - } catch { + case node @ Concat(_, _) => + node.runMap(this) + } + catch { case ex if NonFatal(ex) => Iterant.raiseError(ex) } } diff --git a/monix-tail/shared/src/main/scala/monix/tail/internal/package.scala b/monix-tail/shared/src/main/scala/monix/tail/internal/package.scala index d156fcf8e..96be9d49b 100644 --- a/monix-tail/shared/src/main/scala/monix/tail/internal/package.scala +++ b/monix-tail/shared/src/main/scala/monix/tail/internal/package.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.tail import cats.syntax.all._ import cats.effect.Sync -import monix.tail.Iterant.{Concat, Scope} +import monix.tail.Iterant.{ Concat, Scope } package object internal { /** diff --git a/monix-tail/shared/src/test/scala/monix/tail/AndThenSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/AndThenSuite.scala index 1c027a251..064e77f62 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/AndThenSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/AndThenSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/test/scala/monix/tail/ArbitraryInstances.scala b/monix-tail/shared/src/test/scala/monix/tail/ArbitraryInstances.scala index 0e8910225..7cc91eaf3 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/ArbitraryInstances.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/ArbitraryInstances.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,20 +18,21 @@ package monix.tail import cats.Eq -import cats.effect.{IO, Sync} +import cats.effect.{ IO, Sync } import cats.syntax.eq._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.exceptions.DummyException import monix.execution.schedulers.TestScheduler -import monix.tail.Iterant.{Halt, Last} -import monix.tail.batches.{Batch, BatchCursor} -import org.scalacheck.{Arbitrary, Cogen} +import monix.tail.Iterant.{ Halt, Last } +import monix.tail.batches.{ Batch, BatchCursor } +import org.scalacheck.{ Arbitrary, Cogen } trait ArbitraryInstances extends monix.eval.ArbitraryInstances { import ArbitraryInstances.materialize def arbitraryListToIterant[F[_], A](list: List[A], idx: Int, allowErrors: Boolean = true)( - implicit F: Sync[F]): Iterant[F, A] = { + implicit F: Sync[F] + ): Iterant[F, A] = { def loop(list: List[A], idx: Int): Iterant[F, A] = list match { @@ -42,7 +43,7 @@ trait ArbitraryInstances extends monix.eval.ArbitraryInstances { Iterant[F].haltS(Some(DummyException("arbitrary"))) case x :: Nil if math.abs(idx % 2) == 1 => - if (idx % 4 == 1) + if (idx % 4 == 1) Iterant[F].lastS(x) else Iterant.Concat(F.delay(Iterant[F].lastS(x)), F.delay(Halt(None))) diff --git a/monix-tail/shared/src/test/scala/monix/tail/BaseLawsSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/BaseLawsSuite.scala index 9e800345d..8ce196c03 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/BaseLawsSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/BaseLawsSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.tail -import cats.effect.laws.discipline.{Parameters => EffectParameters} +import cats.effect.laws.discipline.{ Parameters => EffectParameters } import minitest.SimpleTestSuite import minitest.api.IgnoredException import minitest.laws.Checkers diff --git a/monix-tail/shared/src/test/scala/monix/tail/BaseTestSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/BaseTestSuite.scala index c2bd8c1a6..4da8a4341 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/BaseTestSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/BaseTestSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/test/scala/monix/tail/BatchCursorBuildersSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/BatchCursorBuildersSuite.scala index fd51f6b34..75a0192cd 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/BatchCursorBuildersSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/BatchCursorBuildersSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ import monix.tail.batches.BatchCursor object BatchCursorBuildersSuite extends BaseTestSuite { test("apply") { _ => check1 { (list: List[Int]) => - list == BatchCursor(list: _*).toList && + list == BatchCursor(list*).toList && list == BatchCursor.fromSeq(list).toList && list == BatchCursor.fromIndexedSeq(list.toIndexedSeq).toList } diff --git a/monix-tail/shared/src/test/scala/monix/tail/BatchCursorEmptySuite.scala b/monix-tail/shared/src/test/scala/monix/tail/BatchCursorEmptySuite.scala index ca1dcb32f..cd9c6f7d9 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/BatchCursorEmptySuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/BatchCursorEmptySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.tail import java.util.NoSuchElementException import minitest.SimpleTestSuite -import monix.tail.batches.{BatchCursor, EmptyCursor} +import monix.tail.batches.{ BatchCursor, EmptyCursor } object BatchCursorEmptySuite extends SimpleTestSuite { test("BatchCursor.empty.current") { diff --git a/monix-tail/shared/src/test/scala/monix/tail/BatchCursorSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/BatchCursorSuite.scala index cf1387954..fc8711ca1 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/BatchCursorSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/BatchCursorSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,8 +25,8 @@ abstract class BatchCursorSuite[A: ClassTag]( implicit arbA: Arbitrary[A], arbAtoA: Arbitrary[A => A], - arbAtoBoolean: Arbitrary[A => Boolean]) - extends BaseTestSuite { + arbAtoBoolean: Arbitrary[A => Boolean] +) extends BaseTestSuite { type Cursor <: BatchCursor[A] @@ -220,7 +220,7 @@ object GenericCursorSuite extends BatchCursorSuite[Int] { override def fromList(list: List[Int]): Cursor = new GenericCursor[Int] { - private[this] val iter = list.iterator + private val iter = list.iterator def hasNext(): Boolean = iter.hasNext def next(): Int = iter.next() diff --git a/monix-tail/shared/src/test/scala/monix/tail/BatchEmptySuite.scala b/monix-tail/shared/src/test/scala/monix/tail/BatchEmptySuite.scala index 74512869b..a92fb00cc 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/BatchEmptySuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/BatchEmptySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.tail import java.util.NoSuchElementException import minitest.SimpleTestSuite -import monix.tail.batches.{Batch, EmptyBatch} +import monix.tail.batches.{ Batch, EmptyBatch } object BatchEmptySuite extends SimpleTestSuite { test("Batch.empty.cursor().current") { diff --git a/monix-tail/shared/src/test/scala/monix/tail/BatchSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/BatchSuite.scala index bec616649..bf83a3448 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/BatchSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/BatchSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,8 +26,8 @@ abstract class BatchSuite[A: ClassTag]( implicit arbA: Arbitrary[A], arbAtoA: Arbitrary[A => A], - arbAtoBoolean: Arbitrary[A => Boolean]) - extends BaseTestSuite { + arbAtoBoolean: Arbitrary[A => Boolean] +) extends BaseTestSuite { type Batch <: batches.Batch[A] diff --git a/monix-tail/shared/src/test/scala/monix/tail/IntervalIntervalSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IntervalIntervalSuite.scala index cf311d5b7..6db296633 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IntervalIntervalSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IntervalIntervalSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +17,7 @@ package monix.tail -import cats.effect.{IO, Timer} +import cats.effect.{ IO, Timer } import monix.eval.Task import scala.util.Success @@ -177,7 +177,8 @@ object IntervalIntervalSuite extends BaseTestSuite { .mapEval(e => timer.sleep(100.millis).map { _ => effect += 1; e - }) + } + ) .take(3) .toListL .unsafeToFuture() @@ -230,7 +231,8 @@ object IntervalIntervalSuite extends BaseTestSuite { .mapEval(e => timer.sleep(100.millis).map { _ => effect += 1; e - }) + } + ) .take(3) .toListL .unsafeToFuture() @@ -284,7 +286,8 @@ object IntervalIntervalSuite extends BaseTestSuite { .mapEval(e => timer.sleep(2.seconds).map { _ => effect += 1; e - }) + } + ) .take(3) .toListL .unsafeToFuture() diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantBasicSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantBasicSuite.scala index e1bba7973..35d9450d6 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantBasicSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantBasicSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,9 +20,9 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ import cats.effect.IO -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.exceptions.DummyException -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object IterantBasicSuite extends BaseTestSuite { test("arbitraryListToTaskStream works") { implicit s => diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantBufferSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantBufferSuite.scala index 2017218ba..af407d8df 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantBufferSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantBufferSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -37,7 +37,7 @@ object IterantBufferSuite extends BaseTestSuite { test("bufferSliding(c, s) is consistent with List.sliding(c, s)") { implicit s => check4 { (list: List[Int], idx: Int, c: Int, s: Int) => val count = math.abs(c % 4) + 2 - val skip = math.abs(s % 4) + 2 + val skip = math.abs(s % 4) + 2 val stream = arbitraryListToIterant[Coeval, Int](list, idx, allowErrors = false) stream.bufferSliding(count, skip).map(_.toList).toListL <-> diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantChannelSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantChannelSuite.scala index ae7a50be1..5a24f5373 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantChannelSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantChannelSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,13 +18,13 @@ package monix.tail import cats.implicits._ -import cats.effect.{ContextShift, IO, Timer} +import cats.effect.{ ContextShift, IO, Timer } import minitest.SimpleTestSuite import monix.catnap.ProducerF -import monix.execution.BufferCapacity.{Bounded, Unbounded} -import monix.execution.ChannelType.{MultiProducer, SingleProducer} +import monix.execution.BufferCapacity.{ Bounded, Unbounded } +import monix.execution.ChannelType.{ MultiProducer, SingleProducer } import monix.execution.internal.Platform -import monix.execution.{BufferCapacity, Scheduler} +import monix.execution.{ BufferCapacity, Scheduler } import monix.catnap.SchedulerEffect object IterantChannelSuite extends SimpleTestSuite { diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantCollectSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantCollectSuite.scala index 2c4c24be2..c470206e2 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantCollectSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantCollectSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.exceptions.DummyException import monix.tail.Iterant.Suspend import monix.tail.batches.BatchCursor diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantCompleteLSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantCompleteLSuite.scala index b67569047..7f3593638 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantCompleteLSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantCompleteLSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -89,12 +89,15 @@ object IterantCompleteLSuite extends BaseTestSuite { (_, _) => Coeval(triggered.set(true)) ) - val stream = Iterant[Coeval].concatS(Coeval(lh), Coeval { - if (!triggered.getAndSet(true)) - Iterant[Coeval].raiseError[Int](fail) - else - Iterant[Coeval].empty[Int] - }) + val stream = Iterant[Coeval].concatS( + Coeval(lh), + Coeval { + if (!triggered.getAndSet(true)) + Iterant[Coeval].raiseError[Int](fail) + else + Iterant[Coeval].empty[Int] + } + ) assertEquals(stream.completedL.value(), ()) } diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantConcatSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantConcatSuite.scala index ef26ed5aa..f3d33eb62 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantConcatSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantConcatSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } object IterantConcatSuite extends BaseTestSuite { test("Iterant.prepend") { implicit s => @@ -58,14 +58,14 @@ object IterantConcatSuite extends BaseTestSuite { } test("Iterant ++ Iterant is stack safe") { implicit s => - lazy val nats: Iterant[Coeval, Long] = Iterant[Coeval].of(1L) ++ nats.map(_ + 1L) take (4) + lazy val nats: Iterant[Coeval, Long] = (Iterant[Coeval].of(1L) ++ nats.map(_ + 1L)).take(4) assertEquals(nats.toListL.value(), List(1, 2, 3, 4)) } test("Iterant.concat(Iterant*)") { implicit s => check1 { (ll: List[List[Int]]) => val li = ll.map(Iterant[Coeval].fromList) - val concat = Iterant.concat(li: _*) + val concat = Iterant.concat(li*) val expected = Iterant[Coeval].fromList(ll.flatten) concat <-> expected } diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantConsumeSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantConsumeSuite.scala index 546543dc6..1cb541ee1 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantConsumeSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantConsumeSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantDistinctUntilChangedSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantDistinctUntilChangedSuite.scala index afd85585a..f4383af01 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantDistinctUntilChangedSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantDistinctUntilChangedSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantDropLastSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantDropLastSuite.scala index 99f0daab3..644012947 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantDropLastSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantDropLastSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.cancelables.BooleanCancelable import monix.execution.exceptions.DummyException import monix.tail.batches.BatchCursor diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantDropSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantDropSuite.scala index 8e1943b1f..2fd1857fb 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantDropSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantDropSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,10 +19,10 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.exceptions.DummyException import monix.execution.internal.Platform -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.batches.{ Batch, BatchCursor } import org.scalacheck.Test import org.scalacheck.Test.Parameters diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantDropWhileIndexSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantDropWhileIndexSuite.scala index 49294f7fc..29f89580f 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantDropWhileIndexSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantDropWhileIndexSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.exceptions.DummyException import monix.execution.internal.Platform import monix.tail.batches.BatchCursor diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantDropWhileSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantDropWhileSuite.scala index 3c01ea8e5..8b3ca72e7 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantDropWhileSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantDropWhileSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.exceptions.DummyException import monix.execution.internal.Platform import monix.tail.batches.BatchCursor diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantDumpSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantDumpSuite.scala index 39b5df68d..ffd9fcd00 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantDumpSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantDumpSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,14 +17,14 @@ package monix.tail -import java.io.{OutputStream, PrintStream} +import java.io.{ OutputStream, PrintStream } import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.atomic.AtomicInt import monix.execution.exceptions.DummyException -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.batches.{ Batch, BatchCursor } object IterantDumpSuite extends BaseTestSuite { def dummyOut(count: AtomicInt = null) = { diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantFilterSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantFilterSuite.scala index fd382a03c..1d5ce58a9 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantFilterSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantFilterSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.exceptions.DummyException import monix.tail.Iterant.Suspend import monix.tail.batches.BatchCursor diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantFlatMapSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantFlatMapSuite.scala index 2fb9bbde6..3101a68bd 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantFlatMapSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantFlatMapSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,11 +19,11 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.exceptions.DummyException import monix.tail.batches.BatchCursor -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object IterantFlatMapSuite extends BaseTestSuite { test("Iterant[Task].flatMap equivalence with List.flatMap") { implicit s => diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantFoldLeftSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantFoldLeftSuite.scala index ee7803f4c..5a847839b 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantFoldLeftSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantFoldLeftSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,10 +19,10 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.atomic.Atomic import monix.execution.exceptions.DummyException -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.batches.{ Batch, BatchCursor } import scala.util.Failure object IterantFoldLeftSuite extends BaseTestSuite { @@ -90,7 +90,8 @@ object IterantFoldLeftSuite extends BaseTestSuite { val stream = Iterant[Task] .nextS( 1, - Task.evalAsync(Iterant[Task].nextCursorS(BatchCursor(2, 3), Task.now(Iterant[Task].empty[Int])).guarantee(c))) + Task.evalAsync(Iterant[Task].nextCursorS(BatchCursor(2, 3), Task.now(Iterant[Task].empty[Int])).guarantee(c)) + ) .guarantee(c) .mapEval(x => Task.evalAsync(x)) @@ -192,7 +193,8 @@ object IterantFoldLeftSuite extends BaseTestSuite { val stream = Iterant[Coeval] .nextS( 1, - Coeval(Iterant[Coeval].nextCursorS(BatchCursor(2, 3), Coeval.now(Iterant[Coeval].empty[Int])).guarantee(c))) + Coeval(Iterant[Coeval].nextCursorS(BatchCursor(2, 3), Coeval.now(Iterant[Coeval].empty[Int])).guarantee(c)) + ) .guarantee(c) .mapEval(x => Coeval(x)) @@ -276,12 +278,15 @@ object IterantFoldLeftSuite extends BaseTestSuite { (_, _) => Coeval(triggered.set(true)) ) - val stream = Iterant[Coeval].concatS(Coeval(lh), Coeval { - if (!triggered.getAndSet(true)) - Iterant[Coeval].raiseError[Int](fail) - else - Iterant[Coeval].empty[Int] - }) + val stream = Iterant[Coeval].concatS( + Coeval(lh), + Coeval { + if (!triggered.getAndSet(true)) + Iterant[Coeval].raiseError[Int](fail) + else + Iterant[Coeval].empty[Int] + } + ) assertEquals(stream.toListL.value(), List(1)) } diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantFoldRightSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantFoldRightSuite.scala index f98ead879..a70d16cdb 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantFoldRightSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantFoldRightSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ import cats.effect.Sync import monix.eval.Coeval import monix.execution.atomic.Atomic import monix.execution.exceptions.DummyException -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object IterantFoldRightSuite extends BaseTestSuite { def exists(ref: Iterant[Coeval, Int], p: Int => Boolean): Coeval[Boolean] = diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantFoldWhileLeftSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantFoldWhileLeftSuite.scala index 664421480..2a00afe08 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantFoldWhileLeftSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantFoldWhileLeftSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ import cats.laws.discipline._ import monix.eval.Coeval import monix.execution.atomic.Atomic import monix.execution.exceptions.DummyException -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object IterantFoldWhileLeftSuite extends BaseTestSuite { def exists(fa: Iterant[Coeval, Int], p: Int => Boolean): Coeval[Boolean] = @@ -408,12 +408,15 @@ object IterantFoldWhileLeftSuite extends BaseTestSuite { (_, _) => Coeval(triggered.set(true)) ) - val stream = Iterant[Coeval].concatS(Coeval(lh), Coeval { - if (!triggered.getAndSet(true)) - Iterant[Coeval].raiseError[Int](fail) - else - Iterant[Coeval].empty[Int] - }) + val stream = Iterant[Coeval].concatS( + Coeval(lh), + Coeval { + if (!triggered.getAndSet(true)) + Iterant[Coeval].raiseError[Int](fail) + else + Iterant[Coeval].empty[Int] + } + ) assertEquals(stream.foldWhileLeftL(List.empty[Int])((acc, i) => Left(i :: acc)).value(), List(1)) } @@ -449,16 +452,20 @@ object IterantFoldWhileLeftSuite extends BaseTestSuite { (_, _) => Coeval(triggered.set(true)) ) - val stream = Iterant[Coeval].concatS(Coeval(lh), Coeval { - if (!triggered.getAndSet(true)) - Iterant[Coeval].raiseError[Int](fail) - else - Iterant[Coeval].empty[Int] - }) + val stream = Iterant[Coeval].concatS( + Coeval(lh), + Coeval { + if (!triggered.getAndSet(true)) + Iterant[Coeval].raiseError[Int](fail) + else + Iterant[Coeval].empty[Int] + } + ) assertEquals( stream.foldWhileLeftEvalL(Coeval(List.empty[Int]))((acc, i) => Coeval(Left(i :: acc))).value(), - List(1)) + List(1) + ) } test("foldWhileLeftEvalL handles Scope's release after use is finished") { implicit s => @@ -481,6 +488,7 @@ object IterantFoldWhileLeftSuite extends BaseTestSuite { assertEquals( (0 +: stream :+ 2).foldWhileLeftEvalL(Coeval(List.empty[Int]))((acc, i) => Coeval(Left(i :: acc))).value(), - List(2, 1, 0)) + List(2, 1, 0) + ) } } diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantFromIndexedSeqSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantFromIndexedSeqSuite.scala index 92f5605f6..e119a6f04 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantFromIndexedSeqSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantFromIndexedSeqSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } object IterantFromIndexedSeqSuite extends BaseTestSuite { test("Iterant[Task].fromIndexedSeq") { implicit s => diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantFromIterableSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantFromIterableSuite.scala index bded0615e..cd20a3d17 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantFromIterableSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantFromIterableSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.exceptions.DummyException import scala.util.Failure diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantFromListSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantFromListSuite.scala index e7d50b6f5..8b75d3c73 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantFromListSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantFromListSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } object IterantFromListSuite extends BaseTestSuite { test("Iterant[Task].fromList") { implicit s => diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantFromReactivePublisherSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantFromReactivePublisherSuite.scala index 3299c5268..35b2297a9 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantFromReactivePublisherSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantFromReactivePublisherSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,11 +24,11 @@ import monix.eval.Task import monix.execution.Scheduler import monix.execution.atomic.Atomic import monix.execution.exceptions.DummyException -import org.reactivestreams.{Publisher, Subscriber, Subscription} -import org.scalacheck.{Arbitrary, Gen} +import org.reactivestreams.{ Publisher, Subscriber, Subscription } +import org.scalacheck.{ Arbitrary, Gen } import scala.concurrent.Promise -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } import scala.concurrent.duration._ object IterantFromReactivePublisherSuite extends BaseTestSuite { @@ -112,7 +112,7 @@ object IterantFromReactivePublisherSuite extends BaseTestSuite { test("fromReactivePublisher handles immediate completion") { implicit s => val publisher = new Publisher[Unit] { - def subscribe(subscriber: Subscriber[_ >: Unit]): Unit = { + def subscribe(subscriber: Subscriber[? >: Unit]): Unit = { subscriber.onComplete() } } @@ -123,8 +123,8 @@ object IterantFromReactivePublisherSuite extends BaseTestSuite { } class RangePublisher(from: Int, until: Int, step: Int, finish: Option[Throwable], onCancel: Promise[Unit])( - implicit sc: Scheduler) - extends Publisher[Int] { + implicit sc: Scheduler + ) extends Publisher[Int] { def this(range: Range, finish: Option[Throwable])(implicit sc: Scheduler) = this(range.start, range.end, range.step, finish, null) @@ -132,11 +132,11 @@ object IterantFromReactivePublisherSuite extends BaseTestSuite { def this(range: Range, finish: Option[Throwable], onCancel: Promise[Unit])(implicit sc: Scheduler) = this(range.start, range.end, range.step, finish, onCancel) - def subscribe(s: Subscriber[_ >: Int]): Unit = { + def subscribe(s: Subscriber[? >: Int]): Unit = { s.onSubscribe(new Subscription { self => - private[this] val cancelled = Atomic(false) - private[this] val requested = Atomic(0L) - private[this] var index = from + private val cancelled = Atomic(false) + private val requested = Atomic(0L) + private var index = from def isInRange(x: Long, until: Long, step: Long): Boolean = { (step > 0 && x < until) || (step < 0 && x > until) @@ -144,30 +144,28 @@ object IterantFromReactivePublisherSuite extends BaseTestSuite { def request(n: Long): Unit = { if (requested.getAndAdd(n) == 0) - sc.execute(new Runnable { - def run(): Unit = { - var requested = self.requested.get() - var toSend = requested - - while (toSend > 0 && isInRange(index.toLong, until.toLong, step.toLong) && !cancelled.get()) { - s.onNext(index) - index += step - toSend -= 1 - - if (toSend == 0) { - requested = self.requested.subtractAndGet(requested) - toSend = requested - } + sc.execute(() => { + var requested = self.requested.get() + var toSend = requested + + while (toSend > 0 && isInRange(index.toLong, until.toLong, step.toLong) && !cancelled.get()) { + s.onNext(index) + index += step + toSend -= 1 + + if (toSend == 0) { + requested = self.requested.subtractAndGet(requested) + toSend = requested } - - if (!isInRange(index.toLong, until.toLong, step.toLong)) - finish match { - case None => - s.onComplete() - case Some(e) => - s.onError(e) - } } + + if (!isInRange(index.toLong, until.toLong, step.toLong)) + finish match { + case None => + s.onComplete() + case Some(e) => + s.onError(e) + } }) } diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantFromReactiveStreamAsyncSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantFromReactiveStreamAsyncSuite.scala index 87f0123b8..9a5a86241 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantFromReactiveStreamAsyncSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantFromReactiveStreamAsyncSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,9 +24,9 @@ import monix.execution.Scheduler.global import monix.execution.atomic.Atomic import monix.execution.exceptions.DummyException import monix.execution.internal.Platform -import org.reactivestreams.{Publisher, Subscriber, Subscription} +import org.reactivestreams.{ Publisher, Subscriber, Subscription } -import scala.concurrent.{Future, Promise} +import scala.concurrent.{ Future, Promise } object IterantFromReactiveStreamAsyncSuite extends TestSuite[Scheduler] { def setup(): Scheduler = global @@ -181,8 +181,8 @@ object IterantFromReactiveStreamAsyncSuite extends TestSuite[Scheduler] { } class RangePublisher(from: Int, until: Int, step: Int, finish: Option[Throwable], onCancel: Promise[Unit])( - implicit sc: Scheduler) - extends Publisher[Int] { + implicit sc: Scheduler + ) extends Publisher[Int] { def this(range: Range, finish: Option[Throwable])(implicit sc: Scheduler) = this(range.start, range.end, range.step, finish, null) @@ -190,12 +190,12 @@ object IterantFromReactiveStreamAsyncSuite extends TestSuite[Scheduler] { def this(range: Range, finish: Option[Throwable], onCancel: Promise[Unit])(implicit sc: Scheduler) = this(range.start, range.end, range.step, finish, onCancel) - def subscribe(s: Subscriber[_ >: Int]): Unit = { + def subscribe(s: Subscriber[? >: Int]): Unit = { s.onSubscribe(new Subscription { self => - private[this] val finished = Atomic(false) - private[this] val cancelled = Atomic(false) - private[this] val requested = Atomic(0L) - private[this] var index = from + private val finished = Atomic(false) + private val cancelled = Atomic(false) + private val requested = Atomic(0L) + private var index = from def isInRange(x: Long, until: Long, step: Long): Boolean = { (step > 0 && x < until) || (step < 0 && x > until) @@ -203,35 +203,34 @@ object IterantFromReactiveStreamAsyncSuite extends TestSuite[Scheduler] { def request(n: Long): Unit = { if (requested.getAndAdd(n) == 0) - sc.execute(new Runnable { - def run(): Unit = { - var requested = self.requested.get() - var toSend = requested - var isCanceled = self.cancelled.get() && self.finished.get() - - while (toSend > 0 && isInRange(index.toLong, until.toLong, step.toLong) && !isCanceled) { - s.onNext(index) - index += step - toSend -= 1 - - if (toSend == 0) { - requested = self.requested.subtractAndGet(requested) - toSend = requested - } else if (toSend % 100 == 0) { - isCanceled = self.cancelled.get() - } + sc.execute(() => { + var requested = self.requested.get() + var toSend = requested + var isCanceled = self.cancelled.get() && self.finished.get() + + while (toSend > 0 && isInRange(index.toLong, until.toLong, step.toLong) && !isCanceled) { + s.onNext(index) + index += step + toSend -= 1 + + if (toSend == 0) { + requested = self.requested.subtractAndGet(requested) + toSend = requested + } else if (toSend % 100 == 0) { + isCanceled = self.cancelled.get() } + } - if (!isInRange(index.toLong, until.toLong, step.toLong) && - !isCanceled && - finished.compareAndSet(expect = false, update = true) - ) { - finish match { - case None => - s.onComplete() - case Some(e) => - s.onError(e) - } + if ( + !isInRange(index.toLong, until.toLong, step.toLong) && + !isCanceled && + finished.compareAndSet(expect = false, update = true) + ) { + finish match { + case None => + s.onComplete() + case Some(e) => + s.onError(e) } } }) diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantFromResourceSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantFromResourceSuite.scala index 61c96afb7..5cfb06a29 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantFromResourceSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantFromResourceSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantFromSeqSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantFromSeqSuite.scala index 18559fc30..fab92e480 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantFromSeqSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantFromSeqSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -39,7 +39,7 @@ object IterantFromSeqSuite extends BaseTestSuite { test("Iterant[Task].fromSeq(iterable)") { implicit s => check1 { (list: List[Int]) => - val result = Iterant[Task].fromSeq(ListBuffer(list: _*).toSeq).toListL + val result = Iterant[Task].fromSeq(ListBuffer(list*).toSeq).toListL result <-> Task.now(list) } } diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantFromStateActionSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantFromStateActionSuite.scala index dd1dd79d7..071b573ed 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantFromStateActionSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantFromStateActionSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.exceptions.DummyException import monix.execution.internal.Platform.recommendedBatchSize import monix.tail.Iterant.NextBatch @@ -63,7 +63,7 @@ object IterantFromStateActionSuite extends BaseTestSuite { test("Iterant.fromStateActionL should evolve state") { implicit s => check3 { (seed: Int, f: Int => (Int, Int), i: Int) => val n = i % (recommendedBatchSize * 2) - val stream = Iterant[Task].fromStateActionL[Int, Int](f andThen Task.now)(Task.now(seed)) + val stream = Iterant[Task].fromStateActionL[Int, Int](f.andThen(Task.now))(Task.now(seed)) val expected = Iterator .continually(0) .scanLeft(f(seed)) { case ((_, newSeed), _) => f(newSeed) } @@ -79,7 +79,7 @@ object IterantFromStateActionSuite extends BaseTestSuite { check3 { (seed: Int, f: Int => (Int, Int), i: Int) => val n = i % (recommendedBatchSize * 2) val stream = Iterant[Task].fromStateAction[Int, Int](f)(seed) - val streamL = Iterant[Task].fromStateActionL[Int, Int](f andThen Task.now)(Task.now(seed)) + val streamL = Iterant[Task].fromStateActionL[Int, Int](f.andThen(Task.now))(Task.now(seed)) stream.take(n) <-> streamL.take(n) } diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantHeadOptionSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantHeadOptionSuite.scala index 70692c89a..a4db008f1 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantHeadOptionSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantHeadOptionSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,10 +19,10 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.atomic.Atomic import monix.execution.exceptions.DummyException -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.batches.{ Batch, BatchCursor } import scala.util.Failure @@ -43,10 +43,10 @@ object IterantHeadOptionSuite extends BaseTestSuite { test("Iterant.headOption suspends execution for NextCursor or NextBatch") { _ => check1 { (list: List[Int]) => - val iter1 = Iterant[Coeval].nextBatchS(Batch(list: _*), Coeval.now(Iterant[Coeval].empty[Int])) + val iter1 = Iterant[Coeval].nextBatchS(Batch(list*), Coeval.now(Iterant[Coeval].empty[Int])) iter1.headOptionL <-> Coeval.suspend(Coeval.now(list.headOption)) - val iter2 = Iterant[Coeval].nextCursorS(BatchCursor(list: _*), Coeval.now(Iterant[Coeval].empty[Int])) + val iter2 = Iterant[Coeval].nextCursorS(BatchCursor(list*), Coeval.now(Iterant[Coeval].empty[Int])) iter2.headOptionL <-> Coeval.suspend(Coeval.now(list.headOption)) } } @@ -106,12 +106,15 @@ object IterantHeadOptionSuite extends BaseTestSuite { (_, _) => Coeval(triggered.set(true)) ) - val stream = Iterant[Coeval].concatS(Coeval(lh), Coeval { - if (!triggered.getAndSet(true)) - Iterant[Coeval].raiseError[Int](fail) - else - Iterant[Coeval].empty[Int] - }) + val stream = Iterant[Coeval].concatS( + Coeval(lh), + Coeval { + if (!triggered.getAndSet(true)) + Iterant[Coeval].raiseError[Int](fail) + else + Iterant[Coeval].empty[Int] + } + ) assertEquals(stream.headOptionL.value(), None) } diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantInterleaveSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantInterleaveSuite.scala index bbc0876a0..f88f5271b 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantInterleaveSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantInterleaveSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantIntersperseSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantIntersperseSuite.scala index 2d493a06a..9df76d040 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantIntersperseSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantIntersperseSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantLastOptionSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantLastOptionSuite.scala index aab20f1ac..99481fc80 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantLastOptionSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantLastOptionSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,10 +19,10 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.atomic.Atomic import monix.execution.exceptions.DummyException -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.batches.{ Batch, BatchCursor } import scala.util.Failure @@ -43,10 +43,10 @@ object IterantLastOptionSuite extends BaseTestSuite { test("Iterant.lastOption suspends execution for NextCursor or NextBatch") { _ => check1 { (list: List[Int]) => - val iter1 = Iterant[Coeval].nextBatchS(Batch(list: _*), Coeval.now(Iterant[Coeval].empty[Int])) + val iter1 = Iterant[Coeval].nextBatchS(Batch(list*), Coeval.now(Iterant[Coeval].empty[Int])) iter1.lastOptionL <-> Coeval.suspend(Coeval.now(list.lastOption)) - val iter2 = Iterant[Coeval].nextCursorS(BatchCursor(list: _*), Coeval.now(Iterant[Coeval].empty[Int])) + val iter2 = Iterant[Coeval].nextCursorS(BatchCursor(list*), Coeval.now(Iterant[Coeval].empty[Int])) iter2.lastOptionL <-> Coeval.suspend(Coeval.now(list.lastOption)) } } @@ -106,12 +106,15 @@ object IterantLastOptionSuite extends BaseTestSuite { (_, _) => Coeval(triggered.set(true)) ) - val stream = Iterant[Coeval].concatS(Coeval(lh), Coeval { - if (!triggered.getAndSet(true)) - Iterant[Coeval].raiseError[Int](fail) - else - Iterant[Coeval].empty[Int] - }) + val stream = Iterant[Coeval].concatS( + Coeval(lh), + Coeval { + if (!triggered.getAndSet(true)) + Iterant[Coeval].raiseError[Int](fail) + else + Iterant[Coeval].empty[Int] + } + ) assertEquals(stream.lastOptionL.value(), None) } diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantLiftMapSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantLiftMapSuite.scala index 7cf7766a5..55fbf67b8 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantLiftMapSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantLiftMapSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.tail import cats.effect.IO import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } object IterantLiftMapSuite extends BaseTestSuite { test("liftMap(f) converts Iterant[Coeval, ?] to Iterant[Task, ?]") { implicit s => diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantMapBatchSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantMapBatchSuite.scala index 811f70a76..b4df7301c 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantMapBatchSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantMapBatchSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,19 +19,19 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.cancelables.BooleanCancelable import monix.execution.exceptions.DummyException import monix.execution.internal.Platform.recommendedBatchSize -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.batches.{ Batch, BatchCursor } import scala.util.Failure object IterantMapBatchSuite extends BaseTestSuite { test("Iterant[Task].mapBatch(f) equivalence with List.flatMap(f andThen (_.toList))") { implicit s => check2 { (stream: Iterant[Task, Array[Int]], f: Array[Int] => Long) => - val g = f andThen (Batch.apply(_)) + val g = f.andThen(Batch.apply(_)) stream.mapBatch(g).toListL <-> - stream.toListL.map(_.flatMap(g andThen (_.toList))) + stream.toListL.map(_.flatMap(g.andThen(_.toList))) } } @@ -41,7 +41,7 @@ object IterantMapBatchSuite extends BaseTestSuite { Iterant[Task].nextBatchS(Batch.fromSeq(list, recommendedBatchSize), Task.delay(Iterant[Task].lastS[Int](elem))) val f: Int => List[Int] = List.fill(recommendedBatchSize * 2)(_) - val received = stream.mapBatch(f andThen (Batch.fromSeq(_))).toListL + val received = stream.mapBatch(f.andThen(Batch.fromSeq(_))).toListL val expected = stream.toListL.map(_.flatMap(f)) received <-> expected diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantMapEvalSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantMapEvalSuite.scala index 3863a1ce3..9ef6a33ba 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantMapEvalSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantMapEvalSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,10 +19,10 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.exceptions.DummyException import monix.tail.Iterant.Suspend -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.batches.{ Batch, BatchCursor } import scala.util.Failure object IterantMapEvalSuite extends BaseTestSuite { diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantMapSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantMapSuite.scala index fb343498a..904ee8fdb 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantMapSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantMapSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,9 +19,9 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.exceptions.DummyException -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.batches.{ Batch, BatchCursor } import scala.util.Failure object IterantMapSuite extends BaseTestSuite { diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantOnErrorSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantOnErrorSuite.scala index 26c5918db..c7a0e90ad 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantOnErrorSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantOnErrorSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,10 +22,10 @@ import cats.syntax.either._ import cats.syntax.eq._ import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} -import monix.execution.exceptions.{CompositeException, DummyException} +import monix.eval.{ Coeval, Task } +import monix.execution.exceptions.{ CompositeException, DummyException } import monix.execution.internal.Platform -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.batches.{ Batch, BatchCursor } object IterantOnErrorSuite extends BaseTestSuite { test("fa.attempt <-> fa.map(Right) for successful streams") { implicit s => @@ -54,7 +54,8 @@ object IterantOnErrorSuite extends BaseTestSuite { _.fold( e => Iterant[Coeval].raiseError[Int](e), a => Iterant[Coeval].pure(a) - )) + ) + ) r <-> fa } @@ -62,7 +63,7 @@ object IterantOnErrorSuite extends BaseTestSuite { test("fa.onErrorHandleWith(_ => fb) <-> fa for successful streams") { _ => check1 { (list: List[Int]) => - val iter = Iterant[Coeval].of(list: _*) + val iter = Iterant[Coeval].of(list*) iter.onErrorHandleWith(_ => Iterant[Coeval].empty[Int]) <-> iter } @@ -128,11 +129,14 @@ object IterantOnErrorSuite extends BaseTestSuite { var effect = 0 val errorInTail = Iterant[Coeval] - .nextS(1, Coeval { - Iterant[Coeval] - .nextS(2, Coeval { (throw DummyException("Dummy")): Iterant[Coeval, Int] }) - .guarantee(Coeval { effect += 2 }) - }) + .nextS( + 1, + Coeval { + Iterant[Coeval] + .nextS(2, Coeval { (throw DummyException("Dummy")): Iterant[Coeval, Int] }) + .guarantee(Coeval { effect += 2 }) + } + ) .guarantee(Coeval { effect += 1 }) errorInTail.onErrorHandleWith(_ => Iterant[Coeval].empty[Int]).completedL.value() @@ -153,11 +157,14 @@ object IterantOnErrorSuite extends BaseTestSuite { var effect = 0 val errorInTail = Iterant[Coeval] - .nextS(1, Coeval { - Iterant[Coeval] - .nextS(2, Coeval { (throw DummyException("Dummy")): Iterant[Coeval, Int] }) - .guarantee(Coeval { effect += 2 }) - }) + .nextS( + 1, + Coeval { + Iterant[Coeval] + .nextS(2, Coeval { (throw DummyException("Dummy")): Iterant[Coeval, Int] }) + .guarantee(Coeval { effect += 2 }) + } + ) .guarantee(Coeval { effect += 1 }) errorInTail.attempt.completedL.value() @@ -224,7 +231,7 @@ object IterantOnErrorSuite extends BaseTestSuite { assertEquals(result, Some(Left(dummy))) } - //noinspection ScalaUnreachableCode + // noinspection ScalaUnreachableCode def semiBrokenIterator(ex: Throwable): Iterator[Int] = { def end: Iterator[Int] = new Iterator[Int] { override def hasNext: Boolean = true @@ -246,7 +253,8 @@ object IterantOnErrorSuite extends BaseTestSuite { Right(1), Right(2), Left(dummy) - )) + ) + ) } test("Resource.attempt with broken acquire") { _ => diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantRangesSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantRangesSuite.scala index ef5238499..f27336460 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantRangesSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantRangesSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantReduceSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantReduceSuite.scala index c97f2b34a..8913a5f0a 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantReduceSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantReduceSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -178,12 +178,15 @@ object IterantReduceSuite extends BaseTestSuite { (_, _) => Coeval(triggered.set(true)) ) - val stream = Iterant[Coeval].concatS(Coeval(lh), Coeval { - if (!triggered.getAndSet(true)) - Iterant[Coeval].raiseError[Int](fail) - else - Iterant[Coeval].empty[Int] - }) + val stream = Iterant[Coeval].concatS( + Coeval(lh), + Coeval { + if (!triggered.getAndSet(true)) + Iterant[Coeval].raiseError[Int](fail) + else + Iterant[Coeval].empty[Int] + } + ) assertEquals(stream.reduceL(_ + _).value(), Some(1)) } diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantRepeatSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantRepeatSuite.scala index b6a614296..98032c388 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantRepeatSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantRepeatSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,11 +20,11 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ import cats.syntax.eq._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.atomic.Atomic import monix.execution.exceptions.DummyException import monix.execution.internal.Platform -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.batches.{ Batch, BatchCursor } object IterantRepeatSuite extends BaseTestSuite { test("Iterant.repeat works for one item") { _ => @@ -46,7 +46,8 @@ object IterantRepeatSuite extends BaseTestSuite { Iterant[Coeval].fromIterable( (0 until (count / list.length + 1)) .flatMap(_ => list) - .take(count)) + .take(count) + ) } fa <-> expected diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantResourceSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantResourceSuite.scala index 324d5392d..b471be759 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantResourceSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantResourceSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ import cats.laws._ import cats.laws.discipline._ import monix.eval.Coeval import monix.execution.exceptions.DummyException -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.batches.{ Batch, BatchCursor } object IterantResourceSuite extends BaseTestSuite { class Resource(var acquired: Int = 0, var released: Int = 0) { @@ -49,7 +49,8 @@ object IterantResourceSuite extends BaseTestSuite { .of(1, 2, 3) .guarantee(Coeval { earlyStopDone = true - })) + }) + ) bracketed.take(1).completedL.value() assert(earlyStopDone) diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantRetryIfEmptySuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantRetryIfEmptySuite.scala index 9c6271d46..950343c25 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantRetryIfEmptySuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantRetryIfEmptySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } object IterantRetryIfEmptySuite extends BaseTestSuite { test("Iterant.pure(1).retryIfEmpty mirrors source") { _ => @@ -57,7 +57,8 @@ object IterantRetryIfEmptySuite extends BaseTestSuite { Coeval { assertEquals(acquired, 1) acquired -= 1 - }) + } + ) .flatMap(_ => Iterant[Coeval].empty[Int]) val r = (empty ++ resource).retryIfEmpty(Some(2)).toListL.value() diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantScanEvalSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantScanEvalSuite.scala index 2bb18442f..24205c2b2 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantScanEvalSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantScanEvalSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -63,7 +63,8 @@ object IterantScanEvalSuite extends BaseTestSuite { .map(ls => ls.take(19) .map(x => requestPersonDetails(x).value()) - .collect { case Some(p) => p.name }) + .collect { case Some(p) => p.name } + ) fa <-> expected } diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantScanMapSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantScanMapSuite.scala index 070b322e4..d33c2294b 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantScanMapSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantScanMapSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantScanSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantScanSuite.scala index 284527f2b..5b539d63c 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantScanSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantScanSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantStatesSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantStatesSuite.scala index 01f1f4a55..f29a596cd 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantStatesSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantStatesSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,11 +17,11 @@ package monix.tail -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.exceptions.DummyException import monix.tail.batches.BatchCursor -import scala.util.{Failure, Success} +import scala.util.{ Failure, Success } object IterantStatesSuite extends BaseTestSuite { test("Iterant[Task].suspend(Task.evalAsync(list))") { implicit s => diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantSwitchIfEmptySuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantSwitchIfEmptySuite.scala index 66f2114ee..fb0035819 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantSwitchIfEmptySuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantSwitchIfEmptySuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ import cats.laws.discipline._ import monix.eval.Coeval import monix.execution.cancelables.BooleanCancelable import monix.execution.exceptions.DummyException -import monix.tail.batches.{EmptyBatch, EmptyCursor} +import monix.tail.batches.{ EmptyBatch, EmptyCursor } object IterantSwitchIfEmptySuite extends BaseTestSuite { val backupStream: Iterant[Coeval, Int] = Iterant[Coeval].of(42) @@ -80,7 +80,8 @@ object IterantSwitchIfEmptySuite extends BaseTestSuite { Iterant[Coeval].nextCursorS( EmptyCursor, Coeval(emptyInts) - )) + ) + ) } test("Iterant.switchIfEmpty chooses fallback for empty batches") { implicit s => @@ -88,7 +89,8 @@ object IterantSwitchIfEmptySuite extends BaseTestSuite { Iterant[Coeval].nextBatchS( EmptyBatch, Coeval(emptyInts) - )) + ) + ) } test("Iterant.switchIfEmpty consistent with toListL.isEmpty") { implicit s => diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantTailSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantTailSuite.scala index 440914c4a..7221db6f7 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantTailSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantTailSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.exceptions.DummyException import monix.tail.Iterant.Suspend diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantTakeEveryNthSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantTakeEveryNthSuite.scala index 73603cdec..4334be067 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantTakeEveryNthSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantTakeEveryNthSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.tail import cats.effect.Sync import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.cancelables.BooleanCancelable import monix.execution.exceptions.DummyException import monix.execution.internal.Platform diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantTakeLastSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantTakeLastSuite.scala index 332057356..07a970e19 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantTakeLastSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantTakeLastSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.exceptions.DummyException import monix.tail.batches.BatchCursor diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantTakeSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantTakeSuite.scala index 30ae9a960..05c8788ef 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantTakeSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantTakeSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,12 +19,12 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.cancelables.BooleanCancelable import monix.execution.exceptions.DummyException import monix.execution.internal.Platform import monix.tail.Iterant.Suspend -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.batches.{ Batch, BatchCursor } import org.scalacheck.Test import org.scalacheck.Test.Parameters diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantTakeWhileSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantTakeWhileSuite.scala index 3f7d2b3f6..8dd3c9eab 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantTakeWhileSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantTakeWhileSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,11 +19,11 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.cancelables.BooleanCancelable import monix.execution.exceptions.DummyException import monix.execution.internal.Platform -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.batches.{ Batch, BatchCursor } import org.scalacheck.Test import org.scalacheck.Test.Parameters diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantTakeWhileWithIndexSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantTakeWhileWithIndexSuite.scala index a3af7e60f..3f6fc3fad 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantTakeWhileWithIndexSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantTakeWhileWithIndexSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,11 +20,11 @@ package monix.tail import cats.effect.Sync import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.cancelables.BooleanCancelable import monix.execution.exceptions.DummyException import monix.execution.internal.Platform -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.batches.{ Batch, BatchCursor } import org.scalacheck.Test import org.scalacheck.Test.Parameters @@ -126,8 +126,8 @@ object IterantTakeWhileWithIndexSuite extends BaseTestSuite { val suffix = Iterant[Coeval].nextCursorS[Int](new ThrowExceptionCursor(dummy), Coeval.now(Iterant[Coeval].empty)) val stream = (iter.onErrorIgnore ++ suffix).guarantee(Coeval.eval(cancelable.cancel())) - intercept[DummyException] { - stream.takeWhileWithIndex((_, _) => true).toListL.value() + intercept[DummyException] { + stream.takeWhileWithIndex((_, _) => true).toListL.value() () } cancelable.isCanceled diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantToReactivePublisherSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantToReactivePublisherSuite.scala index e575f2bff..1b42c1849 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantToReactivePublisherSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantToReactivePublisherSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,8 +27,8 @@ import monix.execution.exceptions.DummyException import monix.execution.internal.Platform import monix.execution.rstreams.SingleAssignSubscription import monix.tail.batches.Batch -import org.reactivestreams.{Subscriber, Subscription} -import scala.util.{Failure, Success} +import org.reactivestreams.{ Subscriber, Subscription } +import scala.util.{ Failure, Success } object IterantToReactivePublisherSuite extends BaseTestSuite { test("sum with Task and request(1)") { implicit s => @@ -227,9 +227,13 @@ object IterantToReactivePublisherSuite extends BaseTestSuite { } test("protects against invalid subscriber") { implicit s => - intercept[NullPointerException] { - Iterant[Task].of(1).toReactivePublisher.subscribe(null) - () + if (Platform.isJVM) { + intercept[NullPointerException] { + Iterant[Task].of(1).toReactivePublisher.subscribe(null) + () + } + } else { + // TODO } () } @@ -340,9 +344,9 @@ object IterantToReactivePublisherSuite extends BaseTestSuite { val subscription = SingleAssignSubscription() stream.toReactivePublisher.subscribe(new Subscriber[Int] { - private[this] var s: Subscription = _ - private[this] var requested = 0L - private[this] var sum = 0L + private var s: Subscription = _ + private var requested = 0L + private var sum = 0L def onSubscribe(s: Subscription): Unit = { this.s = s @@ -392,7 +396,8 @@ object IterantToReactivePublisherSuite extends BaseTestSuite { override def liftIO[A](ioa: IO[A]): IO[A] = ioa override def bracketCase[A, B](acquire: IO[A])(use: A => IO[B])( - release: (A, ExitCase[Throwable]) => IO[Unit]): IO[B] = + release: (A, ExitCase[Throwable]) => IO[Unit] + ): IO[B] = acquire.bracketCase(use)(release) } } diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantUnconsSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantUnconsSuite.scala index 54b703e0b..e3cfde3d1 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantUnconsSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantUnconsSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantZipMapSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantZipMapSuite.scala index 0f68658af..dd688f0fc 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantZipMapSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantZipMapSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +19,7 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.atomic.Atomic import monix.execution.exceptions.DummyException import monix.execution.internal.Platform @@ -109,12 +109,15 @@ object IterantZipMapSuite extends BaseTestSuite { (_, _) => Coeval(triggered.set(true)) ) - val scope = Iterant[Coeval].concatS(Coeval(lh), Coeval { - if (!triggered.getAndSet(true)) - Iterant[Coeval].raiseError[Int](fail) - else - Iterant[Coeval].empty[Int] - }) + val scope = Iterant[Coeval].concatS( + Coeval(lh), + Coeval { + if (!triggered.getAndSet(true)) + Iterant[Coeval].raiseError[Int](fail) + else + Iterant[Coeval].empty[Int] + } + ) 0 +: scope :+ 2 } diff --git a/monix-tail/shared/src/test/scala/monix/tail/IterantZipWithIndexSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/IterantZipWithIndexSuite.scala index 9efcc9134..c565b4778 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/IterantZipWithIndexSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/IterantZipWithIndexSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,11 +19,11 @@ package monix.tail import cats.laws._ import cats.laws.discipline._ -import monix.eval.{Coeval, Task} +import monix.eval.{ Coeval, Task } import monix.execution.cancelables.BooleanCancelable import monix.execution.exceptions.DummyException import monix.execution.internal.Platform -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.batches.{ Batch, BatchCursor } import org.scalacheck.Test import org.scalacheck.Test.Parameters diff --git a/monix-tail/shared/src/test/scala/monix/tail/ThrowExceptionBatch.scala b/monix-tail/shared/src/test/scala/monix/tail/ThrowExceptionBatch.scala index 144f4086d..3ed079235 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/ThrowExceptionBatch.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/ThrowExceptionBatch.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,12 +18,12 @@ package monix.tail import monix.execution.atomic.Atomic -import monix.tail.batches.{BatchCursor, GenericBatch} +import monix.tail.batches.{ BatchCursor, GenericBatch } /** Batch that throws exception on access. */ final class ThrowExceptionBatch[A](ex: Throwable) extends GenericBatch[A] { - private[this] val triggered = Atomic(false) + private val triggered = Atomic(false) def isTriggered: Boolean = triggered.get() override def cursor(): BatchCursor[A] = { diff --git a/monix-tail/shared/src/test/scala/monix/tail/ThrowExceptionCursor.scala b/monix-tail/shared/src/test/scala/monix/tail/ThrowExceptionCursor.scala index 755e7639e..518cdf8f5 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/ThrowExceptionCursor.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/ThrowExceptionCursor.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,11 +22,11 @@ import monix.tail.batches.BatchCursor /** BatchCursor that throws exception on access. */ final class ThrowExceptionCursor[A](ex: Throwable) extends BatchCursor[A] { self => - private[this] val triggered = Atomic(false) + private val triggered = Atomic(false) def isTriggered: Boolean = triggered.get() private def triggerError(): Nothing = { - triggered := true + triggered.set(true) throw ex } diff --git a/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantCoevalSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantCoevalSuite.scala index 14e5ec49d..6221c36b0 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantCoevalSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantCoevalSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantIOSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantIOSuite.scala index bac2bbdc3..9cbb13686 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantIOSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantIOSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantTaskSuite.scala b/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantTaskSuite.scala index 38d8c8637..f79d20155 100644 --- a/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantTaskSuite.scala +++ b/monix-tail/shared/src/test/scala/monix/tail/TypeClassLawsForIterantTaskSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/monix/shared/src/main/scala/monix/package.scala b/monix/shared/src/main/scala/monix/package.scala index febe0aa0a..bea6a2f07 100644 --- a/monix/shared/src/main/scala/monix/package.scala +++ b/monix/shared/src/main/scala/monix/package.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/project/MimaFilters.scala b/project/MimaFilters.scala index 48a1ae9f5..e7f9d9aa2 100644 --- a/project/MimaFilters.scala +++ b/project/MimaFilters.scala @@ -2,109 +2,262 @@ import com.typesafe.tools.mima.core.ProblemFilters.exclude import com.typesafe.tools.mima.core._ object MimaFilters { - lazy val changesFor_3_2_0: Seq[ProblemFilter] = Seq( - // Signature change in internal instance - exclude[IncompatibleResultTypeProblem]("monix.catnap.internal.ParallelApplicative.apply"), - exclude[MissingClassProblem]("monix.eval.internal.TaskGather*") - ) - - lazy val changesFor_3_0_1: Seq[ProblemFilter] = Seq( - // Signature changes in internal classes - exclude[DirectMissingMethodProblem]("monix.execution.internal.Trampoline.*"), - exclude[DirectMissingMethodProblem]("monix.execution.schedulers.TrampolineExecutionContext#JVMNormalTrampoline.*"), - exclude[DirectMissingMethodProblem]("monix.execution.schedulers.TrampolineExecutionContext#JVMOptimalTrampoline.*") - ) - - lazy val changesFor_3_3_0 = Seq( - // Upgraded JCTools to 3.0.0 - exclude[IncompatibleMethTypeProblem]( - "monix.execution.internal.collection.queues.FromMessagePassingQueue#Java8SPMC.this" - ), - exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromCircularQueue#Java7.this"), - exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromCircularQueue#MPMC.this"), - exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromCircularQueue#Java8SPSC.this"), - exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromCircularQueue.apply"), - exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromCircularQueue.this"), - exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromMessagePassingQueue.apply"), - exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromMessagePassingQueue.this"), - exclude[IncompatibleMethTypeProblem]( - "monix.execution.internal.collection.queues.FromMessagePassingQueue#Java8SPSC.this" - ), - exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromMessagePassingQueue.apply"), - exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromCircularQueue.apply"), - exclude[IncompatibleMethTypeProblem]( - "monix.execution.internal.collection.queues.FromMessagePassingQueue#MPMC.this" - ), - exclude[MissingTypesProblem]("monix.execution.internal.collection.queues.QueueDrain"), - exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromCircularQueue#Java8MPSC.this"), - exclude[IncompatibleMethTypeProblem]( - "monix.execution.internal.collection.queues.FromMessagePassingQueue#Java8MPSC.this" - ), - exclude[IncompatibleMethTypeProblem]( - "monix.execution.internal.collection.queues.FromMessagePassingQueue#Java7.this" - ), - exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromCircularQueue#Java8SPMC.this"), - exclude[IncompatibleMethTypeProblem]( - "monix.reactive.observers.buffers.ConcurrentQueue#FromMessagePassingQueue.this" - ), - // Fixed annoying incremental compilation error with Coeval deprecations - exclude[MissingTypesProblem]("monix.eval.CoevalInstancesLevel0"), - exclude[MissingTypesProblem]("monix.eval.Coeval$DeprecatedExtensions"), - exclude[MissingTypesProblem]("monix.eval.Coeval$"), - exclude[MissingClassProblem]("monix.eval.internal.CoevalDeprecated$Companion"), - exclude[MissingClassProblem]("monix.eval.internal.CoevalDeprecated$Extensions"), - exclude[MissingClassProblem]("monix.eval.internal.CoevalDeprecated"), - exclude[MissingClassProblem]("monix.eval.internal.CoevalDeprecated$"), - // Fixed observable.takeLast, replaced with TakeLastObservable - exclude[MissingClassProblem]("monix.reactive.internal.operators.TakeLastOperator"), - // Changes in Task model due to Asynchronous Stack Traces - exclude[DirectMissingMethodProblem]("monix.eval.Task#Context.copy"), - exclude[DirectMissingMethodProblem]("monix.eval.Task#Context.this"), - exclude[IncompatibleMethTypeProblem]("monix.eval.Task#Context.apply"), - exclude[DirectMissingMethodProblem]("monix.eval.Task#Context.apply"), - exclude[IncompatibleMethTypeProblem]("monix.eval.Task#Map.apply"), - exclude[IncompatibleMethTypeProblem]("monix.eval.Task#Map.this"), - exclude[IncompatibleResultTypeProblem]("monix.eval.Task#Map.copy$default$3"), - exclude[DirectMissingMethodProblem]("monix.eval.Task#Map.index"), - exclude[IncompatibleMethTypeProblem]("monix.eval.Task#Map.copy"), - exclude[DirectMissingMethodProblem]("monix.eval.Task#FlatMap.apply"), - exclude[DirectMissingMethodProblem]("monix.eval.Task#FlatMap.this"), - exclude[DirectMissingMethodProblem]("monix.eval.Task#FlatMap.copy"), - exclude[DirectMissingMethodProblem]("monix.eval.Task#Async.apply"), - exclude[DirectMissingMethodProblem]("monix.eval.Task#Async.copy"), - exclude[DirectMissingMethodProblem]("monix.eval.Task#Async.this"), - // Signature changes in internal classes - exclude[DirectMissingMethodProblem]("monix.execution.CancelableFuture#Async*"), - exclude[DirectMissingMethodProblem]("monix.execution.CancelableFuture#Pure*"), - // Changes in Coeval model due to Better Stack Traces - exclude[DirectMissingMethodProblem]("monix.eval.Coeval#FlatMap.copy"), - exclude[DirectMissingMethodProblem]("monix.eval.Coeval#FlatMap.this"), - exclude[DirectMissingMethodProblem]("monix.eval.Coeval#Map.index"), - exclude[IncompatibleMethTypeProblem]("monix.eval.Coeval#Map.copy"), - exclude[IncompatibleResultTypeProblem]("monix.eval.Coeval#Map.copy$default$3"), - exclude[IncompatibleMethTypeProblem]("monix.eval.Coeval#Map.this"), - exclude[IncompatibleMethTypeProblem]("monix.eval.Coeval#Map.apply"), - exclude[DirectMissingMethodProblem]("monix.eval.Coeval#FlatMap.apply"), - // Remove unused fusionMaxStackDepth - exclude[DirectMissingMethodProblem]("monix.execution.internal.Platform.fusionMaxStackDepth"), - exclude[DirectMissingMethodProblem]("monix.execution.internal.Platform.fusionMaxStackDepth") - ) - - lazy val changesFor_3_4_0 = Seq( - // Remove redundant private interfaces after Scala 2.11 removal - exclude[MissingClassProblem]("monix.execution.internal.forkJoin.package"), - exclude[MissingClassProblem]("monix.execution.internal.forkJoin.package$"), - exclude[MissingClassProblem]("monix.execution.internal.forkJoin.package$ForkJoinPool$"), - exclude[MissingClassProblem]("monix.execution.misc.compat"), - exclude[MissingClassProblem]("monix.execution.misc.compat$"), - // Scala 3 / Dotty support - exclude[MissingClassProblem]("monix.execution.schedulers.AdaptedThreadPoolExecutorMixin") - ) - - lazy val changesFor_avs = Seq( - // TrampolineExecutionContext signature tweaks (internal API) - exclude[IncompatibleMethTypeProblem]("monix.execution.schedulers.TrampolineExecutionContext#JVMNormalTrampoline.startLoop"), - exclude[IncompatibleMethTypeProblem]("monix.execution.schedulers.TrampolineExecutionContext#JVMOptimalTrampoline.startLoop"), - exclude[IncompatibleMethTypeProblem]("monix.execution.schedulers.TrampolineExecutionContext.this") - ) + + // ── Per-sub-project filter buckets ────────────────────────────────────── + + object Monix { + lazy val all: Seq[ProblemFilter] = Seq.empty + } + + object MonixInternalJCTools { + lazy val all: Seq[ProblemFilter] = Seq.empty + } + + object MonixExecutionAtomic { + lazy val all: Seq[ProblemFilter] = Seq.empty + } + + object MonixExecution { + lazy val changesFor_3_0_1: Seq[ProblemFilter] = Seq( + exclude[DirectMissingMethodProblem]("monix.execution.internal.Trampoline.*"), + exclude[DirectMissingMethodProblem]( + "monix.execution.schedulers.TrampolineExecutionContext#JVMNormalTrampoline.*" + ), + exclude[DirectMissingMethodProblem]( + "monix.execution.schedulers.TrampolineExecutionContext#JVMOptimalTrampoline.*" + ) + ) + + lazy val changesFor_3_3_0: Seq[ProblemFilter] = Seq( + exclude[IncompatibleMethTypeProblem]( + "monix.execution.internal.collection.queues.FromMessagePassingQueue#Java8SPMC.this" + ), + exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromCircularQueue#Java7.this"), + exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromCircularQueue#MPMC.this"), + exclude[IncompatibleMethTypeProblem]( + "monix.execution.internal.collection.queues.FromCircularQueue#Java8SPSC.this" + ), + exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromCircularQueue.apply"), + exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromCircularQueue.this"), + exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromMessagePassingQueue.apply"), + exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromMessagePassingQueue.this"), + exclude[IncompatibleMethTypeProblem]( + "monix.execution.internal.collection.queues.FromMessagePassingQueue#Java8SPSC.this" + ), + exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromMessagePassingQueue.apply"), + exclude[IncompatibleMethTypeProblem]("monix.execution.internal.collection.queues.FromCircularQueue.apply"), + exclude[IncompatibleMethTypeProblem]( + "monix.execution.internal.collection.queues.FromMessagePassingQueue#MPMC.this" + ), + exclude[MissingTypesProblem]("monix.execution.internal.collection.queues.QueueDrain"), + exclude[IncompatibleMethTypeProblem]( + "monix.execution.internal.collection.queues.FromCircularQueue#Java8MPSC.this" + ), + exclude[IncompatibleMethTypeProblem]( + "monix.execution.internal.collection.queues.FromMessagePassingQueue#Java8MPSC.this" + ), + exclude[IncompatibleMethTypeProblem]( + "monix.execution.internal.collection.queues.FromMessagePassingQueue#Java7.this" + ), + exclude[IncompatibleMethTypeProblem]( + "monix.execution.internal.collection.queues.FromCircularQueue#Java8SPMC.this" + ), + exclude[MissingTypesProblem]("monix.execution.Scheduler$Extensions"), + exclude[MissingClassProblem]("monix.execution.internal.forkJoin.package"), + exclude[MissingClassProblem]("monix.execution.internal.forkJoin.package$"), + exclude[MissingClassProblem]("monix.execution.internal.forkJoin.package$ForkJoinPool$"), + exclude[MissingClassProblem]("monix.execution.schedulers.ExecuteExtensions"), + exclude[DirectMissingMethodProblem]("monix.execution.CancelableFuture#Async*"), + exclude[DirectMissingMethodProblem]("monix.execution.CancelableFuture#Pure*"), + exclude[DirectMissingMethodProblem]("monix.execution.internal.Platform.fusionMaxStackDepth"), + exclude[DirectMissingMethodProblem]("monix.execution.internal.Platform.fusionMaxStackDepth") + ) + + lazy val changesFor_3_4_0: Seq[ProblemFilter] = Seq( + exclude[MissingClassProblem]("monix.execution.internal.forkJoin.package"), + exclude[MissingClassProblem]("monix.execution.internal.forkJoin.package$"), + exclude[MissingClassProblem]("monix.execution.internal.forkJoin.package$ForkJoinPool$"), + exclude[MissingClassProblem]("monix.execution.misc.compat"), + exclude[MissingClassProblem]("monix.execution.misc.compat$"), + exclude[MissingClassProblem]("monix.execution.schedulers.AdaptedThreadPoolExecutorMixin") + ) + + lazy val changesFor_3_5_0: Seq[ProblemFilter] = Seq( + exclude[MissingClassProblem]("monix.execution.atomic.Atomic"), + exclude[MissingClassProblem]("monix.execution.atomic.Atomic$"), + exclude[MissingClassProblem]("monix.execution.atomic.Atomic$Macros"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicAny"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicAny$"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicBoolean"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicBoolean$"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicBuilder"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicBuilder$"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicBuilder$AtomicBooleanBuilder$"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicBuilder$AtomicByteBuilder$"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicBuilder$AtomicCharBuilder$"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicBuilder$AtomicDoubleBuilder$"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicBuilder$AtomicFloatBuilder$"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicBuilder$AtomicIntBuilder$"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicBuilder$AtomicLongBuilder$"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicBuilder$AtomicShortBuilder$"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicByte"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicByte$"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicChar"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicChar$"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicDouble"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicDouble$"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicFloat"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicFloat$"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicInt"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicInt$"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicLong"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicLong$"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicNumber"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicNumberAny"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicNumberAny$"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicShort"), + exclude[MissingClassProblem]("monix.execution.atomic.AtomicShort$"), + exclude[MissingClassProblem]("monix.execution.atomic.Implicits"), + exclude[MissingClassProblem]("monix.execution.atomic.Implicits$"), + exclude[MissingClassProblem]("monix.execution.atomic.Implicits$Level1"), + exclude[MissingClassProblem]("monix.execution.atomic.Implicits$Level2"), + exclude[MissingClassProblem]("monix.execution.atomic.PaddingStrategy"), + exclude[MissingClassProblem]("monix.execution.atomic.PaddingStrategy$"), + exclude[MissingClassProblem]("monix.execution.atomic.PaddingStrategy$Left128$"), + exclude[MissingClassProblem]("monix.execution.atomic.PaddingStrategy$Left64$"), + exclude[MissingClassProblem]("monix.execution.atomic.PaddingStrategy$LeftRight128$"), + exclude[MissingClassProblem]("monix.execution.atomic.PaddingStrategy$LeftRight256$"), + exclude[MissingClassProblem]("monix.execution.atomic.PaddingStrategy$NoPadding$"), + exclude[MissingClassProblem]("monix.execution.atomic.PaddingStrategy$Right128$"), + exclude[MissingClassProblem]("monix.execution.atomic.PaddingStrategy$Right64$"), + exclude[MissingClassProblem]("monix.execution.atomic.package"), + exclude[MissingClassProblem]("monix.execution.atomic.package$"), + exclude[MissingClassProblem]("monix.execution.internal.InternalApi"), + exclude[MissingClassProblem]("monix.execution.internal.atomic.BoxPaddingStrategy"), + exclude[MissingClassProblem]("monix.execution.internal.atomic.BoxedInt"), + exclude[MissingClassProblem]("monix.execution.internal.atomic.BoxedLong"), + exclude[MissingClassProblem]("monix.execution.internal.atomic.BoxedObject"), + exclude[MissingClassProblem]("monix.execution.internal.atomic.Factory"), + exclude[MissingClassProblem]("monix.execution.internal.atomic.UnsafeAccess"), + exclude[MissingClassProblem]("monix.execution.internal.collection.queues.FromCircularQueue$Java7"), + exclude[MissingClassProblem]("monix.execution.internal.collection.queues.FromMessagePassingQueue$Java7"), + exclude[MissingClassProblem]("monix.execution.misc.HygieneUtilMacros"), + exclude[MissingClassProblem]("monix.execution.misc.HygieneUtilMacros$util$"), + exclude[MissingClassProblem]("monix.execution.misc.InlineMacros"), + exclude[MissingClassProblem]("monix.execution.misc.Local$Macros"), + exclude[MissingClassProblem]("monix.execution.misc.test.TestBox"), + exclude[MissingClassProblem]("monix.execution.misc.test.TestBox$"), + exclude[MissingClassProblem]("monix.execution.misc.test.TestBox$Macros"), + exclude[MissingClassProblem]("monix.execution.misc.test.TestInlineMacros"), + exclude[MissingClassProblem]("monix.execution.misc.test.TestInlineMacros$"), + exclude[MissingClassProblem]("monix.execution.misc.test.TestInlineMacros$Macros"), + exclude[DirectMissingMethodProblem]("monix.execution.AsyncQueue.$default$3"), + exclude[IncompatibleResultTypeProblem]("monix.execution.cancelables.AssignableCancelable.alreadyCanceled"), + exclude[IncompatibleResultTypeProblem]("monix.execution.cancelables.BooleanCancelable.alreadyCanceled") + ) + + lazy val changesFor_avs: Seq[ProblemFilter] = Seq( + // TrampolineExecutionContext signature tweaks (internal API) + exclude[IncompatibleMethTypeProblem]( + "monix.execution.schedulers.TrampolineExecutionContext#JVMNormalTrampoline.startLoop" + ), + exclude[IncompatibleMethTypeProblem]( + "monix.execution.schedulers.TrampolineExecutionContext#JVMOptimalTrampoline.startLoop" + ), + exclude[IncompatibleMethTypeProblem]("monix.execution.schedulers.TrampolineExecutionContext.this") + ) + + lazy val all: Seq[ProblemFilter] = + Seq(changesFor_3_0_1, changesFor_3_3_0, changesFor_3_4_0, changesFor_3_5_0, changesFor_avs).flatten + } + + object MonixCatnap { + lazy val changesFor_3_2_0: Seq[ProblemFilter] = Seq( + exclude[IncompatibleResultTypeProblem]("monix.catnap.internal.ParallelApplicative.apply") + ) + + lazy val changesFor_3_5_0: Seq[ProblemFilter] = Seq( + exclude[DirectMissingMethodProblem]("monix.catnap.ConcurrentChannel#ChanConsumer.this"), + exclude[DirectMissingMethodProblem]("monix.catnap.ConcurrentChannel#ChanProducer.this"), + exclude[IncompatibleResultTypeProblem]("monix.catnap.cancelables.AssignableCancelableF.alreadyCanceled"), + exclude[IncompatibleResultTypeProblem]("monix.catnap.cancelables.BooleanCancelableF.alreadyCanceled") + ) + + lazy val all: Seq[ProblemFilter] = Seq(changesFor_3_2_0, changesFor_3_5_0).flatten + } + + object MonixEval { + lazy val changesFor_3_2_0: Seq[ProblemFilter] = Seq( + exclude[MissingClassProblem]("monix.eval.internal.TaskGather*") + ) + + lazy val changesFor_3_3_0: Seq[ProblemFilter] = Seq( + exclude[MissingTypesProblem]("monix.eval.CoevalInstancesLevel0"), + exclude[MissingTypesProblem]("monix.eval.Coeval$DeprecatedExtensions"), + exclude[MissingTypesProblem]("monix.eval.Coeval$"), + exclude[MissingClassProblem]("monix.eval.internal.CoevalDeprecated$Companion"), + exclude[MissingClassProblem]("monix.eval.internal.CoevalDeprecated$Extensions"), + exclude[MissingClassProblem]("monix.eval.internal.CoevalDeprecated"), + exclude[MissingClassProblem]("monix.eval.internal.CoevalDeprecated$"), + exclude[DirectMissingMethodProblem]("monix.eval.Task#Context.copy"), + exclude[DirectMissingMethodProblem]("monix.eval.Task#Context.this"), + exclude[IncompatibleMethTypeProblem]("monix.eval.Task#Context.apply"), + exclude[DirectMissingMethodProblem]("monix.eval.Task#Context.apply"), + exclude[IncompatibleMethTypeProblem]("monix.eval.Task#Map.apply"), + exclude[IncompatibleMethTypeProblem]("monix.eval.Task#Map.this"), + exclude[IncompatibleResultTypeProblem]("monix.eval.Task#Map.copy$default$3"), + exclude[DirectMissingMethodProblem]("monix.eval.Task#Map.index"), + exclude[IncompatibleMethTypeProblem]("monix.eval.Task#Map.copy"), + exclude[DirectMissingMethodProblem]("monix.eval.Task#FlatMap.apply"), + exclude[DirectMissingMethodProblem]("monix.eval.Task#FlatMap.this"), + exclude[DirectMissingMethodProblem]("monix.eval.Task#FlatMap.copy"), + exclude[DirectMissingMethodProblem]("monix.eval.Task#Async.apply"), + exclude[DirectMissingMethodProblem]("monix.eval.Task#Async.copy"), + exclude[DirectMissingMethodProblem]("monix.eval.Task#Async.this"), + exclude[DirectMissingMethodProblem]("monix.eval.Coeval#FlatMap.copy"), + exclude[DirectMissingMethodProblem]("monix.eval.Coeval#FlatMap.this"), + exclude[DirectMissingMethodProblem]("monix.eval.Coeval#Map.index"), + exclude[IncompatibleMethTypeProblem]("monix.eval.Coeval#Map.copy"), + exclude[IncompatibleResultTypeProblem]("monix.eval.Coeval#Map.copy$default$3"), + exclude[IncompatibleMethTypeProblem]("monix.eval.Coeval#Map.this"), + exclude[IncompatibleMethTypeProblem]("monix.eval.Coeval#Map.apply"), + exclude[DirectMissingMethodProblem]("monix.eval.Coeval#FlatMap.apply") + ) + + lazy val changesFor_3_5_0: Seq[ProblemFilter] = Seq( + exclude[DirectMissingMethodProblem]("monix.eval.internal.TaskMapBoth#Register.sendSignal") + ) + + lazy val all: Seq[ProblemFilter] = Seq(changesFor_3_2_0, changesFor_3_3_0, changesFor_3_5_0).flatten + } + + object MonixTail { + lazy val changesFor_3_5_0: Seq[ProblemFilter] = Seq( + exclude[DirectMissingMethodProblem]("monix.tail.internal.IterantZipMap#Loop.processOneASeqB"), + exclude[DirectMissingMethodProblem]("monix.tail.IterantBuilders#Apply.suspend$extension") + ) + + lazy val all: Seq[ProblemFilter] = Seq(changesFor_3_5_0).flatten + } + + object MonixReactive { + lazy val changesFor_3_3_0: Seq[ProblemFilter] = Seq( + exclude[IncompatibleMethTypeProblem]( + "monix.reactive.observers.buffers.ConcurrentQueue#FromMessagePassingQueue.this" + ), + exclude[MissingClassProblem]("monix.reactive.internal.operators.TakeLastOperator") + ) + + lazy val changesFor_3_5_0: Seq[ProblemFilter] = Seq( + exclude[DirectMissingMethodProblem]("monix.reactive.subjects.ConcurrentSubject.async"), + exclude[MissingClassProblem]("monix.reactive.internal.operators.CollectWhileOperator"), + exclude[MissingClassProblem]("monix.reactive.internal.operators.CollectWhileOperator$") + ) + + lazy val all: Seq[ProblemFilter] = Seq(changesFor_3_3_0, changesFor_3_5_0).flatten + } + + object MonixJava { + lazy val all: Seq[ProblemFilter] = Seq.empty + } } diff --git a/project/MonixBuildUtils.scala b/project/MonixBuildUtils.scala index c6f07eb72..9c7a30f5f 100644 --- a/project/MonixBuildUtils.scala +++ b/project/MonixBuildUtils.scala @@ -11,7 +11,11 @@ import scala.xml.Elem import scala.xml.transform.{ RewriteRule, RuleTransformer } final case class MonixScalaVersion(value: String) { - lazy val parts = value.split("[.]").filter(_.nonEmpty).toList + lazy val parts = + value.split("[.]").filter(_.nonEmpty).toList + + def filterPrefix(prefix: String): Option[MonixScalaVersion] = + if (value.startsWith(prefix)) Some(this) else None } object MonixScalaVersion { @@ -47,8 +51,8 @@ object MonixBuildUtils { /** Applies [[filterOutDependencyFromGeneratedPomXml]] to a list of multiple dependencies. */ def filterOutMultipleDependenciesFromGeneratedPomXml(list: List[(String, Regex)]*) = - list.foldLeft(List.empty[Def.Setting[_]]) { (acc, elem) => - acc ++ filterOutDependencyFromGeneratedPomXml(elem: _*) + list.foldLeft(List.empty[Def.Setting[?]]) { (acc, elem) => + acc ++ filterOutDependencyFromGeneratedPomXml(elem*) } /** Filter out dependencies from the generated `pom.xml`. @@ -117,7 +121,7 @@ object MonixBuildUtils { .toSeq assert(scalaVersions.nonEmpty, "build.yml is corrupt, suitable scala_version_* keys missing") - SortedSet(scalaVersions: _*) + SortedSet(scalaVersions*) } } } diff --git a/project/build.properties b/project/build.properties index 757db63d2..2566b02e0 100644 --- a/project/build.properties +++ b/project/build.properties @@ -15,4 +15,4 @@ # limitations under the License. # -sbt.version=1.12.6 +sbt.version=1.12.8 diff --git a/project/build.sbt b/project/build.sbt index 514eff67d..28364867e 100644 --- a/project/build.sbt +++ b/project/build.sbt @@ -1 +1,6 @@ -libraryDependencies += "org.yaml" % "snakeyaml" % "1.28" +libraryDependencies += "org.yaml" % "snakeyaml" % "2.5" + +// Resolve version conflicts in build plugins +ThisBuild / libraryDependencySchemes ++= Seq( + "com.lihaoyi" %% "geny" % VersionScheme.Always +) diff --git a/project/plugins.sbt b/project/plugins.sbt index cc1d1c1ba..cff20dc57 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,15 +1,16 @@ -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.20.2") -addSbtPlugin("com.github.sbt" % "sbt-unidoc" % "0.5.0") -addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.7") -addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.4") -addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.10.0") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.6") -addSbtPlugin("io.github.sbt-doctest" % "sbt-doctest" % "0.12.4") -addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.3.1") -addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.2.0") -addSbtPlugin("net.bzzt" % "sbt-reproducible-builds" % "0.32") -addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.3") -addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.1.0") -addSbtPlugin("com.github.sbt" % "sbt-git" % "2.1.0") -addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.12.2") -addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.1") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.20.2") +addSbtPlugin("com.github.sbt" % "sbt-unidoc" % "0.6.1") +addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.8") +addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.4") +addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.10.0") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.6") +addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.4.4") +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.1") +addSbtPlugin("net.bzzt" % "sbt-reproducible-builds" % "0.32") +addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.2") +addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.1.1") +addSbtPlugin("com.github.sbt" % "sbt-git" % "2.1.0") +addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.12.2") +addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.1") + +libraryDependencies += "org.typelevel" %% "scalac-options" % "0.1.9" diff --git a/reactiveTests/src/test/scala/monix/reactiveTests/IterantToPublisherTest.scala b/reactiveTests/src/test/scala/monix/reactiveTests/IterantToPublisherTest.scala index 5b3c1bda4..5f545dbbc 100644 --- a/reactiveTests/src/test/scala/monix/reactiveTests/IterantToPublisherTest.scala +++ b/reactiveTests/src/test/scala/monix/reactiveTests/IterantToPublisherTest.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,8 +22,8 @@ import monix.execution.Scheduler.Implicits.global import monix.eval.Task import monix.execution.exceptions.DummyException import monix.tail.Iterant -import monix.tail.Iterant.{Halt, Last} -import monix.tail.batches.{Batch, BatchCursor} +import monix.tail.Iterant.{ Halt, Last } +import monix.tail.batches.{ Batch, BatchCursor } import org.reactivestreams.Publisher import org.reactivestreams.tck.PublisherVerification import org.scalatestplus.testng.TestNGSuiteLike @@ -38,8 +38,7 @@ class IterantToPublisherTest extends PublisherVerification[Long](env()) val list: List[Long] = (0 until elements.toInt).map(_.toLong).toList arbitraryListToIterant[Task, Long](list, Random.nextInt(), allowErrors = false) .toReactivePublisher - } - else if (elements <= Int.MaxValue) + } else if (elements <= Int.MaxValue) repeat(1L).take(elements.toInt).toReactivePublisher else repeat(1L).toReactivePublisher @@ -53,8 +52,9 @@ class IterantToPublisherTest extends PublisherVerification[Long](env()) .toReactivePublisher } - def arbitraryListToIterant[F[_], A](list: List[A], idx: Int, allowErrors: Boolean = true) - (implicit F: Sync[F]): Iterant[F, A] = { + def arbitraryListToIterant[F[_], A](list: List[A], idx: Int, allowErrors: Boolean = true)(implicit + F: Sync[F] + ): Iterant[F, A] = { def loop(list: List[A], idx: Int): Iterant[F, A] = list match { @@ -73,15 +73,15 @@ class IterantToPublisherTest extends PublisherVerification[Long](env()) case ns => math.abs(idx % 16) match { case 0 | 1 => - Iterant[F].nextS(ns.head, F.delay(loop(ns.tail, idx+1))) + Iterant[F].nextS(ns.head, F.delay(loop(ns.tail, idx + 1))) case 2 | 3 => - Iterant[F].suspend(F.delay(loop(list, idx+1))) + Iterant[F].suspend(F.delay(loop(list, idx + 1))) case 4 | 5 => Iterant[F].suspendS(F.delay(loop(ns, idx + 1))) case n @ 6 => val (headSeq, tail) = list.splitAt(3) val cursor = BatchCursor.fromIterator(headSeq.toVector.iterator, n - 2) - Iterant[F].nextCursorS(cursor, F.delay(loop(tail, idx+1))) + Iterant[F].nextCursorS(cursor, F.delay(loop(tail, idx + 1))) case n @ (7 | 8 | 9) => val (headSeq, tail) = list.splitAt(3) val batch = Batch.fromSeq(headSeq.toVector, n - 6) diff --git a/reactiveTests/src/test/scala/monix/reactiveTests/ObservableToPublisherTest.scala b/reactiveTests/src/test/scala/monix/reactiveTests/ObservableToPublisherTest.scala index 299d9f620..17bf461ac 100644 --- a/reactiveTests/src/test/scala/monix/reactiveTests/ObservableToPublisherTest.scala +++ b/reactiveTests/src/test/scala/monix/reactiveTests/ObservableToPublisherTest.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -49,4 +49,4 @@ class ObservableToPublisherTest extends PublisherVerification[Long](env()) .asInstanceOf[Observable[Long]] .toReactivePublisher } -} \ No newline at end of file +} diff --git a/reactiveTests/src/test/scala/monix/reactiveTests/SubscriberWhiteBoxAsyncTest.scala b/reactiveTests/src/test/scala/monix/reactiveTests/SubscriberWhiteBoxAsyncTest.scala index 089e2dc13..a0b4beb2f 100644 --- a/reactiveTests/src/test/scala/monix/reactiveTests/SubscriberWhiteBoxAsyncTest.scala +++ b/reactiveTests/src/test/scala/monix/reactiveTests/SubscriberWhiteBoxAsyncTest.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,7 +24,7 @@ import monix.reactive.Observer import monix.reactiveTests.SubscriberWhiteBoxAsyncTest.Value import org.reactivestreams.tck.SubscriberWhiteboxVerification.WhiteboxSubscriberProbe import org.reactivestreams.tck.SubscriberWhiteboxVerification -import org.reactivestreams.{Subscriber, Subscription} +import org.reactivestreams.{ Subscriber, Subscription } import org.scalatestplus.testng.TestNGSuiteLike import scala.concurrent.Future diff --git a/reactiveTests/src/test/scala/monix/reactiveTests/SubscriberWhiteBoxSyncTest.scala b/reactiveTests/src/test/scala/monix/reactiveTests/SubscriberWhiteBoxSyncTest.scala index 1ce7f36d7..b2c4a4293 100644 --- a/reactiveTests/src/test/scala/monix/reactiveTests/SubscriberWhiteBoxSyncTest.scala +++ b/reactiveTests/src/test/scala/monix/reactiveTests/SubscriberWhiteBoxSyncTest.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ import monix.execution.Ack.Continue import monix.reactiveTests.SubscriberWhiteBoxSyncTest.Value import org.reactivestreams.tck.SubscriberWhiteboxVerification.WhiteboxSubscriberProbe import org.reactivestreams.tck.SubscriberWhiteboxVerification -import org.reactivestreams.{Subscriber, Subscription} +import org.reactivestreams.{ Subscriber, Subscription } import org.scalatestplus.testng.TestNGSuiteLike class SubscriberWhiteBoxSyncTest diff --git a/reactiveTests/src/test/scala/monix/reactiveTests/package.scala b/reactiveTests/src/test/scala/monix/reactiveTests/package.scala index 335b5424e..a697f1c05 100644 --- a/reactiveTests/src/test/scala/monix/reactiveTests/package.scala +++ b/reactiveTests/src/test/scala/monix/reactiveTests/package.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tracingTests/src/test/scala/tracing/CachedStackTracingSuite.scala b/tracingTests/src/test/scala/tracing/CachedStackTracingSuite.scala index be71c8006..842c350ca 100644 --- a/tracingTests/src/test/scala/tracing/CachedStackTracingSuite.scala +++ b/tracingTests/src/test/scala/tracing/CachedStackTracingSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,8 +17,8 @@ package tracing -import monix.eval.tracing.{TaskEvent, TaskTrace} -import monix.eval.{BaseTestSuite, Task} +import monix.eval.tracing.{ TaskEvent, TaskTrace } +import monix.eval.{ BaseTestSuite, Task } /** * All Credits to https://github.com/typelevel/cats-effect and https://github.com/RaasAhsan @@ -36,7 +36,8 @@ object CachedStackTracingSuite extends BaseTestSuite { assertEquals(r.captured, 4) assertEquals( r.events.collect { case e: TaskEvent.StackTrace => e }.count(_.stackTrace.exists(_.getMethodName == "map")), - 3) + 3 + ) } test.runToFuture @@ -66,7 +67,8 @@ object CachedStackTracingSuite extends BaseTestSuite { assertEquals(r.captured, 5) assertEquals( r.events.collect { case e: TaskEvent.StackTrace => e }.count(_.stackTrace.exists(_.getMethodName == "async")), - 1) + 1 + ) } test.runToFuture @@ -81,7 +83,8 @@ object CachedStackTracingSuite extends BaseTestSuite { assertEquals( r.events.collect { case e: TaskEvent.StackTrace => e } .count(_.stackTrace.exists(_.getMethodName == "bracket")), - 1) + 1 + ) } test.runToFuture @@ -97,7 +100,8 @@ object CachedStackTracingSuite extends BaseTestSuite { assertEquals( r.events.collect { case e: TaskEvent.StackTrace => e } .count(_.stackTrace.exists(_.getMethodName == "bracketCase")), - 1) + 1 + ) } test.runToFuture diff --git a/tracingTests/src/test/scala/tracing/TracingSuite.scala b/tracingTests/src/test/scala/tracing/TracingSuite.scala index 72dafcb34..64eb5170c 100644 --- a/tracingTests/src/test/scala/tracing/TracingSuite.scala +++ b/tracingTests/src/test/scala/tracing/TracingSuite.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2021 by The Monix Project Developers. + * Copyright (c) 2014-2022 Monix Contributors. * See the project homepage at: https://monix.io * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ package tracing import monix.eval.tracing.TaskTrace -import monix.eval.{BaseTestSuite, Task} +import monix.eval.{ BaseTestSuite, Task } import scala.util.control.NoStackTrace import cats.syntax.all._ @@ -51,13 +51,13 @@ object TracingSuite extends BaseTestSuite { testAsync("enhanced exceptions are not augmented more than once") { _ => val task = for { - _ <- Task.pure(1) - _ <- Task.pure(2) - _ <- Task.pure(3) - _ <- Task.shift - _ <- Task.pure(1) - _ <- Task.pure(2) - _ <- Task.pure(3) + _ <- Task.pure(1) + _ <- Task.pure(2) + _ <- Task.pure(3) + _ <- Task.shift + _ <- Task.pure(1) + _ <- Task.pure(2) + _ <- Task.pure(3) e1 <- Task.raiseError(new Throwable("Encountered an error")).attempt e2 <- Task.pure(e1).rethrow.attempt } yield (e1, e2)