 (ns overtone.sc.machinery.server.comms
   (:use [overtone.sc.machinery.server osc-validator]
-        [overtone.libs.event]
+        [overtone.libs event counters]
         [overtone.util.lib :only [uuid deref!]])
   (:require [overtone.util.log :as log]))
 
-(defonce server-sync-id* (atom 0))
 (defonce osc-debug*     (atom false))
 (defonce server-osc-peer*        (ref nil))
 

  synchronise with its completion. The action-fn can sync using the fn server-sync.
  Returns the result of action-fn."
  [action-fn]
  (let [id (update-server-sync-id)
        prom (promise)
        key (uuid)]
    (on-event "/synced"

      (log/debug (str "Sending: " path [args])))
    (apply validated-snd @server-osc-peer* path args)))

(defn on-server-sync
  "Registers the handler to be executed when all the osc messages generated
   by executing the action-fn have completed. Returns result of action-fn."
  [action-fn handler-fn]
  (let [id (next-id ::server-sync-id)
        key (uuid)]
    (on-event "/synced"
              (fn [msg] (when (= id (first (:args msg)))
