Skip to content

Commit 8adc983

Browse files
committed
.
1 parent 2c3e540 commit 8adc983

File tree

1 file changed

+12
-22
lines changed
  • stream/src/main/scala/org/apache/pekko/stream/scaladsl

1 file changed

+12
-22
lines changed

stream/src/main/scala/org/apache/pekko/stream/scaladsl/Source.scala

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -589,16 +589,11 @@ object Source {
589589
* Emits a single value when the given `Future` is successfully completed and then completes the stream.
590590
* The stream fails if the `Future` is completed with a failure.
591591
*/
592-
def future[T](futureElement: Future[T]): Source[T, NotUsed] = {
593-
val maybeValue = futureElement.value
594-
if (maybeValue eq None) {
595-
fromGraph(new FutureSource[T](futureElement))
596-
} else maybeValue match {
597-
case Some(scala.util.Success(null)) => empty[T]
598-
case Some(scala.util.Success(elem)) => single(elem)
599-
case Some(scala.util.Failure(ex)) => failed[T](ex)
600-
case _ => throw new IllegalStateException("unexpected case") // will not happen, for exhaustiveness check
601-
}
592+
def future[T](futureElement: Future[T]): Source[T, NotUsed] = futureElement.value match {
593+
case None => fromGraph(new FutureSource[T](futureElement))
594+
case Some(scala.util.Success(null)) => empty[T]
595+
case Some(scala.util.Success(elem)) => single(elem)
596+
case Some(scala.util.Failure(ex)) => failed[T](ex)
602597
}
603598

604599
/**
@@ -621,18 +616,13 @@ object Source {
621616
* Turn a `Future[Source]` into a source that will emit the values of the source when the future completes successfully.
622617
* If the `Future` is completed with a failure the stream is failed.
623618
*/
624-
def futureSource[T, M](futureSource: Future[Source[T, M]]): Source[T, Future[M]] = {
625-
val maybeValue = futureSource.value
626-
if (maybeValue eq None) {
627-
fromGraph(new FutureFlattenSource(futureSource))
628-
} else maybeValue match {
629-
case Some(scala.util.Success(null)) =>
630-
val exception = new NullPointerException("futureSource completed with null")
631-
Source.failed(exception).mapMaterializedValue(_ => Future.failed[M](exception))
632-
case Some(scala.util.Success(source)) => source.mapMaterializedValue(Future.successful)
633-
case Some(scala.util.Failure(ex)) => Source.failed[T](ex).mapMaterializedValue(_ => Future.failed[M](ex))
634-
case _ => throw new IllegalStateException("unexpected case") // will not happen, for exhaustiveness check
635-
}
619+
def futureSource[T, M](futureSource: Future[Source[T, M]]): Source[T, Future[M]] = futureSource.value match {
620+
case None => fromGraph(new FutureFlattenSource(futureSource))
621+
case Some(scala.util.Success(null)) =>
622+
val exception = new NullPointerException("futureSource completed with null")
623+
Source.failed(exception).mapMaterializedValue(_ => Future.failed[M](exception))
624+
case Some(scala.util.Success(source)) => source.mapMaterializedValue(Future.successful)
625+
case Some(scala.util.Failure(ex)) => Source.failed[T](ex).mapMaterializedValue(_ => Future.failed[M](ex))
636626
}
637627

638628
/**

0 commit comments

Comments
 (0)