|
| 1 | +;; Copyright (c) Rich Hickey and contributors. All rights reserved. |
| 2 | +;; The use and distribution terms for this software are covered by the |
| 3 | +;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) |
| 4 | +;; which can be found in the file epl-v10.html at the root of this distribution. |
| 5 | +;; By using this software in any fashion, you are agreeing to be bound by |
| 6 | +;; the terms of this license. |
| 7 | +;; You must not remove this notice, or any other, from this software. |
| 8 | + |
| 9 | +;;;; flow config |
| 10 | + |
| 11 | +(ns clojure.core.async.flow.specs |
| 12 | + (:require |
| 13 | + [clojure.spec.alpha :as s])) |
| 14 | + |
| 15 | +;; process identifier |
| 16 | +(s/def ::pid keyword?) |
| 17 | + |
| 18 | +;; proc in/out identifier |
| 19 | +(s/def ::ioid keyword?) |
| 20 | + |
| 21 | +;; channel end defined by tuple of pid and ioid |
| 22 | +(s/def ::port (s/tuple ::pid ::ioid)) |
| 23 | + |
| 24 | +;; proc function - symbol resolving to a fn or a fn |
| 25 | +(s/def ::proc (s/or symbol? ifn?)) |
| 26 | + |
| 27 | +;; proc arg map - arbitrary, keys defined by proc fn |
| 28 | +(s/def ::args map?) |
| 29 | + |
| 30 | +;; chan config - buffer symbol or fixed buffer size |
| 31 | +(s/def ::buf-or-n (s/or symbol? int?)) |
| 32 | + |
| 33 | +;; chan definition - chan config + xform |
| 34 | +(s/def ::chan-def |
| 35 | + (s/keys :opt-un [::buf-or-n ::xform])) |
| 36 | + |
| 37 | +;; channel opts for a proc, map of ioid to channel definition |
| 38 | +(s/def ::chan-opts |
| 39 | + (s/map-of ::ioid ::chan-def)) |
| 40 | + |
| 41 | +;; process definition |
| 42 | +(s/def ::proc-def |
| 43 | + (s/keys :opt-un [::proc ::args ::chan-opts])) |
| 44 | + |
| 45 | +;; map of pid to proc def in flow |
| 46 | +(s/def ::procs |
| 47 | + (s/map-of ::pid ::proc-def)) |
| 48 | + |
| 49 | +;; connection is a tuple of from-port and to-port |
| 50 | +(s/def ::conn |
| 51 | + (s/tuple ::port ::port)) |
| 52 | + |
| 53 | +;; connections |
| 54 | +(s/def ::conns |
| 55 | + (s/coll-of ::conn)) |
| 56 | + |
| 57 | +;; flow config consists of procs and conns |
| 58 | +;; the exec options take something that resolves to an ExecutorService |
| 59 | +(s/def ::flow-config |
| 60 | + (s/keys :opt-un [::procs ::conns |
| 61 | + ::mixed-exec ::io-exec ::compute-exec])) |
| 62 | + |
| 63 | +;;;; process description |
| 64 | + |
| 65 | +;; defines the parameters a proc takes, kw->docstring |
| 66 | +(s/def ::params |
| 67 | + (s/map-of keyword? string?)) |
| 68 | + |
| 69 | +;; defines the in channels a proc takes, kw->docstring |
| 70 | +(s/def ::ins |
| 71 | + (s/map-of keyword? string?)) |
| 72 | + |
| 73 | +;; defines the out channels a proc takes, kw->docstring |
| 74 | +(s/def ::outs |
| 75 | + (s/map-of keyword? string?)) |
| 76 | + |
| 77 | +;; proc workload type |
| 78 | +(s/def ::workload #{:mixed :io :compute}) |
| 79 | + |
| 80 | +;; returned by the proc :describe function |
| 81 | +(s/def ::proc-description |
| 82 | + (s/keys |
| 83 | + :opt-un [::params ::ins ::outs ::workload])) |
| 84 | + |
0 commit comments