Comments (5)
Possible workaround:
class Foo
include ::Dry::Effects::Handler.Reader(:test)
def call
catch(:error) do
unhandled_throw = nil
with_test(:foobar) do
throw :error
rescue UncaughtThrowError => e
unhandled_throw = [e.tag, e.value]
end
throw(*unhandled_throw) if unhandled_throw
end
puts 'we should have got here'
end
end
Foo.new.call
Although it would be better if this was handled inside of dry-effects
from dry-effects.
Any thoughts on this? as I would rather not use a rescue as it defeats the point of the efficiencies of using control flow over exceptions.
A bit of context here, I am wrapping the hanami-action
call
method which uses throw(:halt)
to handle redirects as well as other things.
from dry-effects.
I'm not sure if this is "fixable". It's certainly possible to emulate catch
/throw
with effects and then patch libraries to account for this. The problem here is effects are not compatible with alternative flow control mechanisms, their goal is to unify all possible effects in a predictable way. I'll post examples and patches a bit later.
from dry-effects.
It seems as though a similar problem was fixed in this repo: https://github.com/rmosolgo/graphql-ruby/pull/3333/files
But as you suggest if may not be possible from these discussions:
and
https://www.reddit.com/r/ruby/comments/l431j4/interesting_throwcatch_behaviour_in_ruby/
I would appreciate any help on this, as I have invested quite heavily into using dry-effects to provide a way to add dynamic scoping to the repository calls in hanami-rb.
from dry-effects.
I have done some benchmarking, and it is not a disaster in terms of performance:
https://gist.github.com/DangerDawson/9488598302a6d2ff9f2ea45912e5d4d7
Yielded these results:
Rehearsal ------------------------------------------------
Catch/Throw 0.217898 0.000054 0.217952 ( 0.218027)
Raise/Rescue 0.738878 0.001477 0.740355 ( 0.740536)
Throw/Rescue 0.882375 0.003234 0.885609 ( 0.886147)
--------------------------------------- total: 1.843916sec
user system total real
Catch/Throw 0.217242 0.000065 0.217307 ( 0.217419)
Raise/Rescue 0.719115 0.000175 0.719290 ( 0.719359)
Throw/Rescue 0.816662 0.001009 0.817671 ( 0.817900)
So the slowdown is just under 4 fold.
from dry-effects.
Related Issues (7)
- spec/intergration typo HOT 1
- Interrupt example from documentation not working HOT 2
- Incompatibility with ActiveSupport::TaggedLogging HOT 8
- Messy data in profilers (New Relic, etc.) HOT 1
- Thread variables are not accessible HOT 10
- [Security] Workflow sync_configs.yml is using vulnerable action actions/checkout
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 dry-effects.