├── .gitignore ├── README.md ├── project.clj └── src └── leiningen └── pdo.clj /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /lib 3 | /classes 4 | /checkouts 5 | pom.xml 6 | *.jar 7 | *.class 8 | .lein-deps-sum 9 | .lein-failures 10 | .lein-plugins -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lein-pdo 2 | 3 | A leiningen plugin for running multiple tasks in parallel. This is primarily useful 4 | for running multiple tasks where one or more would normally block forever, preventing 5 | future tasks from executing. 6 | 7 | If you like this, yell at @technomancy and make him put it in leiningen proper. 8 | 9 | This task does not work with < lein 2. 10 | 11 | ## Usage 12 | 13 | Put `[lein-pdo "0.1.1"]` into the `:plugins` vector of your 14 | `:user` profile. 15 | 16 | You can use it just like the `do` task: 17 | 18 | ``` 19 | lein pdo cljsbuild auto, repl 20 | ``` 21 | 22 | If you had used the `do` task, `cljsbuild` would block forever and the `repl` task would 23 | never execute. With `pdo`, `cljsbuild auto` runs inside of a future and the repl task 24 | (or any task in the last position) runs in the main thread, doing what you want. 25 | 26 | ## License 27 | 28 | Copyright © 2012 Anthony Grimes 29 | 30 | Distributed under the Eclipse Public License, the same as Clojure. 31 | -------------------------------------------------------------------------------- /project.clj: -------------------------------------------------------------------------------- 1 | (defproject lein-pdo "0.1.1" 2 | :description "Execute tasks in parallel. Like the 'do' task only... parallel." 3 | :url "https://github.com/Raynes/lein-pdo" 4 | :license {:name "Eclipse Public License" 5 | :url "http://www.eclipse.org/legal/epl-v10.html"} 6 | :eval-in-leiningen true) -------------------------------------------------------------------------------- /src/leiningen/pdo.clj: -------------------------------------------------------------------------------- 1 | (ns leiningen.pdo 2 | (:require [leiningen.do :refer [group-args]] 3 | [leiningen.core.main :refer [apply-task lookup-alias]])) 4 | 5 | (defn apply-in-future [project task-name args] 6 | (future (apply-task (lookup-alias task-name project) project args))) 7 | 8 | (defn ^:no-project-needed ^:higher-order pdo 9 | "Higher-order task to perform other tasks in parallel. 10 | 11 | Each comma-separated group should be a task named followed by optional arguments. 12 | Each task will be executed in a separate future. The last task will be executed 13 | in the current (main) thread. After it finishes, each future will be dereffed in 14 | order to prevent Leiningen from exiting before all tasks have finished. 15 | 16 | This task is primarily useful for running multiple tasks that block forever. 17 | 18 | USAGE: lein pdo cljsbuild auto, repl" 19 | [project & args] 20 | (let [[last parallel] ((juxt last butlast) (group-args args)) 21 | futures (when (seq parallel) 22 | (doall 23 | (for [[task-name & args] parallel] 24 | (apply-in-future project task-name args)))) 25 | [task-name & args] last] 26 | (apply-task (lookup-alias task-name project) project args) 27 | (doseq [task futures] 28 | @task))) --------------------------------------------------------------------------------