Have FutureUtil.makeAsync handle thrown exceptions (#4458)

This commit is contained in:
benthecarman 2022-07-07 14:26:38 -05:00 committed by GitHub
parent 83cff9a44c
commit 000e7a7930
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View file

@ -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)
}
}

View file

@ -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