Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Use scalafmt to group imports #63

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
version = 3.7.17
version = 3.8.1
runner.dialect = scala3
maxColumn = 120

rewrite {
rules = [
Imports
]

imports {
expand = false
sort = ascii
groups = [
["gears\\..*"],
["java.?\\..*", "scala\\..*"],
]
}
}
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}
import sbtcrossproject.CrossPlugin.autoImport.{CrossType, crossProject}
import scalanative.build._

ThisBuild / scalaVersion := "3.3.3"
Expand Down
9 changes: 5 additions & 4 deletions jvm/src/main/scala/PosixLikeIO/PIO.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package PosixLikeIO

import gears.async.{Async, Future}
import gears.async.Scheduler
import gears.async.default.given
import Future.Promise
import gears.async.{Async, Future}

import java.net.{DatagramPacket, DatagramSocket, InetAddress, InetSocketAddress, ServerSocket, Socket}
import java.nio.ByteBuffer
import java.nio.channels.{AsynchronousFileChannel, CompletionHandler, SocketChannel}
import java.nio.charset.{Charset, StandardCharsets}
import java.nio.file.{Path, StandardOpenOption}
import java.util.concurrent.CancellationException
import scala.Tuple.Union
import scala.concurrent.ExecutionContext
import scala.util.{Failure, Success, Try}
import gears.async.Scheduler
import java.util.concurrent.CancellationException

import Future.Promise

object File:
extension (resolver: Future.Resolver[Int])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package PosixLikeIO.examples

import gears.async.AsyncOperations.*
import gears.async.default.given
import gears.async.{Async, Future}
import gears.async.AsyncOperations.*
import PosixLikeIO.{PIOHelper, SocketUDP}

import java.net.DatagramPacket
import java.nio.ByteBuffer
import java.nio.file.StandardOpenOption
import scala.concurrent.ExecutionContext

import PosixLikeIO.{PIOHelper, SocketUDP}

@main def clientAndServerUDP(): Unit =
given ExecutionContext = ExecutionContext.global
Async.blocking:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package PosixLikeIO.examples

import gears.async.Async
import gears.async.default.given
import PosixLikeIO.PIOHelper

import java.nio.ByteBuffer
import java.nio.charset.StandardCharsets
import java.nio.file.StandardOpenOption
import scala.concurrent.ExecutionContext

import PosixLikeIO.PIOHelper

@main def readAndWriteFile(): Unit =
given ExecutionContext = ExecutionContext.global
Async.blocking:
Expand Down
3 changes: 2 additions & 1 deletion jvm/src/main/scala/PosixLikeIO/examples/readWholeFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package PosixLikeIO.examples

import gears.async.Async
import gears.async.default.given
import PosixLikeIO.PIOHelper

import java.nio.ByteBuffer
import java.nio.charset.StandardCharsets
import java.nio.file.StandardOpenOption
import scala.concurrent.ExecutionContext

import PosixLikeIO.PIOHelper

@main def readWholeFile(): Unit =
given ExecutionContext = ExecutionContext.global
Async.blocking:
Expand Down
4 changes: 2 additions & 2 deletions jvm/src/main/scala/async/VThreadSupport.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package gears.async

import scala.annotation.unchecked.uncheckedVariance
import java.lang.invoke.{MethodHandles, VarHandle}
import java.util.concurrent.locks.ReentrantLock
import scala.annotation.unchecked.uncheckedVariance
import scala.concurrent.duration.FiniteDuration
import java.lang.invoke.{VarHandle, MethodHandles}

object VThreadScheduler extends Scheduler:
private val VTFactory = Thread
Expand Down
9 changes: 5 additions & 4 deletions jvm/src/main/scala/measurements/measureTimes.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package measurements

import PosixLikeIO.PIOHelper
import gears.async.{Async, BufferedChannel, ChannelMultiplexer, Future, SyncChannel}
import gears.async.default.given
import gears.async.{Async, BufferedChannel, ChannelMultiplexer, Future, SyncChannel}

import java.io.{FileReader, FileWriter}
import java.nio.file.{Files, NoSuchFileException, Paths, StandardOpenOption}
import java.util.concurrent.atomic.AtomicInteger
import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, HashMap}
import scala.concurrent.ExecutionContext
import java.util.concurrent.atomic.AtomicInteger
import scala.util.Try
import scala.util.CommandLineParser.FromString.given_FromString_Int
import scala.util.Try

import PosixLikeIO.PIOHelper

case class TimeMeasurementResult(millisecondsPerOperation: Double, standardDeviation: Double)

