]> gitweb.factorcode.org Git - factor.git/commitdiff
rosetta-code.metronome: correct disposal of timer
authorJon Harper <jon.harper87@gmail.com>
Sun, 29 Sep 2013 17:37:08 +0000 (19:37 +0200)
committerJon Harper <jon.harper87@gmail.com>
Sun, 29 Sep 2013 17:37:35 +0000 (19:37 +0200)
extra/rosetta-code/metronome/metronome.factor

index d9095bc065e62074ba9bcb39bd74ecd634049db9..e7fa848c2a395b252a6ccfb4406e96da7b8d3b83 100644 (file)
@@ -2,8 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 
 USING: accessors calendar circular colors.constants colors.hsv
-concurrency.semaphores kernel math openal.example threads timers
-ui ui.gadgets ui.gadgets.worlds ui.pens.solid ;
+concurrency.semaphores continuations kernel math openal.example
+threads timers ui ui.gadgets ui.gadgets.worlds ui.pens.solid ;
 IN: rosetta-code.metronome
 
 : bpm>duration ( bpm -- duration ) 60 swap / seconds ;
@@ -32,9 +32,11 @@ IN: rosetta-code.metronome
 : start-metronome-timer ( bpm -- timer semaphore )
     0 <semaphore> [ (start-metronome-timer) ] keep ;
 
+: run-metronome ( semaphore notes -- )
+    [ open-metronome-window ] 2dip <circular> swap metronome-loop ;
+
 : metronome ( bpm notes -- )
     [ start-metronome-timer ] dip
-    [ open-metronome-window ] 2dip <circular> swap metronome-loop
-    stop-timer ;
+    [ run-metronome ] curry [ stop-timer ] [ ] cleanup ;
 
 ! example usage: 60 { 440 220 330 } metronome