Skip to content

Instantly share code, notes, and snippets.

@vaneyckt
Created June 8, 2018 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaneyckt/bfcfddbcb8bae37d984dfc9fe05a1067 to your computer and use it in GitHub Desktop.
Save vaneyckt/bfcfddbcb8bae37d984dfc9fe05a1067 to your computer and use it in GitHub Desktop.
timeout_queue = TimeoutQueue.new
# blocking pop, empty queue - new data is added after 5s
Thread.new { sleep 5; timeout_queue << 'foobar' }
timeout_queue.pop # => waits for 5s for data to arrive, then returns 'foobar'
# blocking pop, empty queue - no new data is added
timeout_queue.pop(true, 10) # => raises ThreadError after 10s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment