|
42 | 42 | or an (async ...) block. |
43 | 43 |
|
44 | 44 | Usage: |
45 | | - (require '[clojure.clr.async.task.alpha :as t]) |
46 | 45 | (t/await (.ReadAllTextAsync System.IO.File path))" |
47 | 46 | [task-expr] |
48 | 47 | `(await* ~task-expr)) |
|
78 | 77 | |
79 | 78 | timeout values can be any numeric value (cast to int, milliseconds, -1 = no limit) or a TimeSpan" |
80 | 79 | ([tasks] (Task/WaitAll ^Task/1 (into-array Task tasks))) |
81 | | - ([tasks timeout] (Task/WaitAll ^Task/1 (into-array Task tasks) ^int (convert-timeout timeout))) |
82 | | - ([tasks timeout cancellation-token] (Task/WaitAll ^Task/1 (into-array Task tasks) (convert-timeout timeout) cancellation-token))) |
| 80 | + ([tasks timeout] (Task/WaitAll ^Task/1 (into-array Task tasks) (int (convert-timeout timeout)))) |
| 81 | + ([tasks timeout cancellation-token] (Task/WaitAll ^Task/1 (into-array Task tasks) (int (convert-timeout timeout)) cancellation-token))) |
83 | 82 |
|
84 | 83 |
|
85 | 84 | (defn wait-any |
|
96 | 95 | (nth tasks idx))) |
97 | 96 | ([tasks timeout] |
98 | 97 | (let [^Task/1 task-array (into-array Task tasks) |
99 | | - idx (Task/WaitAny task-array ^int (convert-timeout timeout))] |
| 98 | + idx (Task/WaitAny task-array (int (convert-timeout timeout)))] |
100 | 99 | (when-not (= idx -1) |
101 | 100 | (nth tasks idx)))) |
102 | 101 | ([tasks timeout cancellation-token] |
103 | 102 | (let [^Task/1 task-array (into-array Task tasks) |
104 | | - idx (Task/WaitAny task-array (convert-timeout timeout) cancellation-token)] |
| 103 | + idx (Task/WaitAny task-array (int (convert-timeout timeout)) cancellation-token)] |
105 | 104 | (when-not (= idx -1) |
106 | 105 | (nth tasks idx))))) |
107 | 106 |
|
|
120 | 119 | (map result tasks))) |
121 | 120 | ([tasks timeout] |
122 | 121 | (let [^Task/1 task-array (into-array Task tasks)] |
123 | | - (Task/WaitAll task-array ^int (convert-timeout timeout)) |
124 | | - (map result tasks))) |
| 122 | + (when (Task/WaitAll task-array (int (convert-timeout timeout))) |
| 123 | + (map result tasks)))) |
125 | 124 | ([tasks timeout cancellation-token] |
126 | 125 | (let [^Task/1 task-array (into-array Task tasks)] |
127 | | - (Task/WaitAll task-array (convert-timeout timeout) cancellation-token) |
128 | | - (map result tasks)))) |
| 126 | + (when (Task/WaitAll task-array (int (convert-timeout timeout)) cancellation-token) |
| 127 | + (map result tasks))))) |
129 | 128 |
|
130 | 129 | (defn wait-any-result |
131 | 130 | "Waits for any of the provided Task to complete execution. Returns the result of the task that completed or nil if a timeout occurred. |
|
142 | 141 | (result (nth tasks idx))))) |
143 | 142 | ([tasks timeout] |
144 | 143 | (let [^Task/1 task-array (into-array Task tasks) |
145 | | - idx (Task/WaitAny task-array ^int (convert-timeout timeout))] |
| 144 | + idx (Task/WaitAny task-array (int (convert-timeout timeout)))] |
146 | 145 | (when-not (= idx -1) |
147 | 146 | (result (nth tasks idx))))) |
148 | 147 | ([tasks timeout cancellation-token] |
149 | 148 | (let [^Task/1 task-array (into-array Task tasks) |
150 | | - idx (Task/WaitAny task-array (convert-timeout timeout) cancellation-token)] |
| 149 | + idx (Task/WaitAny task-array (int (convert-timeout timeout)) cancellation-token)] |
151 | 150 | (when-not (= idx -1) |
152 | 151 | (result (nth tasks idx)))))) |
153 | 152 |
|
|
160 | 159 |
|
161 | 160 | Usage: |
162 | 161 | (t/await (t/delay-task 1000))" |
163 | | - [milliseconds] |
| 162 | + ^Task [milliseconds] |
164 | 163 | (Task/Delay (int milliseconds))) |
165 | 164 |
|
166 | 165 | (defn ->task |
167 | 166 | "Wraps a value in a completed Task<object>. |
168 | 167 |
|
169 | 168 | Usage: |
170 | 169 | (t/->task 42) ;=> completed Task whose result is 42" |
171 | | - [value] |
| 170 | + ^TaskObj [value] |
172 | 171 | (Task/FromResult (type-args Object) value)) |
173 | 172 |
|
174 | 173 | (defn completed-task |
175 | 174 | "Returns a cached, already-completed void Task." |
176 | | - [] |
| 175 | + ^Task [] |
177 | 176 | Task/CompletedTask) |
178 | 177 |
|
179 | 178 | (defn task? |
|
186 | 185 |
|
187 | 186 | Usage: |
188 | 187 | (t/await (t/run (fn [] (+ 1 2 3))))" |
189 | | - [f] |
| 188 | + ^TaskObj [f] |
190 | 189 | (let [func (gen-delegate |System.Func`1[System.Object]| [] (f))] |
191 | 190 | (Task/Run func))) |
0 commit comments