Comments (3)
In this particular example, you need to have some determinism - nondeterminism cannot be avoided. The FileAlterationListener
represents an external event source, which may trigger zero, one or more events. Since the Promise
/Future
can hold at most a single event, only the first (that is, the quickest) invocation of onFileCreate
can complete the promise object p
.
If we use success
to complete the promise, then if the external event source emits two file creation events, the onFileCreate
will be called twice, and one of the success
calls will throw an exception.
With our definition of determinism, this is deterministic, but not particularly useful - if we ignore the exception, then the rest of the program that depends on the value in the promise becomes non-deterministic anyway.
If we use trySuccess
, one of the calls will similarly not succeed, but an exception will not be thrown. In cases like this, where you cannot avoid determinism, it's sometimes better to just use trySuccess
.
from learning-examples.
In this particular example, you need to have some determinism - nondeterminism cannot be avoided. The FileAlterationListener represents an external event source, which may trigger zero, one or more events. Since the Promise/Future can hold at most a single event, only the first (that is, the quickest) invocation of onFileCreate can complete the promise object p.
Good explanation.
If we use success to complete the promise, then if the external event source emits two file creation events, the onFileCreate will be called twice, and one of the success calls will throw an exception. With our definition of determinism, this is deterministic, but not particularly useful - if we ignore the exception, then the rest of the program that depends on the value in the promise becomes non-deterministic anyway.
If we use trySuccess, one of the calls will similarly not succeed, but an exception will not be thrown. In cases like this, where you cannot avoid determinism, it's sometimes better to just use trySuccess.
"where you cannot avoid nondeterminism", nor?
from learning-examples.
Yes, typo - "where you cannot avoid nondeterminism".
from learning-examples.
Related Issues (20)
- `success` in `timeout` needs a value HOT 1
- Q: timeout & callback HOT 1
- Q: timeout and `or` combinator
- Something wrong in ch9 about ParLongAccumulator HOT 1
- CH3 FileSystem HOT 2
- Example org.learningconcurrency.ch6.ObservablesSubscriptions runs infinitely HOT 2
- Is the CAS implemention demo wrong? HOT 2
- What does 'the last event' mean in Ex4 of Ch6 ? HOT 3
- Unit test for Concurrent Code HOT 13
- Ch8 Actors - CheckActors gives dead letter errors
- Misleading exercice solution ch2, ex4 ? HOT 1
- Isn't ensime dead?
- Deadlock at page 45: Why `t1` locks `a` and `t2` locks `b`? HOT 1
- [error] sbt.librarymanagement.ResolveException: Error downloading org.ensime:sbt-ensime;sbtVersion=1.0;scalaVersion=2.12:1.11.0 HOT 1
- Possible error on the book? [both editions]
- Sample solutions HOT 5
- deprecated code elements so soon in the book's lifecycle? HOT 3
- CAS example HOT 2
- `AtomicBuffer#+=` needs to be final or private 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 learning-examples.