2016-01-21 18:06:42 +02:00
|
|
|
/**
|
2016-02-23 12:58:39 +01:00
|
|
|
* Copyright (C) 2016 Lightbend Inc. <http://www.lightbend.com>
|
2016-01-21 18:06:42 +02:00
|
|
|
*/
|
2016-02-16 16:56:06 +01:00
|
|
|
package akka.stream
|
2016-01-21 18:06:42 +02:00
|
|
|
|
|
|
|
|
import akka.Done
|
|
|
|
|
import scala.util.{ Failure, Success, Try }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Holds a result of an IO operation.
|
|
|
|
|
*
|
|
|
|
|
* @param count Numeric value depending on context, for example IO operations performed or bytes processed.
|
|
|
|
|
* @param status Status of the result. Can be either [[akka.Done]] or an exception.
|
|
|
|
|
*/
|
|
|
|
|
final case class IOResult private[stream] (count: Long, status: Try[Done]) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Java API: Numeric value depending on context, for example IO operations performed or bytes processed.
|
|
|
|
|
*/
|
|
|
|
|
def getCount: Long = count
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Java API: Indicates whether IO operation completed successfully or not.
|
|
|
|
|
*/
|
|
|
|
|
def wasSuccessful: Boolean = status.isSuccess
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Java API: If the IO operation resulted in an error, returns the corresponding [[Throwable]]
|
|
|
|
|
* or throws [[UnsupportedOperationException]] otherwise.
|
|
|
|
|
*/
|
|
|
|
|
def getError: Throwable = status match {
|
|
|
|
|
case Failure(t) ⇒ t
|
2016-02-24 22:00:32 -08:00
|
|
|
case Success(_) ⇒ throw new UnsupportedOperationException("IO operation was successful.")
|
2016-01-21 18:06:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|