Cannot use Concurrent::Cancellation
Closed this issue · 3 comments
I can't create a Concurrent::Cancellation.
Minimal reproduction:
$ ruby -rconcurrent-ruby -e Concurrent::Cancellation.new
-e:1:in `<main>': uninitialized constant Concurrent::Cancellation (NameError)
Concurrent::Cancellation.new
^^^^^^^^^^^^^^
Did you mean? Concurrent::CancelledOperationError
$ ruby -rconcurrent -e Concurrent::Cancellation.new
-e:1:in `<main>': uninitialized constant Concurrent::Cancellation (NameError)
Concurrent::Cancellation.new
^^^^^^^^^^^^^^
Did you mean? Concurrent::CancelledOperationError
My project uses Concurrent::Promises.future for multi-threading, and I am trying to implement a cancellation mechanism.
All my google search results suggest creating this Cancellation instance in this way.
I feel like I must be missing something obvious.
$ ruby -rconcurrent -e 'puts Concurrent::VERSION'
1.3.4
Using ruby 3.1 on debian.
Cancellations is an Edge feature: https://github.com/ruby-concurrency/concurrent-ruby?tab=readme-ov-file#edge-features
Thank you.
I'll switch back to Threads since I need cancellation and I don't see a way to do it in non-edge concurrent-ruby.
I'll switch back to Threads since I need cancellation and I don't see a way to do it in non-edge concurrent-ruby.
How are you handling it in Threads? I'm just curious because Cancellations are not particularly useful imo.
Concurrent::Future / ScheduledTask are cancellable: https://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Future.html
The problem usually comes down to when a task/thread/code is already running, at which point it is not stoppable without (dangerously unsafely) killing the thread. Cancellations can't fix that.