Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Future question #1682

Closed
eed3si9n opened this issue Aug 12, 2019 · 4 comments
Closed

Future question #1682

eed3si9n opened this issue Aug 12, 2019 · 4 comments
Labels
question A question that should be asked on Gitter or Stack Overflow

Comments

@eed3si9n
Copy link

I tried to unstub Future in eed3si9n/verify#16 following monix/minitest#41, but it doesn't seem to work.

@densh
Copy link
Member

densh commented Aug 12, 2019

Similarly to Scala.js, we have a single hardware thread at the moment. So Await.result naturally isn't supported because if you wait on a single thread you block that thread. This means that event loop never gets a chance to run any more futures while you wait so it's guaranteed to time out.

@eed3si9n
Copy link
Author

I am not familiar with the implementation of Scala.JS scalalib override, but minitest works ok on Scala.JS, and so did Minitest's Future/Promise/Await stub.

object Future {
  def apply[A](f: => A): Future[A] =
    new Future(Try(f))

  def successful[A](value: A): Future[A] =
    new Future(Success(value))

  def failed[A](e: Throwable): Future[A] =
    new Future(Failure(e))
}

@eed3si9n
Copy link
Author

Here's a workaround that seems to work for me:

object Await {
  def result[A](future: Future[A], duration: Duration): A = {
    scala.scalanative.runtime.loop()
    future.value.get.get
  }
}

@lolgab
Copy link
Contributor

lolgab commented Aug 12, 2019

Very nice workaround! Thank you.

@sjrd sjrd added the question A question that should be asked on Gitter or Stack Overflow label Jul 7, 2020
@sjrd sjrd closed this as completed Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question that should be asked on Gitter or Stack Overflow
Projects
None yet
Development

No branches or pull requests

4 participants