golo-lang icon indicating copy to clipboard operation
golo-lang copied to clipboard

Future: get() with (long timeout, TimeUnit unit)

Open k33g opened this issue 8 years ago • 0 comments

Hello 🌍

  • gololang.concurrent.async.Future has not a get method to handle a timeout
  • so gololang.concurrent.async.AssignedFuture does not implement this method

What I'm doing instead:

  let concurrentTask = |task, timeout| {
    let executor = Executors.newSingleThreadExecutor()
    return trying({
      let future = executor: submit(asInterfaceInstance(java.util.concurrent.Callable.class, {
        return task()
      }))
      let res = future: get(timeout, MILLISECONDS())
      executor: shutdown()
      return res
    })
  }

  concurrentTask({
    sleep(2000_L)
    return "Hello 🌍"
  }, 1000_L)
  : either(
    recover=|error| {
      println("😡")
    },
    mapping=|result| {
      println(result)
    }
  )

k33g avatar Nov 18 '17 05:11 k33g