Comments (5)
You're right, changing the API isn't an easy choice, but that's better than having a serious bug. I never gave any thought to subclassing Future because, in my mind, I view it like a concurrency primitive. But it isn't and you are correct that subclassing is a problem. What do you think about supporting execute
as both an instance and a class method?
f = Future.new{ sleep(10); print "foo\n" }
f.state #=> :unscheduled
f.execute
f.state #=> :pending
f = Future.new{ sleep(10); print "foo\n" }.execute
f = Future.execute{ sleep(10); print "foo\n" }
In the both cases initialize
raises an ArgumentError
if no block is given. The instance method execute
returns self
to support the single-line chained call, but does nothing once the Future
is in any state other than :unscheduled
. The class method execute
, as you suggested, creates a new Future
, calls execute
on the object, then returns it.
Thoughts?
from concurrent-ruby.
I like this solution, because new
keeps the current signature and the whole class interface is nicer.
execute
could take an optional thread_pool
parameter, to make it more flexible: at the moment is not easy to change it, so in some situations we have a little messy code (like in tests)
from concurrent-ruby.
I've updated Future
with the execute
methods and updated the specs. I didn't implement a thread_pool
parameter yet. I've struggled some with how best to handle internal thread pools. I'd like to handle that consistently for all abstractions that should reasonably support them. An optional parameter makes sense for Future
but I'd like to look at the rest of the library and see how many of the abstractions that approach makes sense with.
from concurrent-ruby.
I noticed that ScheduledTask has the same issue as Future so I implemented the same execute
methods on that class, too.
from concurrent-ruby.
I've also updated Future and ScheduledTask to have identical construction behavior. Both support Dereferenceable
and take an options hash as a parameter to new
and class execute
.
from concurrent-ruby.
Related Issues (20)
- why use wait_for_termination method will stuck the code HOT 2
- DaemonThreadFactory creating new Java thread factory each time it creates a new thread HOT 8
- `Concurrent::Promises::Future#value!` can return `nil` even when promise is not resolved yet HOT 6
- Version 1.2.2 crashes with Segmentation fault HOT 3
- Fiber.new causes SEGV when using Ruby 3.3.0 on Rails 7.1.2 in M1 Mac Docker environment HOT 5
- Segfault in lock_local_var.rb on aarch64 HOT 3
- [REDIRECT] Segfault on Ruby 3.3.0 on linux-aarch64? See https://bugs.ruby-lang.org/issues/20085
- Add new CI job with RUBY_MN_THREADS=1 HOT 4
- Add API to prestart threads in threadpools HOT 4
- Don't know how to build task 'parallel_spec' HOT 2
- Segmentation fault related to concurrent-ruby HOT 4
- Segmentation fault with Ruby 3.3.0 running with Docker HOT 1
- Add keyword arguments to async HOT 1
- ThreadPoolExecutor#shutdown? inconsistency in JRuby and C Ruby HOT 4
- test failure due to "uninitialized constant Concurrent::CAtomicReference" HOT 7
- CAtomicFixnum should probably be a private constant HOT 1
- support re-raising exceptions when shutting down a timertask HOT 4
- v1.2.0 release notes do not mention that RubyThreadLocalVar class was removed HOT 8
- NameError: uninitialized constant Concurrent::RubyThreadLocalVar HOT 1
- The Concurrent::Map default_proc is passed a Concurrent::Hash instead of the Concurrent::Map HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from concurrent-ruby.