Value Promise
Promise represents value which will be available later (at some point of time), but it can now be incorporated in current calculations
val s: String = "Hello"
val v: Promise[String] = Promise(s + " Concurrent Promise!")
v.resultOpt.tp // Value is likely not available yet
v.onResult(_.tp) // Will run when value is available
// Output
Opt(VOID)
Result(Hello Concurrent Promise!)
- Source
- __.scala
Def
Reversed filter
Reversed filter
Creates a new promise where in case if future value will satisfy given predicate, it will be replaced with generated problem result
The result with problem will not be affected
- Source
- __.scala
Process failure
Process failure
Will run the given function, when promise is fulfilled and the result is a problem
Note. The function will never run if promise is a success
- Source
- __.scala
Process value
Process value
Will run the given function, when value will become available
Note. The function will never run if promise fails
- Source
- __.scala
Convert value
Convert value
Creates a new promise where future value will be converted with given function
The result with problem will not be affected
- Source
- __.scala
Change completly
Change completly
Creates a new promise where all outcomes of current promise, both: value and problem will be processed
- Source
- __.scala
Map result
Map result
Creates a new promise where future value will be converted to given function result
- Source
- __.scala
Map with Promise
Map with Promise
Creates a new promise, which will be completed based on promise created with the given function result.
- Source
- __.scala
Run when ready
Run when ready
Will run the given function, when the result will become available
val v = Promise{ 2 * 2 }
v.onResult("onResult: " + _.tag tp())
"Immediate Result: " + v.resultOpt tp()
// Output
Immediate Result: Opt(VOID)
onResult: Result(4)
- Source
- __.scala
Process result
Process result
When promise is fulfilled with a result, the apropriate given function is executed either with value or problem
- Source
- __.scala
Optional result
Optional result
Returns calculation result if it is available
val v = Promise{ 2 * 2 }
v.resultOpt.tp // Likely prints: \/
J.sleep(1.Second)
v.resultOpt.tp // Likely prints: Opt(Result(4))
- Source
- __.scala
Filter
Filter
Creates a new promise where in case if future value will not satisfy given predicate, it will be replaced with generated problem result
The result with problem will not be affected
- Source
- __.scala
Join two promises
Join two promises
Creates a new promise where values of two promises will be returned as tuple. If either promise fails, the new promise will also be a failure
- Source
- __.scala