    config :- jruby-schemas/JRubyConfig
    flush-instance-fn :- IFn]
   (let [instance (jruby-schemas/map->JRubyInstance
-                   {:id id
-                    :internal {:pool pool
-                               :max-borrows (:max-borrows-per-instance config)
-                               :flush-instance-fn flush-instance-fn
-                               :state (atom {:borrow-count 0})}
-                    :scripting-container (ScriptingContainer.
-                                           LocalContextScope/SINGLETHREAD)})
+                  {:id id
+                   :internal {:pool pool
+                              :max-borrows (:max-borrows-per-instance config)
+                              :flush-instance-fn flush-instance-fn
+                              :state (atom {:borrow-count 0})}
+                   :scripting-container (ScriptingContainer.
+                                         LocalContextScope/SINGLETHREAD)})
         modified-instance (merge instance {:jruby-puppet (mock-jruby-instance-creator-fn)
                                            :environment-registry (puppet-env/environment-registry)})]
     (.register pool modified-instance)

  which will either return an interpreter if one is available within the
  timeout length, or will return nil after the timeout expires if no
  interpreters are available. This timeout defaults to 1200000 milliseconds.
  `reason` is an identifier (usually a map) describing the reason for borrowing the
  JRuby instance.  It may be used for metrics and logging purposes."
  [jruby-puppet-service reason]
  (let [{:keys [pool-context]} (tk-service/service-context jruby-puppet-service)
        event-callbacks (jruby-core/get-event-callbacks pool-context)]
    (jruby-core/borrow-from-pool-with-timeout pool-context reason event-callbacks)))

(defn return-instance
  "Returns the JRubyPuppet interpreter back to the pool.
  `reason` is an identifier (usually a map) describing the reason for borrowing the
  JRuby instance.  It may be used for metrics and logging purposes, so for
  best results it should be set to the same value as it was set during the
  `borrow-instance` call."
  [jruby-puppet-service jruby-instance reason]
  (let [pool-context (:pool-context (tk-service/service-context jruby-puppet-service))
        event-callbacks (jruby-core/get-event-callbacks pool-context)]
    (jruby-core/return-to-pool jruby-instance reason event-callbacks)))


(schema/defn ^:always-validate

  to string.  For each JRuby instance in the pool, f will be called, passing in
  an integer offset into the jruby array (0..size), and f is expected to return
  a string containing a script to run against the jruby instance.

  Returns a vector containing the results of executing the scripts against the
  JRuby instances."
  [pool-context size f]