Expand Down
12 changes: 7 additions & 5 deletions jvm/src/test/scala/CancellationBehavior.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import gears.async.{Async, Future, AsyncSupport, uninterruptible}
import gears.async.AsyncOperations.*
import gears.async.default.given
import scala.util.boundary
import boundary.break
import scala.concurrent.duration.{Duration, DurationInt}
import gears.async.{Async, AsyncSupport, Future, uninterruptible}

import java.util.concurrent.CancellationException
import scala.util.Success
import scala.concurrent.duration.{Duration, DurationInt}
import scala.util.Properties
import scala.util.Success
import scala.util.boundary

import boundary.break

// JVM-only since `munitTimeout` is not available on scala native.
// See (here)[https://scalameta.org/munit/docs/tests.html#customize-test-timeouts].
Expand Down
9 changes: 5 additions & 4 deletions native/src/main/scala/async/ForkJoinSupport.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package gears.async.native

import gears.async.Future.Promise
import gears.async._
import scala.scalanative.runtime.{Continuations => nativeContinuations}

import java.util.concurrent.CancellationException
import java.util.concurrent.ForkJoinPool
import java.util.concurrent.atomic.AtomicBoolean
import scala.concurrent.ExecutionContext
import scala.concurrent.JavaConversions._
import scala.concurrent.duration._
import java.util.concurrent.atomic.AtomicBoolean
import gears.async.Future.Promise
import java.util.concurrent.CancellationException
import scala.scalanative.runtime.{Continuations => nativeContinuations}

class NativeContinuation[-T, +R] private[native] (val cont: T => R) extends Suspension[T, R]:
def resume(arg: T): R = cont(arg)
Expand Down
10 changes: 6 additions & 4 deletions shared/src/main/scala/async/Async.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package gears.async

import gears.async.Listener.NumberedLock
import gears.async.Listener.withLock

import java.util.concurrent.atomic.AtomicBoolean
import scala.collection.mutable
import java.util.concurrent.locks.ReentrantLock
import java.util.concurrent.atomic.AtomicLong
import gears.async.Listener.withLock
import gears.async.Listener.NumberedLock
import java.util.concurrent.locks.ReentrantLock
import scala.collection.mutable
import scala.util.boundary

/** The async context: provides the capability to asynchronously [[Async.await await]] for [[Async.Source Source]]s, and
Expand Down
5 changes: 3 additions & 2 deletions shared/src/main/scala/async/AsyncOperations.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package gears.async

import scala.concurrent.duration.FiniteDuration
import java.util.concurrent.TimeoutException
import gears.async.AsyncOperations.sleep

import java.util.concurrent.TimeoutException
import scala.concurrent.duration.FiniteDuration

/** Defines fundamental operations that require the support of the scheduler. This is commonly provided alongside with
* the given implementation of [[Scheduler]].
* @see
Expand Down
3 changes: 2 additions & 1 deletion shared/src/main/scala/async/CompletionGroup.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package gears.async
import scala.collection.mutable
import Future.Promise
import scala.util.Success

import Future.Promise

/** A group of cancellable objects that are completed together. Cancelling the group means cancelling all its
* uncompleted members.
*/
Expand Down
3 changes: 2 additions & 1 deletion shared/src/main/scala/async/Listener.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package gears.async

import scala.annotation.tailrec
import gears.async.Async.Source

import java.util.concurrent.locks.ReentrantLock
import scala.annotation.tailrec

/** A listener, representing an one-time value receiver of an [[Async.Source]].
*
Expand Down
2 changes: 1 addition & 1 deletion shared/src/main/scala/async/ScalaConverters.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gears.async

import scala.concurrent.{Future as StdFuture, Promise as StdPromise}
import scala.concurrent.ExecutionContext
import scala.concurrent.{Future as StdFuture, Promise as StdPromise}
import scala.util.Try

/** Converters from Gears types to Scala API types and back. */
Expand Down
13 changes: 7 additions & 6 deletions shared/src/main/scala/async/Timer.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package gears.async

import Future.Promise
import AsyncOperations.sleep
import gears.async.Listener

import java.util.concurrent.CancellationException
import java.util.concurrent.TimeoutException
import scala.annotation.tailrec
import scala.collection.mutable
import scala.concurrent.TimeoutException
import scala.util.{Failure, Success, Try}
import gears.async.Listener
import scala.concurrent.duration._
import scala.annotation.tailrec
import java.util.concurrent.CancellationException
import scala.util.{Failure, Success, Try}

import AsyncOperations.sleep
import Future.Promise

