Wants
- I want to know if reading a value will block
future-done?for Future
- I want to know if something has finished
awaitfor Agentfuture-done?for FutureThread.isAlive(rare)
- I want to wait for something to finish
awaitfor Agentdereffor Future, Delay, and Promise
- I want to wait a specific amount of time for something to finish
await-forfor Agent
- I want to prevent something from happening
future-cancelfor FutureThreadPoolExecutor.removefor a custom thread pool- Avoid
derefon a Delay
Example Problem
- printing at the REPL looks through a deref (e.g. on a promise)
- this can block (possibly forever) if a data structure contains e.g. a promise
- if a deref is potentially blocking, then I don't think the REPL should perform the deref
- option 1: never deref possible blockers
- option 2: have a bindable val that controls how REPL prints blocking derefs, analogous to the controls for lazy data structures
- in any case, there needs to be a way to discover which derefs might block
Facts
derefcan block- Never for Var, Ref, Agent, and Atom
- Sometimes for Future, Delay, and Promise
- Java APIs
- Future
.get()blocks until complete- interruptible, throws InterruptedException
.get(long, TimeUnit)blocks for specified duration- throws TimeouotException if it times out
- interruptible, throws InterruptedException
.isDone()asks if finished.cancel(bool mayInterrupt)attempts to cancel- if already finished or cancelled, returns false
- if already running, tries to interrupt if argument is true
.isCancellled()asks if cancelled
- CountDownLatch
.await()blocks until latch reaches zero- interruptible, throws InterruptedException
.await(long, TimeUnit)blocks until latch reaches zero- returns false if it times out
- interruptible, throws InterruptedException
.getCount()returns current count
- Semaphore
- CyclicBarrier
- Future
Labels: