Skip to content

Commit

Permalink
Update scalafmt-core to 3.8.2 (#154)
Browse files Browse the repository at this point in the history
Co-authored-by: scala-steward <scala-steward>
  • Loading branch information
softwaremill-ci authored Jun 17, 2024
1 parent cf4b0eb commit 04f8a69
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 40 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ e988553eda72e5b4ea0760ff5e95bf0af12e9921

# Scala Steward: Reformat with scalafmt 3.8.1
5c6ea70f91018a2c0d16116c82cab92ee4d507f0

# Scala Steward: Reformat with scalafmt 3.8.2
b73b3c3f8fcaaa70595cd267f7242b0a0c345039
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version = 3.8.1
version = 3.8.2
maxColumn = 140
runner.dialect = scala3
3 changes: 1 addition & 2 deletions core/src/main/scala/ox/channels/SourceCompanionIOOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ trait SourceCompanionIOOps:
chunks.done()
false
else
if readBytes > 0 then
chunks.send(if readBytes == chunkSize then Chunk.fromArray(buf) else Chunk.fromArray(buf.take(readBytes)))
if readBytes > 0 then chunks.send(if readBytes == chunkSize then Chunk.fromArray(buf) else Chunk.fromArray(buf.take(readBytes)))
true
}
catch
Expand Down
1 change: 0 additions & 1 deletion core/src/main/scala/ox/channels/SourceCompanionOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -386,4 +386,3 @@ trait SourceCompanionOps:
val c = Channel.rendezvous[T]
c.errorOrClosed(t)
c

43 changes: 22 additions & 21 deletions core/src/main/scala/ox/channels/SourceIOOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,24 @@ trait SourceIOOps[+T]:
* @throws IOException
* if an error occurs when writing or closing of the `OutputStream`.
*/
def toOutputStream(outputStream: OutputStream)(using T <:< Chunk[Byte], IO): Unit =
repeatWhile {
outer.receiveOrClosed() match
case ChannelClosed.Done =>
close(outputStream)
false
case ChannelClosed.Error(e) =>
close(outputStream, Some(e))
throw e
case chunk: T @unchecked =>
try
outputStream.write(chunk.toArray)
true
catch case NonFatal(e) =>
def toOutputStream(outputStream: OutputStream)(using T <:< Chunk[Byte], IO): Unit =
repeatWhile {
outer.receiveOrClosed() match
case ChannelClosed.Done =>
close(outputStream)
false
case ChannelClosed.Error(e) =>
close(outputStream, Some(e))
throw e
case chunk: T @unchecked =>
try
outputStream.write(chunk.toArray)
true
catch
case NonFatal(e) =>
close(outputStream, Some(e))
throw e
}
throw e
}

/** Writes content of this `Source` to a file.
*
Expand Down Expand Up @@ -86,14 +87,14 @@ trait SourceIOOps[+T]:
try
jFileChannel.write(ByteBuffer.wrap(chunk.toArray))
true
catch case NonFatal(e) =>
close(jFileChannel, Some(e))
throw e
catch
case NonFatal(e) =>
close(jFileChannel, Some(e))
throw e
}

private inline def close(closeable: Closeable, cause: Option[Throwable] = None)(using IO): Unit =
try
closeable.close()
try closeable.close()
catch
case NonFatal(closeException) =>
cause.foreach(_.addSuppressed(closeException))
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/ox/channels/SourceTextOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ trait SourceTextOps[+T]:
outer.receiveOrClosed() match
// end of channel before getting enough bytes to resolve BOM, assuming no BOM
case ChannelClosed.Done =>
if (buffer != null) then
if (buffer != null) then
// There's a buffer accumulated (not BOM), decode it directly
outputChannel.send(buffer.asStringUtf8)
outputChannel.done()
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/scala/ox/channels/actor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class ActorRef[T](c: Sink[T => Unit]):
def ask[U](f: T => U): U =
val cf = new CompletableFuture[U]()
c.send { t =>
try
cf.complete(f(t)).discard
try cf.complete(f(t)).discard
catch
case NonFatal(e) =>
// since this is an ask, only propagating the exception to the caller, not to the scope
Expand Down
9 changes: 6 additions & 3 deletions core/src/main/scala/ox/resilience/Schedule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object Schedule:
*/
def forever(delay: FiniteDuration): Infinite = DelayForever(delay)

case class DelayForever private[resilience](delay: FiniteDuration) extends Infinite:
case class DelayForever private[resilience] (delay: FiniteDuration) extends Infinite:
override def nextDelay(attempt: Int, lastDelay: Option[FiniteDuration]): FiniteDuration = delay

/** A schedule that retries up to a given number of times, with an increasing delay (backoff) between subsequent attempts.
Expand Down Expand Up @@ -115,8 +115,11 @@ object Schedule:
def forever(initialDelay: FiniteDuration, maxDelay: FiniteDuration = 1.minute, jitter: Jitter = Jitter.None): Infinite =
BackoffForever(initialDelay, maxDelay, jitter)

case class BackoffForever private[resilience](initialDelay: FiniteDuration, maxDelay: FiniteDuration = 1.minute, jitter: Jitter = Jitter.None)
extends Infinite:
case class BackoffForever private[resilience] (
initialDelay: FiniteDuration,
maxDelay: FiniteDuration = 1.minute,
jitter: Jitter = Jitter.None
) extends Infinite:
override def nextDelay(attempt: Int, lastDelay: Option[FiniteDuration]): FiniteDuration =
Backoff.nextDelay(attempt, initialDelay, maxDelay, jitter, lastDelay)

Expand Down
8 changes: 4 additions & 4 deletions core/src/main/scala/ox/supervised.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import scala.reflect.ClassTag
* [[fork]] (daemon) don't have to complete successfully for the scope to end.
* - the scope also ends once the first supervised fork (including the `f` main body) fails with an exception
* - when the scope **ends**, all running forks are cancelled
* - the scope **completes** (that is, this method returns) only once all forks started by `f` have completed (either successfully, or with
* an exception)
* - the scope **completes** (that is, this method returns) only once all forks started by `f` have completed (either successfully, or
* with an exception)
*
* Upon successful completion, returns the result of evaluating `f`. Upon failure, the exception that caused the scope to end is re-thrown
* (regardless if the exception was thrown from the main body, or from a fork). Any other exceptions that occur when completing the scope
* are added as suppressed.
*
* @see
* [[unsupervised]] Starts a scope in unsupervised mode
* [[unsupervised]] Starts a scope in unsupervised mode
* @see
* [[supervisedError]] Starts a scope in supervised mode, with the additional ability to report application errors
* [[supervisedError]] Starts a scope in supervised mode, with the additional ability to report application errors
*/
def supervised[T](f: Ox ?=> T): T = supervisedError(NoErrorMode)(f)

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/ox/unsupervised.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import java.util.concurrent.StructuredTaskScope

private class DoNothingScope[T] extends StructuredTaskScope[T](null, Thread.ofVirtual().factory()) {}

/** Starts a new concurrency scope, which allows starting forks in the given code block `f`. Forks can be started using [[forkUnsupervised]], and
* [[forkCancellable]]. All forks are guaranteed to complete before this scope completes.
/** Starts a new concurrency scope, which allows starting forks in the given code block `f`. Forks can be started using
* [[forkUnsupervised]], and [[forkCancellable]]. All forks are guaranteed to complete before this scope completes.
*
* It is advisable to use [[supervised]] scopes if possible, as they minimise the chances of an error to go unnoticed.
*
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/scala/ox/UtilTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ class UtilTest extends AnyFlatSpec with Matchers {
}

"pipe" should "work" in {
(1+2).pipe(_ * 2) shouldBe 6
(1 + 2).pipe(_ * 2) shouldBe 6
}

"tap" should "work" in {
val t = Trail()
{
t.add("Adding")
1+2
1 + 2
}.tap(v => t.add(s"Got: $v")) shouldBe 3
t.get shouldBe Vector("Adding", "Got: 3")
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/scala/ox/channels/SourceTextOpsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class SourceTextOpsTest extends AnyWordSpec with Matchers {
.last()
.getBytes should contain theSameElementsInOrderAs new String(Array[Byte](-17, -69)).getBytes
}

"handle a string shorter than BOM" in supervised {
Source
.fromValues(Chunk.fromArray(":)".getBytes))
Expand Down

0 comments on commit 04f8a69

Please sign in to comment.