   "Calls resource-fn until it returns a non-nil value and returns it. If resource-fn
 returns nil, waits for step milliseconds, and repeats. Returns nil if resource-fn
 never returned a non-nil value before the timeout occurred."
-  [resource-fn timeout step]
+  [resource-fn timeout step monitor]
   (loop
     [self-timeout timeout]
     (if (and 
           (> self-timeout 0) 
-          (not (Thread/interrupted)))
+          (not (Thread/interrupted))
+          (not (.isCanceled monitor)))
       (let [resource (resource-fn)]
         (if resource
           resource

          (let
            [startup-file-selection (StructuredSelection. (.getFile (.getFolder project "src") "labrepl.clj"))
              browser-labrepl-job
                (proxy [UIJob] ["Start Labrepl Session and Browser"]
			            (runInUIThread [monitor]
			              (.launch (ClojureLaunchShortcut.) startup-file-selection ILaunchManager/RUN_MODE)
										(let [console (wait-for-resource #(ClojureClient/findActiveReplConsole) *timeout* *step*)]
                      (if console
                        (do
	                        (EvaluateTextAction/evaluateText console "(labrepl/-main)")
										      (open-browser)
                          Status/OK_STATUS)
                        Status/CANCEL_STATUS))))]
            (.schedule browser-labrepl-job)))))))

(defn -run
  [this monitor]
  (let
    [monitor (if monitor monitor (NullProgressMonitor.))
      state @(.state this)
      page (:page state)
      overwrite-query (:overwrite-query state)]
    (try

     [org.eclipse.ui.wizards.datatransfer ImportOperation
                                          ZipFileStructureProvider]
     [org.eclipse.ui.browser IWorkbenchBrowserSupport]
     [org.eclipse.ui.progress WorkbenchJob])
  
  (:use
    [leiningen.core :only [read-project defproject]]
