                                     (str (name kwd) ":" val "; "))
                                  (apply hash-map info))))})
 
+(defn get-worker-state []
+  (let [res (atom nil)
+        ll (CountDownLatch. 1)]
+    (Platform/runLater
+      (fn []
+        (swap! res (fn [x] (.getState (.getLoadWorker @engine))))
+        (.countDown ll)))
+    (.await ll)
+    @res))
+
+(defn wait-for-worker []
+  (let [state (get-worker-state)]
+    (cond (= Worker$State/SUCCEEDED state) state
+          (= Worker$State/FAILED state) state
+          (= Worker$State/CANCELLED state) state
+          :else (do (println "waiting for worker ... state was" state)
+                    (Thread/sleep 10) (recur)))))
+
 (defn render-string [s]
   (if @engine
     (do
-      (let [ll (CountDownLatch. 1)]
-        (Platform/runLater (fn [] (.loadContent @engine s "text/html")))
-        (Platform/runLater (fn [] (.countDown ll)))
-        (.await ll)))
+      (Platform/runLater (fn [] (.loadContent @engine s "text/html")))
+      (wait-for-worker))
     (do
       (launch)
       (.await latch)

    (Platform/runLater (fn [] (.setPrefWidth @webview width)))
    (Platform/runLater (fn [] (.sizeToScene @stage)))
    (Platform/runLater (fn [] (.show @stage)))
    (Platform/runLater
      (fn []
        (let [snap (SnapshotParameters.)]

           (javafx.geometry Rectangle2D)
           (javafx.embed.swing SwingFXUtils)
           (javax.imageio ImageIO)
           (java.io File)
           (javafx.concurrent Worker$State)))

(defonce latch (CountDownLatch. 1))
(defonce webview (atom nil))
