mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-22 14:33:06 +01:00
Have FutureUtil.makeAsync handle thrown exceptions (#4458)
This commit is contained in:
parent
83cff9a44c
commit
000e7a7930
2 changed files with 10 additions and 2 deletions
|
@ -109,4 +109,11 @@ class FutureUtilTest extends BitcoinSJvmTest {
|
|||
}
|
||||
}
|
||||
|
||||
it must "properly handle an exception in makeAsync" in {
|
||||
val f = FutureUtil.makeAsync { () =>
|
||||
throw new RuntimeException("test")
|
||||
}
|
||||
|
||||
recoverToSucceededIf[RuntimeException](f)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.bitcoins.core.util
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future, Promise}
|
||||
import scala.util.Try
|
||||
|
||||
object FutureUtil {
|
||||
|
||||
|
@ -100,8 +101,8 @@ object FutureUtil {
|
|||
val resultP = Promise[T]()
|
||||
|
||||
ec.execute { () =>
|
||||
val result = func()
|
||||
resultP.success(result)
|
||||
val resultT = Try(func())
|
||||
resultP.complete(resultT)
|
||||
}
|
||||
|
||||
resultP.future
|
||||
|
|
Loading…
Add table
Reference in a new issue