-
Notifications
You must be signed in to change notification settings - Fork 110
Fix dropped errors in manifold.time/in
#247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: detect-dropped-errors-in-tests
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,7 +125,7 @@ | |
;;; | ||
|
||
(in-ns 'manifold.deferred) | ||
(clojure.core/declare success! error! deferred realized? chain connect) | ||
(clojure.core/declare success! error! deferred realized? chain connect on-realized) | ||
(in-ns 'manifold.time) | ||
|
||
;;; | ||
|
@@ -191,8 +191,14 @@ | |
(reify | ||
IClock | ||
(in [this interval-millis f] | ||
(swap! events update-in [(p/+ ^double @now interval-millis)] #(conj (or % []) f)) | ||
(advance this 0)) | ||
(let [t (p/+ ^double @now interval-millis) | ||
cancel-fn (fn [] | ||
(swap! events #(cond-> % | ||
(contains? % t) | ||
(update t disj f))))] | ||
(swap! events update t (fnil conj #{}) f) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could there be a race condition between the deref now on L194 and this swap? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only if there is a concurrent call to |
||
(advance this 0) | ||
cancel-fn)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this changes the return value from nil (what advance returns) to a fn. is that ok? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not only OK but fixes the mock clock implementation to conform to the expected return value. Quoting from the commit message / PR description:
Compare with the real clock implementation and here for where this would fail if we didn't return a function here. |
||
(every [this delay-millis period-millis f] | ||
(assert (p/< 0.0 period-millis)) | ||
(let [period (atom period-millis) | ||
|
@@ -263,7 +269,9 @@ | |
(catch Throwable e | ||
(manifold.deferred/error! d e))))) | ||
cancel-fn (.in *clock* interval f)] | ||
(manifold.deferred/chain d (fn [_] (cancel-fn))) | ||
(manifold.deferred/on-realized d | ||
(fn [_] (cancel-fn)) | ||
(fn [_] (cancel-fn))) | ||
d)) | ||
|
||
(defn every | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be a
swap!
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On
now
you mean? If so: no, the current clock time can only be changed viaadvance
for the mock clock. Also note that this was already the case before - I merely pulled out the key construction from theupdate-in
so that I can re-use it incancel-fn
.