         ;; Two pieces of state are maintained:
         ;;  - the set of seen events
         ;;  - the set of started tasks
+        _           (assert (or (nil? db-path) (vector? db-path)) "aync-flow: db-path must be a vector")
         local-store (atom {})
         set-state   (if db-path
                       (fn [db seen started]


(defn massage-rules
  "Massage the supplied rules as follows:
    - replace `:when` keyword value with a function  implements the predicate
    - ensure that `:dispatch` is always a list and turn  `:done` into the right event
    - ensure that :events is a set
    - add a unique id"
  [id rules]
  (let [halt-event  [id :halt]
        when->fn {:seen? all-events-seen?
                  :seen-both? all-events-seen?
                  :all-events-seen? all-events-seen?
                  :any-events-seen? any-events-seen?}]
    (->> rules
         (map-indexed (fn [index {:keys [when events dispatch]}]
                        (let [w  (when->fn when)
                              _  (assert (some? w) (str "aync-flow: found illegal value for :when: " when))]
                          {:id        index
                           :when      w
                           :events    (if (coll? events) (set events) #{events})
                           :dispatch  (cond
                                        (vector? dispatch)  (list dispatch)

                                        :else  (js/console.error "aync-flow: dispatch value not valid: " dispatch))}))))))


;; -- Create Event Handler

(defn make-flow-event-handler
  "given a flow definitiion, returns an event handler which implements this definition"
  [{:keys [id db-path rules first-dispatch]}]
  (let [id  (or id default-id)

