-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement
Source.future
operator
Creates a source that emits a single value when Future completes or fails otherwise. Notes: * when Future fails with `scala.concurrent.ExecutionException` then its cause is returned as source failure. * the input Future cannot be `null` Examples: Source .future(Future.failed(new RuntimeException("future failed"))) .receive() // ChannelClosed.Error(Some(java.lang.RuntimeException: future failed)) Source.future(Future.successful(1)).toList // List(1)
- Loading branch information
1 parent
053c486
commit 9d3c32a
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ox.channels | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import ox.* | ||
|
||
import scala.concurrent.Future | ||
|
||
class SourceOpsFutureTest extends AnyFlatSpec with Matchers { | ||
behavior of "Source.future" | ||
|
||
it should "fail to create source from the null future" in supervised { | ||
the[IllegalArgumentException] thrownBy { | ||
Source.future(null) | ||
} should have message "requirement failed: from cannot be null" | ||
} | ||
|
||
it should "return report failure when future fails" in supervised { | ||
val failure = new RuntimeException("future failed") | ||
Source.future(Future.failed(failure)).receive() shouldBe ChannelClosed.Error(Some(failure)) | ||
} | ||
|
||
it should "return future value" in supervised { | ||
Source.future(Future.successful(1)).toList shouldBe List(1) | ||
} | ||
} |