   (:require [clojure.core.match :refer [match]]
             [clojure.string :as string]
             [clojure.pprint :as pp]
+            [io.aviso.rook :as rook]
+            [io.aviso.rook.async :as async]
             [io.aviso.rook.internals :as internals]
-            [io.aviso.rook :as rook]
             [io.aviso.rook.schema-validation :as sv]))
 
 (def ^:private default-mappings

  ([options dispatch-table]
     (let [dt  (unnest-dispatch-table dispatch-table)
           req (gensym "request__")
           emit-fn (or (:emit-fn options) eval)]
       (emit-fn
         `(fn rook-dispatcher# [~req]
            (match (preparse-request ~req)
              ~@(mapcat
                  (fn [[method pathvec verb-fn-sym middleware]]
                    (let [metadata         (meta (resolve verb-fn-sym))
                          pathvec          (keywords->symbols pathvec)
                          route-params     (set (filter symbol? pathvec))
                          arglist          (first (:arglists metadata))

                  (-> ~request-sym :rook :arg-resolvers)))])
    arglist))

(defn apply-middleware-sync [middleware sync? handler]
  (middleware handler))

(defn apply-middleware-async [middleware sync? handler]
  (middleware
    (if sync?
      (async/ring-handler->async-handler handler)
      handler)))

(defn compile-dispatch-table
  "Compiles the dispatch table into a Ring handler.

