opened
justinhj
username_0
The attached PR adds timeout capability to FetchMonadError[Future]

I also modified Query.Sync to return a completed future which I think is the intent rather than run it in a Future

All tests pass but I didn't yet create tests for the timeout, I can do so if the PR looks like something you might want

Only thing I'm not sure about is whether the use of synchronize is needed. I'm not sure but I think Promise may be safe to use from multiple threads because it uses an AtomicReference but didn't find any confirmation of that.
Add timeout capability to Future implementation of FetchMonadError
issue
created
justinhj
username_0
Removed synchronization on Promise and simplified the PR
comment
created
justinhj
username_0
Have added tests for the two cases of a future failing because it timed out and succeeding because it finished before the timeout occurred.
comment
created
justinhj
username_0
I've updated the PR so that the tests that require non-blocking sleep are now in the JVM module. Seems travis build is failing but this is due to a timeout building the docs
comment
created
justinhj
username_0
I think everything looks good now, just getting a timeout with Travis building the docs
comment
created
peterneyens
username_1
There definitely is something strange going on when combining `Timer` and tut.

Commenting out `implicits.timer` (and as a consequence `timer.schedule(...)`) makes tut run fine.

A minimal tut file which makes tut hang (notice that we aren't even using the time out here, since we are using `Query.sync`):

```scala
// ```tut
import scala.concurrent.{Await, Future}
import scala.concurrent.duration.Duration
import scala.concurrent.ExecutionContext.Implicits.global

import fetch.{FetchMonadError, Query}
import fetch.implicits._

val query: Query[Option[Int]] = Query.sync { Some(1) }

val future: Future[Option[Int]] = FetchMonadError[Future].runQuery(query)
Await.result(future, Duration.Inf)
// ```
```

If I change the `Sync` from `Future(...)` to the line below, tut runs fine for the minimal file, not for the complete _docs.md_ file though ...
```scala
case Sync(e) =>
  cats.ApplicativeError[Future, Throwable].catchNonFatalEval(e)
```

It seems like I need to do some more investigating to see what is going on ...
comment
created
justinhj
username_0
Ah timer is supposed to run on a daemon thread and if it doesn't then it can stop a program from terminating. I'll check the code and see if I'm doing that correctly
comment
created
justinhj
username_0
I've updated so Timer is on a daemon thread and also created lazily so it is not initialized by programs that don't use it
comment