Permalink
Browse files

First commit.

  • Loading branch information...
0 parents commit 3fe2c8affb7ae06a8053ae61b507855ee2528575 @Raynes committed Jul 30, 2012
Showing with 44 additions and 0 deletions.
  1. +10 −0 .gitignore
  2. +6 −0 project.clj
  3. +28 −0 src/leiningen/pdo.clj
@@ -0,0 +1,10 @@
+/target
+/lib
+/classes
+/checkouts
+pom.xml
+*.jar
+*.class
+.lein-deps-sum
+.lein-failures
+.lein-plugins
@@ -0,0 +1,6 @@
+(defproject lein-pdo "0.1.0"
+ :description "Execute tasks in parallel. Like the 'do' task only... parallel."
+ :url "https://github.com/Raynes/lein-pdo"
+ :license {:name "Eclipse Public License"
+ :url "http://www.eclipse.org/legal/epl-v10.html"}
+ :eval-in-leiningen true)
@@ -0,0 +1,28 @@
+(ns leiningen.pdo
+ (:require [leiningen.do :refer [group-args]]
+ [leiningen.core.main :refer [apply-task lookup-alias]]))
+
+(defn apply-in-future [project task-name args]
+ (future (apply-task (lookup-alias task-name project) project args)))
+
+(defn ^:no-project-needed ^:higher-order pdo
+ "Higher-order task to perform other tasks in parallel.
+
+Each comma-separated group should be a task named followed by optional arguments.
+Each task will be executed in a separate future. The last task will be executed
+in the current (main) thread. After it finishes, each future will be dereffed in
+order to prevent Leiningen from exiting before all tasks have finished.
+
+This task is primarily useful for running multiple tasks that block forever.
+
+USAGE: lein pdo cljsbuild auto, repl"
+ [project & args]
+ (let [[last parallel] ((juxt last butlast) (group-args args))
+ futures (when (seq parallel)
+ (doall
+ (for [[task-name & args] parallel]
+ (apply-in-future project task-name args))))
+ [task-name & args] last]
+ (apply-task (lookup-alias task-name project) project args)
+ (doseq [task futures]
+ @task)))

0 comments on commit 3fe2c8a

Please sign in to comment.