Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

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

Open
k33g opened this issue Nov 18, 2017 · 0 comments
Open

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

k33g opened this issue Nov 18, 2017 · 0 comments
Labels

Comments

@k33g
Copy link
Contributor

k33g commented Nov 18, 2017

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 k33g added the feature label Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant