Skip to content

clojure.core.async/timeout

View this page on ClojureDocs

Type: function Added: Clojure unknown Examples: 3 Runnable: 0
([msecs])

Returns a channel that will close after msecs

Examples

by runexec on . May have evaluation errors.
by runexec on . May have evaluation errors.
by loeschzwerg on . May have evaluation errors.

Note by hlship

Never close! the channel returned by timeout -- this is an unwritten rule.

The implementation sometimes will use an existing timeout channel, if it is within a few ms of the desired timeout. Closing the channel will affect multiple otherwise unrelated CSPs that may be blocked/parked waiting for the channel to close.

In our application, we saw this as spurious "timed out after waiting X ms" messages when the logged timestamps didn't support this possibility.

Thanks to Ryan Neufeld for identifying this!

Note by raymcdermott

Might be obvious but this construct is preferred in go blocks over Thread/sleep as it does not block


Content from the matching ClojureDocs page, with authors credited on each contribution.