Comments (3)
The first snippet is unsupported due to host limitations. It is not currently possible to capture the continuation from an arbitrary point of the call stack at runtime, therefore we have to emulate it with compile-time syntactic transformation techniques (cloroutine, in this case). As a consequence, any call to ?
from a sp
block is forbidden unless it's called directly from its body. The code rewriting stops at lambdas, so the ?
is considered foreign to the sp
block here.
Project Loom is a promising attempt to provide runtime continuations on the JVM so it's not impossible it eventually works at some point but for now there's still way too much uncertainty about it to be a viable option.
The second snippet works as expected because ?
is not called from a sp
block so the future's thread sees it as a blocking call.
I'm not sure if this is expected behaviour or if it is a bug, but I generally see all NullPointerExceptions as bugs, so thought I'd submit it.
You did well ! Even though an error is expected, the error is confusing, confusion means poor developer experience. I think the right path forward is to add a check and raise an error with a more explicit message. I also think the documentation could be more clear about that so feel free to suggest improvements.
from missionary.
One problem that I have been running into a few times that is related to this issue: if I use missionary in some internal code (ie a separate library or namespace), and then turn it into a blocking call (to "hide" the use of missionary behind the api methods), I cannot then use that api within another missionary block.
(defn get-value []
(m/? (m/sp :internal-use-of-missionary)))
(m/? (m/sp (get-value))))
This throws an nullreference exception, and also the return value of get-value
is a java.lang.ThreadLocal$SuppliedThreadLocal.
The fix for this seems to be:
(defn get-value []
@(future (m/? (m/sp :internal-use-of-missionary))))
(m/? (m/sp (get-value))))
But it can be difficult to diagnose this, especially if you don't know that the library you are using uses missionary underneath.
Please let me know if this does not make sense and I'll try to explain better.
A proposed fix would probably just be to throw an better exception in this case, or maybe to wrap the m/? in a future by default.
from missionary.
That makes sense. get-value
is a blocking call therefore it's wrong to call it directly from m/sp
, and the error message should explain that. The right fix is to turn blocking calls into tasks using m/via
.
(defn get-value []
(m/? (m/sp :internal-use-of-missionary)))
(m/? (m/sp (m/? (m/via m/blk (get-value)))))
from missionary.
Related Issues (20)
- Cloroutine exception HOT 9
- Performance warning - case has int tests, but tested expression is not primitive.
- Compiler Exception on Clojure 1.11.1 - No matching clause: :static-field HOT 2
- zip doesn't terminate properly HOT 3
- group-by consumers must terminate immediately on input crash HOT 6
- Large dependency: missionary dependency grows uber jar by 26 MiB
- Cannot set properties of undefined (setting 'parent') HOT 2
- Cannot read properties of null (reading 'parallelism')
- nullpointerexception with subscribe HOT 6
- `m/sleep` does not terminate after exception HOT 1
- task succeeds on cancel when task body is wrapped in a try/catch HOT 10
- missionary.Cancelled not thrown HOT 6
- `m/mbx` on post can return non-nil value, the docs say otherwise
- `ap` bug
- Cancel in example for basic walkthrough doesn't work HOT 3
- watch can discard latest value
- Hello task example prints only Hello with Clojure repl HOT 4
- generalize `signal` to any semigroup HOT 1
- `observe` - on JVM, consider parking the caller thread instead of throwing when pipeline is busy HOT 2
- make `ap` switch consistent with `cp` HOT 1
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 missionary.