/** Timer exposes a steady [[Async.Source]] of ticks that happens every `tickDuration` milliseconds. Note that the timer
* does not start ticking until `start` is called (which is a blocking operation, until the timer is cancelled).
Expand Down
13 changes: 6 additions & 7 deletions shared/src/main/scala/async/channels.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package gears.async
import scala.collection.mutable
import mutable.{ArrayBuffer, ListBuffer}

import scala.util.{Failure, Success, Try}

import scala.util.control.Breaks.{break, breakable}
import gears.async.Async.Source
import gears.async.listeners.lockBoth
import gears.async.Listener.acceptingListener
import gears.async.listeners.lockBoth

import scala.collection.mutable
import scala.util.control.Breaks.{break, breakable}
import scala.util.{Failure, Success, Try}

import Channel.{Closed, Res}
import mutable.{ArrayBuffer, ListBuffer}

/** The part of a channel one can send values to. Blocking behavior depends on the implementation.
*/
Expand Down
10 changes: 5 additions & 5 deletions shared/src/main/scala/async/futures.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package gears.async

import scala.collection.mutable
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.CancellationException
import scala.compiletime.uninitialized
import scala.annotation.unchecked.uncheckedVariance
import java.util.concurrent.atomic.AtomicBoolean
import scala.annotation.tailrec
import scala.annotation.unchecked.uncheckedVariance
import scala.collection.mutable
import scala.compiletime.uninitialized
import scala.util
import scala.util.{Failure, Success, Try}
import scala.util.control.NonFatal
import scala.util.{Failure, Success, Try}

/** Futures are [[Async.Source Source]]s that has the following properties:
* - They represent a single value: Once resolved, [[Async.await await]]-ing on a [[Future]] should always return the
Expand Down
4 changes: 3 additions & 1 deletion shared/src/main/scala/async/listeners/locking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
package gears.async.listeners

import gears.async._
import Listener.ListenerLock

import scala.annotation.tailrec

import Listener.ListenerLock

/** Two listeners being locked at the same time, while having the same [[Listener.ListenerLock.selfNumber lock number]].
*/
case class ConflictingLocksException(
Expand Down
12 changes: 6 additions & 6 deletions shared/src/main/scala/async/retry.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package gears.async

import scala.util.Random
import scala.util.{Try, Success, Failure}
import scala.util.boundary
import scala.util.control.NonFatal
import scala.concurrent.duration._

import gears.async.Async
import gears.async.AsyncOperations.sleep
import gears.async.Retry.Delay

import scala.concurrent.duration._
import scala.util.Random
import scala.util.boundary
import scala.util.control.NonFatal
import scala.util.{Failure, Success, Try}

/** Utility class to perform asynchronous actions with retrying policies on exceptions.
*
* See [[Retry]] companion object for common policies as a starting point.
Expand Down
10 changes: 6 additions & 4 deletions shared/src/test/scala/CancellationBehavior.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import gears.async.{Async, Future, AsyncSupport, uninterruptible}
import gears.async.AsyncOperations.*
import gears.async.default.given
import scala.util.boundary
import boundary.break
import scala.concurrent.duration.{Duration, DurationInt}
import gears.async.{Async, AsyncSupport, Future, uninterruptible}

import java.util.concurrent.CancellationException
import scala.concurrent.duration.{Duration, DurationInt}
import scala.util.Success
import scala.util.boundary

import boundary.break

class CancellationBehavior extends munit.FunSuite:
enum State:
Expand Down
17 changes: 9 additions & 8 deletions shared/src/test/scala/ChannelBehavior.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import gears.async.AsyncOperations.*
import gears.async.default.given
import gears.async.{
Async,
BufferedChannel,
Expand All @@ -9,19 +11,18 @@ import gears.async.{
TaskSchedule,
UnboundedChannel
}
import gears.async.default.given
import gears.async.AsyncOperations.*
import Future.zip

import java.nio.ByteBuffer
import java.util.concurrent.CancellationException
import java.util.concurrent.atomic.AtomicInteger
import scala.collection.Stepper.UnboxingFloatStepper
import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, Set}
import scala.concurrent.ExecutionContext
import scala.util.{Failure, Success, Try}
import scala.util.Random
import scala.collection.mutable.{ArrayBuffer, Set}
import java.util.concurrent.atomic.AtomicInteger
import java.nio.ByteBuffer
import scala.collection.Stepper.UnboxingFloatStepper
import scala.util.{Failure, Success, Try}

import Future.zip

class ChannelBehavior extends munit.FunSuite {

Expand Down
Loading
Loading