Skip to content

Commit

Permalink
do not dispose convicted outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
leonoel committed Oct 9, 2024
1 parent 3b865d0 commit e411ab5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/hyperfiddle/electric/impl/runtime3.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,8 @@ T T T -> (EXPR T)
(do (aset output output-slot-requested false)
(port-deps input-down nil port)
(when (zero? (aget output output-slot-refcount))
(output-dispose output)))
(when (identical? output (aget output output-slot-convicted))
(output-dispose output))))
(do (aset output output-slot-requested true)
(port-deps input-up nil port)))
remote))
Expand Down
35 changes: 35 additions & 0 deletions test/hyperfiddle/electric3_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2371,3 +2371,38 @@
(tests
(with ((l/single {} (tap (.fooBar (js/Object.)))) tap (fn [_] (tap :error)))
% := :error))))

(tests

(let [!x (atom 0)
!y (atom true)
!z (atom true)
!clocks (atom {})
clock (fn [k]
(m/observe
(fn [!]
(swap! !clocks assoc k !)
#(swap! !clocks dissoc k))))
tick (fn [k] ((@!clocks k) nil))]
((l/local {::lang/client-clock [(clock :client-read) (clock :client-write)]
::lang/server-clock [(clock :server-read) (clock :server-write)]}
(let [x (e/watch !x)]
(when (e/watch !y)
(e/server [(identity x)
(when (e/watch !z) x)]))))
tap tap)
(tick :client-write)
(tick :server-read)
(tick :server-write)
(swap! !z not)
(tick :server-write)
(swap! !y not)
(tick :client-write)
(tick :client-read)
(tick :client-read)
(tick :server-read)
(tick :server-write)
(tick :client-read)
(tick :client-write)
(tap :done)
% := :done))

0 comments on commit e411ab5

Please sign in to comment.