New upstream version 1.3.610
Louis-Philippe Véronneau
3 years ago
0 | Eclipse Public License - v 1.0 | |
1 | ||
2 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC | |
3 | LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM | |
4 | CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. | |
5 | ||
6 | 1. DEFINITIONS | |
7 | ||
8 | "Contribution" means: | |
9 | ||
10 | a) in the case of the initial Contributor, the initial code and documentation | |
11 | distributed under this Agreement, and | |
12 | b) in the case of each subsequent Contributor: | |
13 | i) changes to the Program, and | |
14 | ii) additions to the Program; | |
15 | ||
16 | where such changes and/or additions to the Program originate from and are | |
17 | distributed by that particular Contributor. A Contribution 'originates' | |
18 | from a Contributor if it was added to the Program by such Contributor | |
19 | itself or anyone acting on such Contributor's behalf. Contributions do not | |
20 | include additions to the Program which: (i) are separate modules of | |
21 | software distributed in conjunction with the Program under their own | |
22 | license agreement, and (ii) are not derivative works of the Program. | |
23 | ||
24 | "Contributor" means any person or entity that distributes the Program. | |
25 | ||
26 | "Licensed Patents" mean patent claims licensable by a Contributor which are | |
27 | necessarily infringed by the use or sale of its Contribution alone or when | |
28 | combined with the Program. | |
29 | ||
30 | "Program" means the Contributions distributed in accordance with this | |
31 | Agreement. | |
32 | ||
33 | "Recipient" means anyone who receives the Program under this Agreement, | |
34 | including all Contributors. | |
35 | ||
36 | 2. GRANT OF RIGHTS | |
37 | a) Subject to the terms of this Agreement, each Contributor hereby grants | |
38 | Recipient a non-exclusive, worldwide, royalty-free copyright license to | |
39 | reproduce, prepare derivative works of, publicly display, publicly | |
40 | perform, distribute and sublicense the Contribution of such Contributor, | |
41 | if any, and such derivative works, in source code and object code form. | |
42 | b) Subject to the terms of this Agreement, each Contributor hereby grants | |
43 | Recipient a non-exclusive, worldwide, royalty-free patent license under | |
44 | Licensed Patents to make, use, sell, offer to sell, import and otherwise | |
45 | transfer the Contribution of such Contributor, if any, in source code and | |
46 | object code form. This patent license shall apply to the combination of | |
47 | the Contribution and the Program if, at the time the Contribution is | |
48 | added by the Contributor, such addition of the Contribution causes such | |
49 | combination to be covered by the Licensed Patents. The patent license | |
50 | shall not apply to any other combinations which include the Contribution. | |
51 | No hardware per se is licensed hereunder. | |
52 | c) Recipient understands that although each Contributor grants the licenses | |
53 | to its Contributions set forth herein, no assurances are provided by any | |
54 | Contributor that the Program does not infringe the patent or other | |
55 | intellectual property rights of any other entity. Each Contributor | |
56 | disclaims any liability to Recipient for claims brought by any other | |
57 | entity based on infringement of intellectual property rights or | |
58 | otherwise. As a condition to exercising the rights and licenses granted | |
59 | hereunder, each Recipient hereby assumes sole responsibility to secure | |
60 | any other intellectual property rights needed, if any. For example, if a | |
61 | third party patent license is required to allow Recipient to distribute | |
62 | the Program, it is Recipient's responsibility to acquire that license | |
63 | before distributing the Program. | |
64 | d) Each Contributor represents that to its knowledge it has sufficient | |
65 | copyright rights in its Contribution, if any, to grant the copyright | |
66 | license set forth in this Agreement. | |
67 | ||
68 | 3. REQUIREMENTS | |
69 | ||
70 | A Contributor may choose to distribute the Program in object code form under | |
71 | its own license agreement, provided that: | |
72 | ||
73 | a) it complies with the terms and conditions of this Agreement; and | |
74 | b) its license agreement: | |
75 | i) effectively disclaims on behalf of all Contributors all warranties | |
76 | and conditions, express and implied, including warranties or | |
77 | conditions of title and non-infringement, and implied warranties or | |
78 | conditions of merchantability and fitness for a particular purpose; | |
79 | ii) effectively excludes on behalf of all Contributors all liability for | |
80 | damages, including direct, indirect, special, incidental and | |
81 | consequential damages, such as lost profits; | |
82 | iii) states that any provisions which differ from this Agreement are | |
83 | offered by that Contributor alone and not by any other party; and | |
84 | iv) states that source code for the Program is available from such | |
85 | Contributor, and informs licensees how to obtain it in a reasonable | |
86 | manner on or through a medium customarily used for software exchange. | |
87 | ||
88 | When the Program is made available in source code form: | |
89 | ||
90 | a) it must be made available under this Agreement; and | |
91 | b) a copy of this Agreement must be included with each copy of the Program. | |
92 | Contributors may not remove or alter any copyright notices contained | |
93 | within the Program. | |
94 | ||
95 | Each Contributor must identify itself as the originator of its Contribution, | |
96 | if | |
97 | any, in a manner that reasonably allows subsequent Recipients to identify the | |
98 | originator of the Contribution. | |
99 | ||
100 | 4. COMMERCIAL DISTRIBUTION | |
101 | ||
102 | Commercial distributors of software may accept certain responsibilities with | |
103 | respect to end users, business partners and the like. While this license is | |
104 | intended to facilitate the commercial use of the Program, the Contributor who | |
105 | includes the Program in a commercial product offering should do so in a manner | |
106 | which does not create potential liability for other Contributors. Therefore, | |
107 | if a Contributor includes the Program in a commercial product offering, such | |
108 | Contributor ("Commercial Contributor") hereby agrees to defend and indemnify | |
109 | every other Contributor ("Indemnified Contributor") against any losses, | |
110 | damages and costs (collectively "Losses") arising from claims, lawsuits and | |
111 | other legal actions brought by a third party against the Indemnified | |
112 | Contributor to the extent caused by the acts or omissions of such Commercial | |
113 | Contributor in connection with its distribution of the Program in a commercial | |
114 | product offering. The obligations in this section do not apply to any claims | |
115 | or Losses relating to any actual or alleged intellectual property | |
116 | infringement. In order to qualify, an Indemnified Contributor must: | |
117 | a) promptly notify the Commercial Contributor in writing of such claim, and | |
118 | b) allow the Commercial Contributor to control, and cooperate with the | |
119 | Commercial Contributor in, the defense and any related settlement | |
120 | negotiations. The Indemnified Contributor may participate in any such claim at | |
121 | its own expense. | |
122 | ||
123 | For example, a Contributor might include the Program in a commercial product | |
124 | offering, Product X. That Contributor is then a Commercial Contributor. If | |
125 | that Commercial Contributor then makes performance claims, or offers | |
126 | warranties related to Product X, those performance claims and warranties are | |
127 | such Commercial Contributor's responsibility alone. Under this section, the | |
128 | Commercial Contributor would have to defend claims against the other | |
129 | Contributors related to those performance claims and warranties, and if a | |
130 | court requires any other Contributor to pay any damages as a result, the | |
131 | Commercial Contributor must pay those damages. | |
132 | ||
133 | 5. NO WARRANTY | |
134 | ||
135 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN | |
136 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR | |
137 | IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, | |
138 | NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each | |
139 | Recipient is solely responsible for determining the appropriateness of using | |
140 | and distributing the Program and assumes all risks associated with its | |
141 | exercise of rights under this Agreement , including but not limited to the | |
142 | risks and costs of program errors, compliance with applicable laws, damage to | |
143 | or loss of data, programs or equipment, and unavailability or interruption of | |
144 | operations. | |
145 | ||
146 | 6. DISCLAIMER OF LIABILITY | |
147 | ||
148 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY | |
149 | CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
150 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION | |
151 | LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
152 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
153 | ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE | |
154 | EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY | |
155 | OF SUCH DAMAGES. | |
156 | ||
157 | 7. GENERAL | |
158 | ||
159 | If any provision of this Agreement is invalid or unenforceable under | |
160 | applicable law, it shall not affect the validity or enforceability of the | |
161 | remainder of the terms of this Agreement, and without further action by the | |
162 | parties hereto, such provision shall be reformed to the minimum extent | |
163 | necessary to make such provision valid and enforceable. | |
164 | ||
165 | If Recipient institutes patent litigation against any entity (including a | |
166 | cross-claim or counterclaim in a lawsuit) alleging that the Program itself | |
167 | (excluding combinations of the Program with other software or hardware) | |
168 | infringes such Recipient's patent(s), then such Recipient's rights granted | |
169 | under Section 2(b) shall terminate as of the date such litigation is filed. | |
170 | ||
171 | All Recipient's rights under this Agreement shall terminate if it fails to | |
172 | comply with any of the material terms or conditions of this Agreement and does | |
173 | not cure such failure in a reasonable period of time after becoming aware of | |
174 | such noncompliance. If all Recipient's rights under this Agreement terminate, | |
175 | Recipient agrees to cease use and distribution of the Program as soon as | |
176 | reasonably practicable. However, Recipient's obligations under this Agreement | |
177 | and any licenses granted by Recipient relating to the Program shall continue | |
178 | and survive. | |
179 | ||
180 | Everyone is permitted to copy and distribute copies of this Agreement, but in | |
181 | order to avoid inconsistency the Agreement is copyrighted and may only be | |
182 | modified in the following manner. The Agreement Steward reserves the right to | |
183 | publish new versions (including revisions) of this Agreement from time to | |
184 | time. No one other than the Agreement Steward has the right to modify this | |
185 | Agreement. The Eclipse Foundation is the initial Agreement Steward. The | |
186 | Eclipse Foundation may assign the responsibility to serve as the Agreement | |
187 | Steward to a suitable separate entity. Each new version of the Agreement will | |
188 | be given a distinguishing version number. The Program (including | |
189 | Contributions) may always be distributed subject to the version of the | |
190 | Agreement under which it was received. In addition, after a new version of the | |
191 | Agreement is published, Contributor may elect to distribute the Program | |
192 | (including its Contributions) under the new version. Except as expressly | |
193 | stated in Sections 2(a) and 2(b) above, Recipient receives no rights or | |
194 | licenses to the intellectual property of any Contributor under this Agreement, | |
195 | whether expressly, by implication, estoppel or otherwise. All rights in the | |
196 | Program not expressly granted under this Agreement are reserved. | |
197 | ||
198 | This Agreement is governed by the laws of the State of New York and the | |
199 | intellectual property laws of the United States of America. No party to this | |
200 | Agreement will bring a legal action under this Agreement more than one year | |
201 | after the cause of action arose. Each party waives its rights to a jury trial in | |
202 | any resulting litigation. | |
203 | ||
204 |
4 | 4 | |
5 | 5 | ## Releases and Dependency Information |
6 | 6 | |
7 | Latest release: 0.3.442 | |
7 | This project follows the version scheme MAJOR.MINOR.COMMITS where MAJOR and MINOR provide some relative indication of the size of the change, but do not follow semantic versioning. In general, all changes endeavor to be non-breaking (by moving to new names rather than by breaking existing names). COMMITS is an ever-increasing counter of commits since the beginning of this repository. | |
8 | ||
9 | Latest release: 1.2.603 | |
8 | 10 | |
9 | 11 | * [All Released Versions](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.clojure%22%20AND%20a%3A%22core.async%22) |
12 | ||
13 | [deps.edn](https://clojure.org/reference/deps_and_cli) dependency information: | |
14 | ||
15 | ```clj | |
16 | org.clojure/core.async {:mvn/version "1.2.603"} | |
17 | ``` | |
10 | 18 | |
11 | 19 | [Leiningen](https://github.com/technomancy/leiningen) dependency information: |
12 | 20 | |
13 | 21 | ```clj |
14 | [org.clojure/clojure "1.6.0"] | |
15 | [org.clojure/core.async "0.3.442"] | |
22 | [org.clojure/core.async "1.2.603"] | |
16 | 23 | ``` |
17 | 24 | |
18 | 25 | [Maven](http://maven.apache.org/) dependency information: |
21 | 28 | <dependency> |
22 | 29 | <groupId>org.clojure</groupId> |
23 | 30 | <artifactId>core.async</artifactId> |
24 | <version>0.3.442</version> | |
31 | <version>1.2.603</version> | |
25 | 32 | </dependency> |
26 | 33 | ``` |
27 | 34 | |
28 | 35 | ## Documentation |
29 | 36 | |
30 | * [Rationale](http://clojure.com/blog/2013/06/28/clojure-core-async-channels.html) | |
31 | * [API docs](http://clojure.github.io/core.async/) | |
37 | * [Rationale](https://clojure.org/news/2013/06/28/clojure-clore-async-channels) | |
38 | * [API docs](https://clojure.github.io/core.async/) | |
32 | 39 | * [Code walkthrough](https://github.com/clojure/core.async/blob/master/examples/walkthrough.clj) |
33 | 40 | |
34 | 41 | ## Presentations |
36 | 43 | * [Rich Hickey on core.async](http://www.infoq.com/presentations/clojure-core-async) |
37 | 44 | * [Tim Baldridge on core.async](http://www.youtube.com/watch?v=enwIIGzhahw) from Clojure/conj 2013 ([code](https://github.com/halgari/clojure-conj-2013-core.async-examples)). |
38 | 45 | * Tim Baldridge on go macro internals - [part 1](https://www.youtube.com/watch?v=R3PZMIwXN_g) [part 2](https://www.youtube.com/watch?v=SI7qtuuahhU) |
39 | * David Nolen [core.async webinar](http://go.cognitect.com/core_async_webinar_recording) | |
40 | 46 | |
41 | 47 | ## Contributing |
42 | 48 | |
43 | [Contributing to Clojure projects](http://clojure.org/contributing) requires a signed Contributor Agreement. Pull requests and GitHub issues are not accepted; please use the [core.async JIRA project](http://dev.clojure.org/jira/browse/ASYNC) to report problems or enhancements. | |
49 | [Contributing to Clojure projects](https://clojure.org/community/contributing) requires a signed Contributor Agreement. Pull requests and GitHub issues are not accepted; please use the [core.async JIRA project](https://clojure.atlassian.net/browse/ASYNC) to report problems or enhancements. | |
44 | 50 | |
45 | 51 | To run the ClojureScript tests: |
46 | 52 | |
50 | 56 | |
51 | 57 | ## License |
52 | 58 | |
53 | Copyright © 2017 Rich Hickey and contributors | |
59 | Copyright © 2017-2020 Rich Hickey and contributors | |
54 | 60 | |
55 | 61 | Distributed under the Eclipse Public License, the same as Clojure. |
56 | 62 | |
57 | 63 | ## Changelog |
58 | 64 | |
59 | * Release 0.3.xxx on 2017.05.26 | |
60 | * | |
65 | * Release 1.2.603 on 2020.05.11 | |
66 | * Fix bug in cljs impl of onto-chan! in 1.2.598 | |
67 | * Release 1.2.598 on 2020.05.11 | |
68 | * Add onto-chan! and to-chan! to cljs core.async | |
69 | * Release 1.2.593 on 2020.05.11 | |
70 | * onto-chan use of go-loop incompatible with blocking colls, replace with onto-chan! and onto-chan!! | |
71 | * Release 1.1.587 on 2020.04.01 | |
72 | * Added :require-macros for the promise interop from 1.1.582 | |
73 | * Release 1.1.582 on 2020.03.31 | |
74 | * Bumped deps - clojure 1.9, clojurescript 1.10.1.597, cljsbuild 1.1.7, tools.analyzer.jvm 1.0.0 | |
75 | * [ASYNC-165](https://clojure.atlassian.net/browse/ASYNC-165) (CLJS) Fix inlining of let binding | |
76 | * [ASYNC-184](https://clojure.atlassian.net/browse/ASYNC-184) (CLJS) Port CLJ exception handling fixes | |
77 | * [ASYNC-228](https://clojure.atlassian.net/browse/ASYNC-228) (CLJS) Fix skip list for CLJS timers | |
78 | * [ASYNC-96](https://clojure.atlassian.net/browse/ASYNC-96) (CLJS) Fix full checking in fixed buffer | |
79 | * [ASYNC-230](https://clojure.atlassian.net/browse/ASYNC-230) (CLJS) Add js/Promise interop via core.async.interop | |
80 | * Release 1.0.567 on 2020.02.18 | |
81 | * Release 0.7.559 on 2020.01.10 | |
82 | * [ASYNC-198](https://clojure.atlassian.net/browse/ASYNC-198) (CLJ) Fix exception rewriting in go can replace return value | |
83 | * [ASYNC-220](https://clojure.atlassian.net/browse/ASYNC-220) (CLJ) Fix exception in go finally swallows exception of outer try | |
84 | * [ASYNC-229](https://clojure.atlassian.net/browse/ASYNC-229) (CLJ) Fix go finally block executed twice | |
85 | * [ASYNC-212](https://clojure.atlassian.net/browse/ASYNC-212) (CLJ) Fix go fails to compile expressions with literal nil as let value | |
86 | * [ASYNC-145](https://clojure.atlassian.net/browse/ASYNC-145) (CLJ, CLJS) Fix mix throws error when many channels added | |
87 | * [ASYNC-170](https://clojure.atlassian.net/browse/ASYNC-170) (CLJ) Fix binding in go block throws assertion error | |
88 | * [ASYNC-127](https://clojure.atlassian.net/browse/ASYNC-127) (CLJ, CLJS) Fix mult to work as doc'ed with all taps accepting before next | |
89 | * [ASYNC-210](https://clojure.atlassian.net/browse/ASYNC-210) (CLJ) Fix puts allowed when buffer still full from expanding transducer | |
90 | * Release 0.6.532 on 2019.12.02 | |
91 | * Bump tools.analyzer.jvm dep to 0.7.3 | |
92 | * Release 0.5.527 on 2019.11.12 | |
93 | * Add system property clojure.core.async.go-checking that will throw if core.async blocking ops (>!!, <!!, alts!!, alt!!) are used in a go block | |
94 | * Fix use of blocking op and thread constraints in `pipeline` - will now match `pipeline-blocking` in using N cached threads. | |
95 | * Release 0.4.500 on 2019.06.11 | |
96 | * [ASYNC-227](https://clojure.atlassian.net/browse/ASYNC-227) cljs alts! isn't non-deterministic | |
97 | * [ASYNC-224](https://clojure.atlassian.net/browse/ASYNC-224) Fix bad putter unwrapping in channel abort | |
98 | * [ASYNC-226](https://clojure.atlassian.net/browse/ASYNC-226) Fix bad cljs test code | |
99 | * Release 0.4.490 on 2018.11.19 | |
100 | * [ASYNC-216](https://clojure.atlassian.net/browse/ASYNC-216) Delay start of timeout thread | |
101 | * [ASYNC-218](https://clojure.atlassian.net/browse/ASYNC-218) Fix docstring for put! | |
102 | * [ASYNC-213](https://clojure.atlassian.net/browse/ASYNC-213) Small addition to promise-chan docstring | |
103 | * Release 0.4.474 on 2018.01.08 | |
104 | * Fix typo in error message | |
105 | * Remove Java code, depend on Java 1.7+ | |
106 | * Add deps.edn, can now be used as a git dependency | |
107 | * Release 0.3.465 on 2017.11.17 | |
108 | * [ASYNC-119](https://clojure.atlassian.net/browse/ASYNC-119) Move macros to cljs.core.async ns (CLJS) | |
109 | * [ASYNC-201](https://clojure.atlassian.net/browse/ASYNC-201) Out-of-bounds index values passed in timers (CLJS) | |
110 | * Release 0.3.443 on 2017.05.26 | |
111 | * [ASYNC-159](https://clojure.atlassian.net/browse/ASYNC-159) - promise-chan in ClojureScript is broken | |
61 | 112 | * Release 0.3.442 on 2017.03.14 |
62 | 113 | * Fix bad `:refer-clojure` clause that violates new spec in Clojure 1.9.0-alpha15 |
63 | 114 | * Release 0.3.441 on 2017.02.23 |
64 | * [ASYNC-187](http://dev.clojure.org/jira/browse/ASYNC-187) - Tag metadata is lost in local closed over by a loop | |
65 | * Related: [ASYNC-188](http://dev.clojure.org/jira/browse/ASYNC-188) | |
66 | * [ASYNC-185](http://dev.clojure.org/jira/browse/ASYNC-185) - `thread` prevents clearing of body locals | |
67 | * [ASYNC-186](http://dev.clojure.org/jira/browse/ASYNC-186) - NPE when `go` closes over a local variable bound to nil | |
115 | * [ASYNC-187](https://clojure.atlassian.net/browse/ASYNC-187) - Tag metadata is lost in local closed over by a loop | |
116 | * Related: [ASYNC-188](https://clojure.atlassian.net/browse/ASYNC-188) | |
117 | * [ASYNC-185](https://clojure.atlassian.net/browse/ASYNC-185) - `thread` prevents clearing of body locals | |
118 | * [ASYNC-186](https://clojure.atlassian.net/browse/ASYNC-186) - NPE when `go` closes over a local variable bound to nil | |
68 | 119 | * Release 0.3.426 on 2017.02.22 |
69 | * [ASYNC-169](http://dev.clojure.org/jira/browse/ASYNC-169) - handling of catch and finally inside go blocks was broken, causing a number of issues. Related: [ASYNC-100](http://dev.clojure.org/jira/browse/ASYNC-100), [ASYNC-173](http://dev.clojure.org/jira/browse/ASYNC-173), [ASYNC-180](http://dev.clojure.org/jira/browse/ASYNC-180), [ASYNC-179](http://dev.clojure.org/jira/browse/ASYNC-179), [ASYNC-122](http://dev.clojure.org/jira/browse/ASYNC-122), [ASYNC-78](http://dev.clojure.org/jira/browse/ASYNC-78), [ASYNC-168](http://dev.clojure.org/jira/browse/ASYNC-168) | |
70 | * [ASYNC-138](http://dev.clojure.org/jira/browse/ASYNC-138) - go blocks do not allow closed over locals to be cleared which can lead to a memory leak. Related: [ASYNC-32](http://dev.clojure.org/jira/browse/ASYNC-32) | |
71 | * [ASYNC-155](http://dev.clojure.org/jira/browse/ASYNC-155) - preserve loop binding metadata when inside a go block | |
72 | * [ASYNC-54](http://dev.clojure.org/jira/browse/ASYNC-54) - fix bad type hint on MAX-QUEUE-SIZE | |
73 | * [ASYNC-177](http://dev.clojure.org/jira/browse/ASYNC-177) - fix typo in Buffer protocol full? method | |
74 | * [ASYNC-70](http://dev.clojure.org/jira/browse/ASYNC-70) - docstring change in thread, thread-call | |
75 | * [ASYNC-143](http://dev.clojure.org/jira/browse/ASYNC-143) - assert that fixed buffers must have size > 0 | |
120 | * [ASYNC-169](https://clojure.atlassian.net/browse/ASYNC-169) - handling of catch and finally inside go blocks was broken, causing a number of issues. Related: [ASYNC-100](https://clojure.atlassian.net/browse/ASYNC-100), [ASYNC-173](https://clojure.atlassian.net/browse/ASYNC-173), [ASYNC-180](https://clojure.atlassian.net/browse/ASYNC-180), [ASYNC-179](https://clojure.atlassian.net/browse/ASYNC-179), [ASYNC-122](https://clojure.atlassian.net/browse/ASYNC-122), [ASYNC-78](https://clojure.atlassian.net/browse/ASYNC-78), [ASYNC-168](https://clojure.atlassian.net/browse/ASYNC-168) | |
121 | * [ASYNC-138](https://clojure.atlassian.net/browse/ASYNC-138) - go blocks do not allow closed over locals to be cleared which can lead to a memory leak. Related: [ASYNC-32](https://clojure.atlassian.net/browse/ASYNC-32) | |
122 | * [ASYNC-155](https://clojure.atlassian.net/browse/ASYNC-155) - preserve loop binding metadata when inside a go block | |
123 | * [ASYNC-54](https://clojure.atlassian.net/browse/ASYNC-54) - fix bad type hint on MAX-QUEUE-SIZE | |
124 | * [ASYNC-177](https://clojure.atlassian.net/browse/ASYNC-177) - fix typo in Buffer protocol full? method | |
125 | * [ASYNC-70](https://clojure.atlassian.net/browse/ASYNC-70) - docstring change in thread, thread-call | |
126 | * [ASYNC-143](https://clojure.atlassian.net/browse/ASYNC-143) - assert that fixed buffers must have size > 0 | |
76 | 127 | * Update tools.analyzer.jvm dependency |
77 | 128 | * Release 0.2.395 on 2016.10.12 |
78 | 129 | * Add async version of transduce |
84 | 135 | * Release 0.2.382 on 2016.06.13 |
85 | 136 | * Important: Change default dispatch thread pool size to 8. |
86 | 137 | * Add Java system property `clojure.core.async.pool-size` to set the dispatch thread pool size |
87 | * [ASYNC-152](http://dev.clojure.org/jira/browse/ASYNC-152) - disable t.a.jvm's warn-on-reflection pass | |
138 | * [ASYNC-152](https://clojure.atlassian.net/browse/ASYNC-152) - disable t.a.jvm's warn-on-reflection pass | |
88 | 139 | * Release 0.2.374 on 2015.11.11 |
89 | * [ASYNC-149](http://dev.clojure.org/jira/browse/ASYNC-149) - fix error compiling recur inside case in a go block | |
140 | * [ASYNC-149](https://clojure.atlassian.net/browse/ASYNC-149) - fix error compiling recur inside case in a go block | |
90 | 141 | * Updated tools.analyzer.jvm version (and other upstream deps) |
91 | 142 | * Updated to latest clojurescript and cljsbuild versions |
92 | 143 | * Release 0.2.371 on 2015.10.28 |
93 | * [ASYNC-124](http://dev.clojure.org/jira/browse/ASYNC-124) - dispatch multiple pending takers from expanding transducer | |
94 | * [ASYNC-103](http://dev.clojure.org/jira/browse/ASYNC-103) - NEW promise-chan | |
95 | * [ASYNC-104](http://dev.clojure.org/jira/browse/ASYNC-104) - NEW non-blocking offer!, poll! | |
96 | * [ASYNC-101](http://dev.clojure.org/jira/browse/ASYNC-101) - async/reduce now respects reduced | |
97 | * [ASYNC-112](http://dev.clojure.org/jira/browse/ASYNC-112) - replace "transformer" with "transducer" in deprecation messages | |
98 | * [ASYNC-6](http://dev.clojure.org/jira/browse/ASYNC-6) - alts! docs updated to explicitly state ports is a vector | |
144 | * [ASYNC-124](https://clojure.atlassian.net/browse/ASYNC-124) - dispatch multiple pending takers from expanding transducer | |
145 | * [ASYNC-103](https://clojure.atlassian.net/browse/ASYNC-103) - NEW promise-chan | |
146 | * [ASYNC-104](https://clojure.atlassian.net/browse/ASYNC-104) - NEW non-blocking offer!, poll! | |
147 | * [ASYNC-101](https://clojure.atlassian.net/browse/ASYNC-101) - async/reduce now respects reduced | |
148 | * [ASYNC-112](https://clojure.atlassian.net/browse/ASYNC-112) - replace "transformer" with "transducer" in deprecation messages | |
149 | * [ASYNC-6](https://clojure.atlassian.net/browse/ASYNC-6) - alts! docs updated to explicitly state ports is a vector | |
99 | 150 | * Support (try (catch :default)) in CLJS exception handling |
100 | 151 | * Use cljs.test |
101 | 152 | * Updated tools.analyzer.jvm version (and other upstream deps) |
0 | <?xml version="1.0" encoding="ISO-8859-1" ?> | |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
2 | <html xmlns="http://www.w3.org/1999/xhtml"> | |
3 | ||
4 | <head> | |
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> | |
6 | <title>Eclipse Public License - Version 1.0</title> | |
7 | <style type="text/css"> | |
8 | body { | |
9 | size: 8.5in 11.0in; | |
10 | margin: 0.25in 0.5in 0.25in 0.5in; | |
11 | tab-interval: 0.5in; | |
12 | } | |
13 | p { | |
14 | margin-left: auto; | |
15 | margin-top: 0.5em; | |
16 | margin-bottom: 0.5em; | |
17 | } | |
18 | p.list { | |
19 | margin-left: 0.5in; | |
20 | margin-top: 0.05em; | |
21 | margin-bottom: 0.05em; | |
22 | } | |
23 | </style> | |
24 | ||
25 | </head> | |
26 | ||
27 | <body lang="EN-US"> | |
28 | ||
29 | <p align=center><b>Eclipse Public License - v 1.0</b></p> | |
30 | ||
31 | <p>THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE | |
32 | PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR | |
33 | DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS | |
34 | AGREEMENT.</p> | |
35 | ||
36 | <p><b>1. DEFINITIONS</b></p> | |
37 | ||
38 | <p>"Contribution" means:</p> | |
39 | ||
40 | <p class="list">a) in the case of the initial Contributor, the initial | |
41 | code and documentation distributed under this Agreement, and</p> | |
42 | <p class="list">b) in the case of each subsequent Contributor:</p> | |
43 | <p class="list">i) changes to the Program, and</p> | |
44 | <p class="list">ii) additions to the Program;</p> | |
45 | <p class="list">where such changes and/or additions to the Program | |
46 | originate from and are distributed by that particular Contributor. A | |
47 | Contribution 'originates' from a Contributor if it was added to the | |
48 | Program by such Contributor itself or anyone acting on such | |
49 | Contributor's behalf. Contributions do not include additions to the | |
50 | Program which: (i) are separate modules of software distributed in | |
51 | conjunction with the Program under their own license agreement, and (ii) | |
52 | are not derivative works of the Program.</p> | |
53 | ||
54 | <p>"Contributor" means any person or entity that distributes | |
55 | the Program.</p> | |
56 | ||
57 | <p>"Licensed Patents" mean patent claims licensable by a | |
58 | Contributor which are necessarily infringed by the use or sale of its | |
59 | Contribution alone or when combined with the Program.</p> | |
60 | ||
61 | <p>"Program" means the Contributions distributed in accordance | |
62 | with this Agreement.</p> | |
63 | ||
64 | <p>"Recipient" means anyone who receives the Program under | |
65 | this Agreement, including all Contributors.</p> | |
66 | ||
67 | <p><b>2. GRANT OF RIGHTS</b></p> | |
68 | ||
69 | <p class="list">a) Subject to the terms of this Agreement, each | |
70 | Contributor hereby grants Recipient a non-exclusive, worldwide, | |
71 | royalty-free copyright license to reproduce, prepare derivative works | |
72 | of, publicly display, publicly perform, distribute and sublicense the | |
73 | Contribution of such Contributor, if any, and such derivative works, in | |
74 | source code and object code form.</p> | |
75 | ||
76 | <p class="list">b) Subject to the terms of this Agreement, each | |
77 | Contributor hereby grants Recipient a non-exclusive, worldwide, | |
78 | royalty-free patent license under Licensed Patents to make, use, sell, | |
79 | offer to sell, import and otherwise transfer the Contribution of such | |
80 | Contributor, if any, in source code and object code form. This patent | |
81 | license shall apply to the combination of the Contribution and the | |
82 | Program if, at the time the Contribution is added by the Contributor, | |
83 | such addition of the Contribution causes such combination to be covered | |
84 | by the Licensed Patents. The patent license shall not apply to any other | |
85 | combinations which include the Contribution. No hardware per se is | |
86 | licensed hereunder.</p> | |
87 | ||
88 | <p class="list">c) Recipient understands that although each Contributor | |
89 | grants the licenses to its Contributions set forth herein, no assurances | |
90 | are provided by any Contributor that the Program does not infringe the | |
91 | patent or other intellectual property rights of any other entity. Each | |
92 | Contributor disclaims any liability to Recipient for claims brought by | |
93 | any other entity based on infringement of intellectual property rights | |
94 | or otherwise. As a condition to exercising the rights and licenses | |
95 | granted hereunder, each Recipient hereby assumes sole responsibility to | |
96 | secure any other intellectual property rights needed, if any. For | |
97 | example, if a third party patent license is required to allow Recipient | |
98 | to distribute the Program, it is Recipient's responsibility to acquire | |
99 | that license before distributing the Program.</p> | |
100 | ||
101 | <p class="list">d) Each Contributor represents that to its knowledge it | |
102 | has sufficient copyright rights in its Contribution, if any, to grant | |
103 | the copyright license set forth in this Agreement.</p> | |
104 | ||
105 | <p><b>3. REQUIREMENTS</b></p> | |
106 | ||
107 | <p>A Contributor may choose to distribute the Program in object code | |
108 | form under its own license agreement, provided that:</p> | |
109 | ||
110 | <p class="list">a) it complies with the terms and conditions of this | |
111 | Agreement; and</p> | |
112 | ||
113 | <p class="list">b) its license agreement:</p> | |
114 | ||
115 | <p class="list">i) effectively disclaims on behalf of all Contributors | |
116 | all warranties and conditions, express and implied, including warranties | |
117 | or conditions of title and non-infringement, and implied warranties or | |
118 | conditions of merchantability and fitness for a particular purpose;</p> | |
119 | ||
120 | <p class="list">ii) effectively excludes on behalf of all Contributors | |
121 | all liability for damages, including direct, indirect, special, | |
122 | incidental and consequential damages, such as lost profits;</p> | |
123 | ||
124 | <p class="list">iii) states that any provisions which differ from this | |
125 | Agreement are offered by that Contributor alone and not by any other | |
126 | party; and</p> | |
127 | ||
128 | <p class="list">iv) states that source code for the Program is available | |
129 | from such Contributor, and informs licensees how to obtain it in a | |
130 | reasonable manner on or through a medium customarily used for software | |
131 | exchange.</p> | |
132 | ||
133 | <p>When the Program is made available in source code form:</p> | |
134 | ||
135 | <p class="list">a) it must be made available under this Agreement; and</p> | |
136 | ||
137 | <p class="list">b) a copy of this Agreement must be included with each | |
138 | copy of the Program.</p> | |
139 | ||
140 | <p>Contributors may not remove or alter any copyright notices contained | |
141 | within the Program.</p> | |
142 | ||
143 | <p>Each Contributor must identify itself as the originator of its | |
144 | Contribution, if any, in a manner that reasonably allows subsequent | |
145 | Recipients to identify the originator of the Contribution.</p> | |
146 | ||
147 | <p><b>4. COMMERCIAL DISTRIBUTION</b></p> | |
148 | ||
149 | <p>Commercial distributors of software may accept certain | |
150 | responsibilities with respect to end users, business partners and the | |
151 | like. While this license is intended to facilitate the commercial use of | |
152 | the Program, the Contributor who includes the Program in a commercial | |
153 | product offering should do so in a manner which does not create | |
154 | potential liability for other Contributors. Therefore, if a Contributor | |
155 | includes the Program in a commercial product offering, such Contributor | |
156 | ("Commercial Contributor") hereby agrees to defend and | |
157 | indemnify every other Contributor ("Indemnified Contributor") | |
158 | against any losses, damages and costs (collectively "Losses") | |
159 | arising from claims, lawsuits and other legal actions brought by a third | |
160 | party against the Indemnified Contributor to the extent caused by the | |
161 | acts or omissions of such Commercial Contributor in connection with its | |
162 | distribution of the Program in a commercial product offering. The | |
163 | obligations in this section do not apply to any claims or Losses | |
164 | relating to any actual or alleged intellectual property infringement. In | |
165 | order to qualify, an Indemnified Contributor must: a) promptly notify | |
166 | the Commercial Contributor in writing of such claim, and b) allow the | |
167 | Commercial Contributor to control, and cooperate with the Commercial | |
168 | Contributor in, the defense and any related settlement negotiations. The | |
169 | Indemnified Contributor may participate in any such claim at its own | |
170 | expense.</p> | |
171 | ||
172 | <p>For example, a Contributor might include the Program in a commercial | |
173 | product offering, Product X. That Contributor is then a Commercial | |
174 | Contributor. If that Commercial Contributor then makes performance | |
175 | claims, or offers warranties related to Product X, those performance | |
176 | claims and warranties are such Commercial Contributor's responsibility | |
177 | alone. Under this section, the Commercial Contributor would have to | |
178 | defend claims against the other Contributors related to those | |
179 | performance claims and warranties, and if a court requires any other | |
180 | Contributor to pay any damages as a result, the Commercial Contributor | |
181 | must pay those damages.</p> | |
182 | ||
183 | <p><b>5. NO WARRANTY</b></p> | |
184 | ||
185 | <p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS | |
186 | PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS | |
187 | OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, | |
188 | ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY | |
189 | OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely | |
190 | responsible for determining the appropriateness of using and | |
191 | distributing the Program and assumes all risks associated with its | |
192 | exercise of rights under this Agreement , including but not limited to | |
193 | the risks and costs of program errors, compliance with applicable laws, | |
194 | damage to or loss of data, programs or equipment, and unavailability or | |
195 | interruption of operations.</p> | |
196 | ||
197 | <p><b>6. DISCLAIMER OF LIABILITY</b></p> | |
198 | ||
199 | <p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT | |
200 | NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, | |
201 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING | |
202 | WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF | |
203 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
204 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR | |
205 | DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED | |
206 | HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</p> | |
207 | ||
208 | <p><b>7. GENERAL</b></p> | |
209 | ||
210 | <p>If any provision of this Agreement is invalid or unenforceable under | |
211 | applicable law, it shall not affect the validity or enforceability of | |
212 | the remainder of the terms of this Agreement, and without further action | |
213 | by the parties hereto, such provision shall be reformed to the minimum | |
214 | extent necessary to make such provision valid and enforceable.</p> | |
215 | ||
216 | <p>If Recipient institutes patent litigation against any entity | |
217 | (including a cross-claim or counterclaim in a lawsuit) alleging that the | |
218 | Program itself (excluding combinations of the Program with other | |
219 | software or hardware) infringes such Recipient's patent(s), then such | |
220 | Recipient's rights granted under Section 2(b) shall terminate as of the | |
221 | date such litigation is filed.</p> | |
222 | ||
223 | <p>All Recipient's rights under this Agreement shall terminate if it | |
224 | fails to comply with any of the material terms or conditions of this | |
225 | Agreement and does not cure such failure in a reasonable period of time | |
226 | after becoming aware of such noncompliance. If all Recipient's rights | |
227 | under this Agreement terminate, Recipient agrees to cease use and | |
228 | distribution of the Program as soon as reasonably practicable. However, | |
229 | Recipient's obligations under this Agreement and any licenses granted by | |
230 | Recipient relating to the Program shall continue and survive.</p> | |
231 | ||
232 | <p>Everyone is permitted to copy and distribute copies of this | |
233 | Agreement, but in order to avoid inconsistency the Agreement is | |
234 | copyrighted and may only be modified in the following manner. The | |
235 | Agreement Steward reserves the right to publish new versions (including | |
236 | revisions) of this Agreement from time to time. No one other than the | |
237 | Agreement Steward has the right to modify this Agreement. The Eclipse | |
238 | Foundation is the initial Agreement Steward. The Eclipse Foundation may | |
239 | assign the responsibility to serve as the Agreement Steward to a | |
240 | suitable separate entity. Each new version of the Agreement will be | |
241 | given a distinguishing version number. The Program (including | |
242 | Contributions) may always be distributed subject to the version of the | |
243 | Agreement under which it was received. In addition, after a new version | |
244 | of the Agreement is published, Contributor may elect to distribute the | |
245 | Program (including its Contributions) under the new version. Except as | |
246 | expressly stated in Sections 2(a) and 2(b) above, Recipient receives no | |
247 | rights or licenses to the intellectual property of any Contributor under | |
248 | this Agreement, whether expressly, by implication, estoppel or | |
249 | otherwise. All rights in the Program not expressly granted under this | |
250 | Agreement are reserved.</p> | |
251 | ||
252 | <p>This Agreement is governed by the laws of the State of New York and | |
253 | the intellectual property laws of the United States of America. No party | |
254 | to this Agreement will bring a legal action under this Agreement more | |
255 | than one year after the cause of action arose. Each party waives its | |
256 | rights to a jury trial in any resulting litigation.</p> | |
257 | ||
258 | </body> | |
259 | ||
260 | </html> |
0 | <?xml version="1.0" encoding="ISO-8859-1" ?> | |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
2 | <html xmlns="http://www.w3.org/1999/xhtml"> | |
3 | ||
4 | <head> | |
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> | |
6 | <title>Eclipse Public License - Version 1.0</title> | |
7 | <style type="text/css"> | |
8 | body { | |
9 | size: 8.5in 11.0in; | |
10 | margin: 0.25in 0.5in 0.25in 0.5in; | |
11 | tab-interval: 0.5in; | |
12 | } | |
13 | p { | |
14 | margin-left: auto; | |
15 | margin-top: 0.5em; | |
16 | margin-bottom: 0.5em; | |
17 | } | |
18 | p.list { | |
19 | margin-left: 0.5in; | |
20 | margin-top: 0.05em; | |
21 | margin-bottom: 0.05em; | |
22 | } | |
23 | </style> | |
24 | ||
25 | </head> | |
26 | ||
27 | <body lang="EN-US"> | |
28 | ||
29 | <h2>Eclipse Public License - v 1.0</h2> | |
30 | ||
31 | <p>THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE | |
32 | PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR | |
33 | DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS | |
34 | AGREEMENT.</p> | |
35 | ||
36 | <p><b>1. DEFINITIONS</b></p> | |
37 | ||
38 | <p>"Contribution" means:</p> | |
39 | ||
40 | <p class="list">a) in the case of the initial Contributor, the initial | |
41 | code and documentation distributed under this Agreement, and</p> | |
42 | <p class="list">b) in the case of each subsequent Contributor:</p> | |
43 | <p class="list">i) changes to the Program, and</p> | |
44 | <p class="list">ii) additions to the Program;</p> | |
45 | <p class="list">where such changes and/or additions to the Program | |
46 | originate from and are distributed by that particular Contributor. A | |
47 | Contribution 'originates' from a Contributor if it was added to the | |
48 | Program by such Contributor itself or anyone acting on such | |
49 | Contributor's behalf. Contributions do not include additions to the | |
50 | Program which: (i) are separate modules of software distributed in | |
51 | conjunction with the Program under their own license agreement, and (ii) | |
52 | are not derivative works of the Program.</p> | |
53 | ||
54 | <p>"Contributor" means any person or entity that distributes | |
55 | the Program.</p> | |
56 | ||
57 | <p>"Licensed Patents" mean patent claims licensable by a | |
58 | Contributor which are necessarily infringed by the use or sale of its | |
59 | Contribution alone or when combined with the Program.</p> | |
60 | ||
61 | <p>"Program" means the Contributions distributed in accordance | |
62 | with this Agreement.</p> | |
63 | ||
64 | <p>"Recipient" means anyone who receives the Program under | |
65 | this Agreement, including all Contributors.</p> | |
66 | ||
67 | <p><b>2. GRANT OF RIGHTS</b></p> | |
68 | ||
69 | <p class="list">a) Subject to the terms of this Agreement, each | |
70 | Contributor hereby grants Recipient a non-exclusive, worldwide, | |
71 | royalty-free copyright license to reproduce, prepare derivative works | |
72 | of, publicly display, publicly perform, distribute and sublicense the | |
73 | Contribution of such Contributor, if any, and such derivative works, in | |
74 | source code and object code form.</p> | |
75 | ||
76 | <p class="list">b) Subject to the terms of this Agreement, each | |
77 | Contributor hereby grants Recipient a non-exclusive, worldwide, | |
78 | royalty-free patent license under Licensed Patents to make, use, sell, | |
79 | offer to sell, import and otherwise transfer the Contribution of such | |
80 | Contributor, if any, in source code and object code form. This patent | |
81 | license shall apply to the combination of the Contribution and the | |
82 | Program if, at the time the Contribution is added by the Contributor, | |
83 | such addition of the Contribution causes such combination to be covered | |
84 | by the Licensed Patents. The patent license shall not apply to any other | |
85 | combinations which include the Contribution. No hardware per se is | |
86 | licensed hereunder.</p> | |
87 | ||
88 | <p class="list">c) Recipient understands that although each Contributor | |
89 | grants the licenses to its Contributions set forth herein, no assurances | |
90 | are provided by any Contributor that the Program does not infringe the | |
91 | patent or other intellectual property rights of any other entity. Each | |
92 | Contributor disclaims any liability to Recipient for claims brought by | |
93 | any other entity based on infringement of intellectual property rights | |
94 | or otherwise. As a condition to exercising the rights and licenses | |
95 | granted hereunder, each Recipient hereby assumes sole responsibility to | |
96 | secure any other intellectual property rights needed, if any. For | |
97 | example, if a third party patent license is required to allow Recipient | |
98 | to distribute the Program, it is Recipient's responsibility to acquire | |
99 | that license before distributing the Program.</p> | |
100 | ||
101 | <p class="list">d) Each Contributor represents that to its knowledge it | |
102 | has sufficient copyright rights in its Contribution, if any, to grant | |
103 | the copyright license set forth in this Agreement.</p> | |
104 | ||
105 | <p><b>3. REQUIREMENTS</b></p> | |
106 | ||
107 | <p>A Contributor may choose to distribute the Program in object code | |
108 | form under its own license agreement, provided that:</p> | |
109 | ||
110 | <p class="list">a) it complies with the terms and conditions of this | |
111 | Agreement; and</p> | |
112 | ||
113 | <p class="list">b) its license agreement:</p> | |
114 | ||
115 | <p class="list">i) effectively disclaims on behalf of all Contributors | |
116 | all warranties and conditions, express and implied, including warranties | |
117 | or conditions of title and non-infringement, and implied warranties or | |
118 | conditions of merchantability and fitness for a particular purpose;</p> | |
119 | ||
120 | <p class="list">ii) effectively excludes on behalf of all Contributors | |
121 | all liability for damages, including direct, indirect, special, | |
122 | incidental and consequential damages, such as lost profits;</p> | |
123 | ||
124 | <p class="list">iii) states that any provisions which differ from this | |
125 | Agreement are offered by that Contributor alone and not by any other | |
126 | party; and</p> | |
127 | ||
128 | <p class="list">iv) states that source code for the Program is available | |
129 | from such Contributor, and informs licensees how to obtain it in a | |
130 | reasonable manner on or through a medium customarily used for software | |
131 | exchange.</p> | |
132 | ||
133 | <p>When the Program is made available in source code form:</p> | |
134 | ||
135 | <p class="list">a) it must be made available under this Agreement; and</p> | |
136 | ||
137 | <p class="list">b) a copy of this Agreement must be included with each | |
138 | copy of the Program.</p> | |
139 | ||
140 | <p>Contributors may not remove or alter any copyright notices contained | |
141 | within the Program.</p> | |
142 | ||
143 | <p>Each Contributor must identify itself as the originator of its | |
144 | Contribution, if any, in a manner that reasonably allows subsequent | |
145 | Recipients to identify the originator of the Contribution.</p> | |
146 | ||
147 | <p><b>4. COMMERCIAL DISTRIBUTION</b></p> | |
148 | ||
149 | <p>Commercial distributors of software may accept certain | |
150 | responsibilities with respect to end users, business partners and the | |
151 | like. While this license is intended to facilitate the commercial use of | |
152 | the Program, the Contributor who includes the Program in a commercial | |
153 | product offering should do so in a manner which does not create | |
154 | potential liability for other Contributors. Therefore, if a Contributor | |
155 | includes the Program in a commercial product offering, such Contributor | |
156 | ("Commercial Contributor") hereby agrees to defend and | |
157 | indemnify every other Contributor ("Indemnified Contributor") | |
158 | against any losses, damages and costs (collectively "Losses") | |
159 | arising from claims, lawsuits and other legal actions brought by a third | |
160 | party against the Indemnified Contributor to the extent caused by the | |
161 | acts or omissions of such Commercial Contributor in connection with its | |
162 | distribution of the Program in a commercial product offering. The | |
163 | obligations in this section do not apply to any claims or Losses | |
164 | relating to any actual or alleged intellectual property infringement. In | |
165 | order to qualify, an Indemnified Contributor must: a) promptly notify | |
166 | the Commercial Contributor in writing of such claim, and b) allow the | |
167 | Commercial Contributor to control, and cooperate with the Commercial | |
168 | Contributor in, the defense and any related settlement negotiations. The | |
169 | Indemnified Contributor may participate in any such claim at its own | |
170 | expense.</p> | |
171 | ||
172 | <p>For example, a Contributor might include the Program in a commercial | |
173 | product offering, Product X. That Contributor is then a Commercial | |
174 | Contributor. If that Commercial Contributor then makes performance | |
175 | claims, or offers warranties related to Product X, those performance | |
176 | claims and warranties are such Commercial Contributor's responsibility | |
177 | alone. Under this section, the Commercial Contributor would have to | |
178 | defend claims against the other Contributors related to those | |
179 | performance claims and warranties, and if a court requires any other | |
180 | Contributor to pay any damages as a result, the Commercial Contributor | |
181 | must pay those damages.</p> | |
182 | ||
183 | <p><b>5. NO WARRANTY</b></p> | |
184 | ||
185 | <p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS | |
186 | PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS | |
187 | OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, | |
188 | ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY | |
189 | OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely | |
190 | responsible for determining the appropriateness of using and | |
191 | distributing the Program and assumes all risks associated with its | |
192 | exercise of rights under this Agreement , including but not limited to | |
193 | the risks and costs of program errors, compliance with applicable laws, | |
194 | damage to or loss of data, programs or equipment, and unavailability or | |
195 | interruption of operations.</p> | |
196 | ||
197 | <p><b>6. DISCLAIMER OF LIABILITY</b></p> | |
198 | ||
199 | <p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT | |
200 | NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, | |
201 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING | |
202 | WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF | |
203 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
204 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR | |
205 | DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED | |
206 | HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</p> | |
207 | ||
208 | <p><b>7. GENERAL</b></p> | |
209 | ||
210 | <p>If any provision of this Agreement is invalid or unenforceable under | |
211 | applicable law, it shall not affect the validity or enforceability of | |
212 | the remainder of the terms of this Agreement, and without further action | |
213 | by the parties hereto, such provision shall be reformed to the minimum | |
214 | extent necessary to make such provision valid and enforceable.</p> | |
215 | ||
216 | <p>If Recipient institutes patent litigation against any entity | |
217 | (including a cross-claim or counterclaim in a lawsuit) alleging that the | |
218 | Program itself (excluding combinations of the Program with other | |
219 | software or hardware) infringes such Recipient's patent(s), then such | |
220 | Recipient's rights granted under Section 2(b) shall terminate as of the | |
221 | date such litigation is filed.</p> | |
222 | ||
223 | <p>All Recipient's rights under this Agreement shall terminate if it | |
224 | fails to comply with any of the material terms or conditions of this | |
225 | Agreement and does not cure such failure in a reasonable period of time | |
226 | after becoming aware of such noncompliance. If all Recipient's rights | |
227 | under this Agreement terminate, Recipient agrees to cease use and | |
228 | distribution of the Program as soon as reasonably practicable. However, | |
229 | Recipient's obligations under this Agreement and any licenses granted by | |
230 | Recipient relating to the Program shall continue and survive.</p> | |
231 | ||
232 | <p>Everyone is permitted to copy and distribute copies of this | |
233 | Agreement, but in order to avoid inconsistency the Agreement is | |
234 | copyrighted and may only be modified in the following manner. The | |
235 | Agreement Steward reserves the right to publish new versions (including | |
236 | revisions) of this Agreement from time to time. No one other than the | |
237 | Agreement Steward has the right to modify this Agreement. The Eclipse | |
238 | Foundation is the initial Agreement Steward. The Eclipse Foundation may | |
239 | assign the responsibility to serve as the Agreement Steward to a | |
240 | suitable separate entity. Each new version of the Agreement will be | |
241 | given a distinguishing version number. The Program (including | |
242 | Contributions) may always be distributed subject to the version of the | |
243 | Agreement under which it was received. In addition, after a new version | |
244 | of the Agreement is published, Contributor may elect to distribute the | |
245 | Program (including its Contributions) under the new version. Except as | |
246 | expressly stated in Sections 2(a) and 2(b) above, Recipient receives no | |
247 | rights or licenses to the intellectual property of any Contributor under | |
248 | this Agreement, whether expressly, by implication, estoppel or | |
249 | otherwise. All rights in the Program not expressly granted under this | |
250 | Agreement are reserved.</p> | |
251 | ||
252 | <p>This Agreement is governed by the laws of the State of New York and | |
253 | the intellectual property laws of the United States of America. No party | |
254 | to this Agreement will bring a legal action under this Agreement more | |
255 | than one year after the cause of action arose. Each party waives its | |
256 | rights to a jury trial in any resulting litigation.</p> | |
257 | ||
258 | </body> | |
259 | ||
260 | </html> |
2 | 2 | <groupId>org.clojure</groupId> |
3 | 3 | <artifactId>core.async</artifactId> |
4 | 4 | <!-- Don't set this manually! Call script/build/update_version --> |
5 | <version>0.3.443</version> | |
5 | <version>1.3.610</version> | |
6 | 6 | <packaging>jar</packaging> |
7 | 7 | <name>core.async</name> |
8 | 8 | <description>Facilities for async programming and communication in Clojure</description> |
19 | 19 | <parent> |
20 | 20 | <groupId>org.clojure</groupId> |
21 | 21 | <artifactId>pom.contrib</artifactId> |
22 | <version>0.2.2</version> | |
22 | <version>1.0.0</version> | |
23 | 23 | </parent> |
24 | 24 | |
25 | 25 | <scm> |
26 | 26 | <connection>scm:git:git://github.com/clojure/core.async.git</connection> |
27 | 27 | <developerConnection>scm:git:git@github.com:clojure/core.async.git</developerConnection> |
28 | 28 | <url>https://github.com/clojure/core.async</url> |
29 | <tag>core.async-0.3.443</tag> | |
29 | <tag>core.async-1.3.610</tag> | |
30 | 30 | </scm> |
31 | 31 | |
32 | 32 | <properties> |
33 | <clojure.version>1.7.0</clojure.version> | |
33 | <clojure.version>1.9.0</clojure.version> | |
34 | 34 | </properties> |
35 | 35 | |
36 | 36 | <dependencies> |
37 | 37 | <dependency> |
38 | 38 | <groupId>org.clojure</groupId> |
39 | 39 | <artifactId>clojurescript</artifactId> |
40 | <version>0.0-2311</version> | |
40 | <version>1.10.597</version> | |
41 | 41 | <scope>provided</scope> |
42 | 42 | </dependency> |
43 | 43 | <dependency> |
44 | 44 | <groupId>org.clojure</groupId> |
45 | 45 | <artifactId>tools.analyzer.jvm</artifactId> |
46 | <version>0.7.0</version> | |
46 | <version>1.1.0</version> | |
47 | 47 | </dependency> |
48 | 48 | </dependencies> |
49 | 49 | |
50 | 50 | <build> |
51 | <sourceDirectory>src/main/clojure</sourceDirectory> | |
51 | 52 | <plugins> |
52 | 53 | <plugin> |
53 | 54 | <groupId>org.codehaus.mojo</groupId> |
54 | 55 | <artifactId>versions-maven-plugin</artifactId> |
55 | <version>2.3</version> | |
56 | <version>2.7</version> | |
57 | </plugin> | |
58 | <plugin> | |
59 | <groupId>com.theoryinpractise</groupId> | |
60 | <artifactId>clojure-maven-plugin</artifactId> | |
61 | <version>1.7.1</version> | |
62 | <configuration> | |
63 | <temporaryOutputDirectory>true</temporaryOutputDirectory> | |
64 | </configuration> | |
65 | <executions> | |
66 | <execution> | |
67 | <id>clojure-compile</id> | |
68 | <phase>compile</phase> | |
69 | <goals> | |
70 | <goal>compile</goal> | |
71 | </goals> | |
72 | <configuration> | |
73 | <compileDeclaredNamespaceOnly>true</compileDeclaredNamespaceOnly> | |
74 | <namespaces> | |
75 | <namespace>!clojure.core.*</namespace> | |
76 | </namespaces> | |
77 | </configuration> | |
78 | </execution> | |
79 | </executions> | |
56 | 80 | </plugin> |
57 | 81 | </plugins> |
58 | 82 | </build> |
2 | 2 | :url "https://github.com/clojure/core.async" |
3 | 3 | :license {:name "Eclipse Public License" |
4 | 4 | :url "http://www.eclipse.org/legal/epl-v10.html"} |
5 | :parent [org.clojure/pom.contrib "0.1.2"] | |
6 | :dependencies [[org.clojure/clojure "1.7.0"] | |
7 | [org.clojure/tools.analyzer.jvm "0.7.0"] | |
8 | [org.clojure/clojurescript "1.7.170" :scope "provided"]] | |
5 | :parent [org.clojure/pom.contrib "1.0.0"] | |
6 | :dependencies [[org.clojure/clojure "1.9.0"] | |
7 | [org.clojure/tools.analyzer.jvm "1.0.0"] | |
8 | [org.clojure/clojurescript "1.10.597" :scope "provided"]] | |
9 | 9 | :global-vars {*warn-on-reflection* true} |
10 | 10 | :source-paths ["src/main/clojure"] |
11 | 11 | :test-paths ["src/test/clojure"] |
13 | 13 | :java-source-paths ["src/main/java"] |
14 | 14 | :profiles {:dev {:source-paths ["examples"]}} |
15 | 15 | |
16 | :plugins [[lein-cljsbuild "1.1.2"]] | |
16 | :plugins [[lein-cljsbuild "1.1.7"]] | |
17 | 17 | |
18 | 18 | :clean-targets ["tests.js" "tests.js.map" |
19 | 19 | "out" "out-simp" "out-simp-node" |
79 | 79 | (deftype FixedBuffer [buf n] |
80 | 80 | impl/Buffer |
81 | 81 | (full? [this] |
82 | (== (.-length buf) n)) | |
82 | (>= (.-length buf) n)) | |
83 | 83 | (remove! [this] |
84 | 84 | (.pop buf)) |
85 | 85 | (add!* [this itm] |
42 | 42 | (impl/close! this)) |
43 | 43 | impl/WritePort |
44 | 44 | (put! [this val ^not-native handler] |
45 | (assert (not (nil? val)) "Can't put nil in on a channel") | |
45 | (assert (not (nil? val)) "Can't put nil on a channel") | |
46 | 46 | ;; bug in CLJS compiler boolean inference - David |
47 | 47 | (let [^boolean closed closed] |
48 | 48 | (if (or closed (not ^boolean (impl/active? handler))) |
96 | 96 | (do |
97 | 97 | (if-let [take-cb (impl/commit handler)] |
98 | 98 | (let [val (impl/remove! buf) |
99 | [done? cbs] (when (pos? (.-length puts)) | |
99 | [done? cbs] (when (and (not (impl/full? buf)) (pos? (.-length puts))) | |
100 | 100 | (loop [cbs []] |
101 | 101 | (let [putter (.pop puts) |
102 | 102 | ^not-native put-handler (.-handler putter) |
0 | ;; Copyright (c) Rich Hickey and contributors. All rights reserved. | |
1 | ;; The use and distribution terms for this software are covered by the | |
2 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
3 | ;; which can be found in the file epl-v10.html at the root of this distribution. | |
4 | ;; By using this software in any fashion, you are agreeing to be bound by | |
5 | ;; the terms of this license. | |
6 | ;; You must not remove this notice, or any other, from this software. | |
7 | ||
0 | 8 | (ns cljs.core.async.impl.dispatch |
1 | 9 | (:require [cljs.core.async.impl.buffers :as buffers] |
2 | 10 | [goog.async.nextTick])) |
0 | ;; Copyright (c) Rich Hickey and contributors. All rights reserved. | |
1 | ;; The use and distribution terms for this software are covered by the | |
2 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
3 | ;; which can be found in the file epl-v10.html at the root of this distribution. | |
4 | ;; By using this software in any fashion, you are agreeing to be bound by | |
5 | ;; the terms of this license. | |
6 | ;; You must not remove this notice, or any other, from this software. | |
7 | ||
0 | 8 | (ns cljs.core.async.impl.ioc-helpers |
1 | 9 | (:require [cljs.core.async.impl.protocols :as impl]) |
2 | 10 | (:require-macros [cljs.core.async.impl.ioc-macros :as ioc])) |
64 | 72 | (impl/close! c) |
65 | 73 | c)) |
66 | 74 | |
67 | (defrecord ExceptionFrame [catch-block | |
68 | ^Class catch-exception | |
69 | finally-block | |
70 | continue-block | |
71 | prev]) | |
72 | 75 | |
73 | (defn add-exception-frame [state catch-block catch-exception finally-block continue-block] | |
74 | (ioc/aset-all! state | |
75 | EXCEPTION-FRAMES | |
76 | (->ExceptionFrame catch-block | |
77 | catch-exception | |
78 | finally-block | |
79 | continue-block | |
80 | (aget-object state EXCEPTION-FRAMES)))) | |
81 | ||
82 | (defn process-exception [state] | |
83 | (let [exception-frame (aget-object state EXCEPTION-FRAMES) | |
84 | catch-block (:catch-block exception-frame) | |
85 | catch-exception (:catch-exception exception-frame) | |
86 | exception (aget-object state CURRENT-EXCEPTION)] | |
87 | (cond | |
88 | (and exception | |
89 | (not exception-frame)) | |
90 | (throw exception) | |
91 | ||
92 | (and exception | |
93 | catch-block | |
94 | (or (= :default catch-exception) | |
95 | (instance? catch-exception exception))) | |
96 | (ioc/aset-all! state | |
97 | STATE-IDX | |
98 | catch-block | |
99 | VALUE-IDX | |
100 | exception | |
101 | CURRENT-EXCEPTION | |
102 | nil | |
103 | EXCEPTION-FRAMES | |
104 | (assoc exception-frame | |
105 | :catch-block nil | |
106 | :catch-exception nil)) | |
107 | ||
108 | ||
109 | (and exception | |
110 | (not catch-block) | |
111 | (not (:finally-block exception-frame))) | |
112 | ||
113 | (do (ioc/aset-all! state | |
114 | EXCEPTION-FRAMES | |
115 | (:prev exception-frame)) | |
116 | (recur state)) | |
117 | ||
118 | (and exception | |
119 | (not catch-block) | |
120 | (:finally-block exception-frame)) | |
121 | (ioc/aset-all! state | |
122 | STATE-IDX | |
123 | (:finally-block exception-frame) | |
124 | EXCEPTION-FRAMES | |
125 | (assoc exception-frame | |
126 | :finally-block nil)) | |
127 | ||
128 | (and (not exception) | |
129 | (:finally-block exception-frame)) | |
130 | (do (ioc/aset-all! state | |
131 | STATE-IDX | |
132 | (:finally-block exception-frame) | |
133 | EXCEPTION-FRAMES | |
134 | (assoc exception-frame | |
135 | :finally-block nil))) | |
136 | ||
137 | (and (not exception) | |
138 | (not (:finally-block exception-frame))) | |
139 | (do (ioc/aset-all! state | |
140 | STATE-IDX | |
141 | (:continue-block exception-frame) | |
142 | EXCEPTION-FRAMES | |
143 | (:prev exception-frame))) | |
144 | ||
145 | :else (throw (js/Error. "No matching clause"))))) |
344 | 344 | :recur))) |
345 | 345 | |
346 | 346 | |
347 | (defrecord Try [catch-block catch-exception finally-block continue-block] | |
347 | (defrecord PushTry [catch-block] | |
348 | 348 | IInstruction |
349 | 349 | (reads-from [this] []) |
350 | 350 | (writes-to [this] []) |
351 | (block-references [this] [catch-block finally-block continue-block]) | |
351 | (block-references [this] [catch-block]) | |
352 | 352 | IEmittableInstruction |
353 | 353 | (emit-instruction [this state-sym] |
354 | `[~'_ (cljs.core.async.impl.ioc-helpers/add-exception-frame ~state-sym | |
355 | ~catch-block | |
356 | ~catch-exception | |
357 | ~finally-block | |
358 | ~continue-block)])) | |
359 | ||
360 | (defrecord ProcessExceptionWithValue [value] | |
361 | IInstruction | |
362 | (reads-from [this] [value]) | |
354 | `[~'_ (aset-all! ~state-sym ~EXCEPTION-FRAMES (cons ~catch-block (aget ~state-sym ~EXCEPTION-FRAMES)))])) | |
355 | ||
356 | (defrecord PopTry [] | |
357 | IInstruction | |
358 | (reads-from [this] []) | |
363 | 359 | (writes-to [this] []) |
364 | 360 | (block-references [this] []) |
361 | IEmittableInstruction | |
362 | (emit-instruction [this state-sym] | |
363 | `[~'_ (aset-all! ~state-sym ~EXCEPTION-FRAMES (rest (aget ~state-sym ~EXCEPTION-FRAMES)))])) | |
364 | ||
365 | (defrecord CatchHandler [catches] | |
366 | IInstruction | |
367 | (reads-from [this] []) | |
368 | (writes-to [this] []) | |
369 | (block-references [this] (map first catches)) | |
365 | 370 | ITerminator |
366 | 371 | (terminate-block [this state-sym _] |
367 | `(do (aset-all! ~state-sym | |
368 | ~VALUE-IDX | |
369 | ~value) | |
370 | (cljs.core.async.impl.ioc-helpers/process-exception ~state-sym) | |
371 | :recur))) | |
372 | ||
373 | (defrecord EndCatchFinally [] | |
372 | (let [ex (gensym 'ex)] | |
373 | `(let [~ex (aget ~state-sym ~VALUE-IDX)] | |
374 | (aset-all! ~state-sym ~CURRENT-EXCEPTION ~ex) | |
375 | (cond | |
376 | ~@(for [[handler-idx type] catches | |
377 | i [(if (= type :default) | |
378 | `true | |
379 | `(instance? ~type ~ex)) ` (aset-all! ~state-sym | |
380 | ~STATE-IDX ~handler-idx | |
381 | ~CURRENT-EXCEPTION nil)]] | |
382 | i) | |
383 | :else (throw ~ex)) | |
384 | :recur)))) | |
385 | ||
386 | (defrecord EndFinally [] | |
374 | 387 | IInstruction |
375 | 388 | (reads-from [this] []) |
376 | 389 | (writes-to [this] []) |
377 | 390 | (block-references [this] []) |
378 | ITerminator | |
379 | (terminate-block [this state-sym _] | |
380 | `(do (cljs.core.async.impl.ioc-helpers/process-exception ~state-sym) | |
381 | :recur))) | |
382 | ||
391 | IEmittableInstruction | |
392 | (emit-instruction [this state-sym] | |
393 | `[~'_ (when-let [e# (aget ~state-sym ~CURRENT-EXCEPTION)] | |
394 | (throw e#))])) | |
383 | 395 | |
384 | 396 | |
385 | 397 | ;; Dispatch clojure forms based on data type |
411 | 423 | inst-id (add-instruction (->Call args-ids))] |
412 | 424 | inst-id)) |
413 | 425 | |
426 | ||
427 | (defn local-init-to-ssa [init] | |
428 | (gen-plan | |
429 | [bind-id (item-to-ssa init) | |
430 | bind-id (if (::global (meta bind-id)) | |
431 | (add-instruction (->Const bind-id)) | |
432 | (fn [p] [bind-id p]))] | |
433 | bind-id)) | |
434 | ||
414 | 435 | (defn let-binding-to-ssa |
415 | 436 | [[sym bind]] |
416 | 437 | (gen-plan |
417 | [bind-id (item-to-ssa bind) | |
438 | [bind-id (local-init-to-ssa bind) | |
418 | 439 | _ (push-alter-binding :locals assoc sym bind-id)] |
419 | 440 | bind-id)) |
420 | 441 | |
438 | 459 | [local-val-ids (all (map ; parallel bind |
439 | 460 | (fn [sym init] |
440 | 461 | (gen-plan |
441 | [itm-id (item-to-ssa init) | |
462 | [itm-id (local-init-to-ssa init) | |
442 | 463 | _ (push-alter-binding :locals assoc sym itm-id)] |
443 | 464 | itm-id)) |
444 | 465 | syms |
550 | 571 | ret-id (add-instruction (->Dot target-id method args-ids))] |
551 | 572 | ret-id))) |
552 | 573 | |
574 | (defn destructure-try | |
575 | [body] | |
576 | (reduce | |
577 | (fn [accum form] | |
578 | (case (:state accum) | |
579 | :body (cond | |
580 | (and (seq? form) (= (first form) 'catch)) (-> accum | |
581 | (assoc :state :catch) | |
582 | (update-in [:catches] conj form)) | |
583 | (and (seq? form) (= (first form) 'finally)) (-> accum | |
584 | (assoc :state :finally) | |
585 | (assoc :finally form)) | |
586 | :else (update-in accum [:body] conj form)) | |
587 | :catch (cond | |
588 | (and (seq? form) (= (first form) 'catch)) (-> accum | |
589 | (assoc :state :catch) | |
590 | (update-in [:catches] conj form)) | |
591 | (and (seq? form) (= (first form) 'finally)) (-> accum | |
592 | (assoc :state :finally) | |
593 | (assoc :finally form)) | |
594 | :else (throw (Exception. "Only catch or finally clause can follow catch in try expression"))) | |
595 | :finally (throw (Exception. "finally clause must be last in try expression")))) | |
596 | {:state :body | |
597 | :body [] | |
598 | :catches [] | |
599 | :finally nil} | |
600 | body)) | |
601 | ||
553 | 602 | (defmethod sexpr-to-ssa 'try |
554 | 603 | [[_ & body]] |
555 | (let [finally-fn (every-pred seq? (comp (partial = 'finally) first)) | |
556 | catch-fn (every-pred seq? (comp (partial = 'catch) first)) | |
557 | finally (next (first (filter finally-fn body))) | |
558 | body (remove finally-fn body) | |
559 | catch (next (first (filter catch-fn body))) | |
560 | [ex ex-bind & catch-body] catch | |
561 | body (remove catch-fn body)] | |
604 | (let [{:keys [body catches finally] :as m} (destructure-try body)] | |
562 | 605 | (gen-plan |
563 | [end-blk (add-block) | |
606 | [body-block (add-block) | |
607 | exit-block (add-block) | |
564 | 608 | finally-blk (if finally |
565 | 609 | (gen-plan |
566 | 610 | [cur-blk (get-block) |
567 | blk (add-block) | |
568 | _ (set-block blk) | |
569 | value-id (add-instruction (->Const ::value)) | |
570 | _ (all (map item-to-ssa finally)) | |
571 | _ (add-instruction (->EndCatchFinally)) | |
611 | finally-blk (add-block) | |
612 | _ (set-block finally-blk) | |
613 | _ (add-instruction (->PopTry)) | |
614 | result-id (add-instruction (->Const ::value)) | |
615 | _ (item-to-ssa (cons 'do (rest finally))) | |
616 | ;; rethrow exception on exception path | |
617 | _ (add-instruction (->EndFinally)) | |
618 | _ (add-instruction (->Jmp result-id exit-block)) | |
572 | 619 | _ (set-block cur-blk)] |
573 | blk) | |
574 | (no-op)) | |
575 | catch-blk (if catch | |
576 | (gen-plan | |
577 | [cur-blk (get-block) | |
578 | blk (add-block) | |
579 | _ (set-block blk) | |
580 | ex-id (add-instruction (->Const ::value)) | |
581 | _ (push-alter-binding :locals assoc ex-bind ex-id) | |
582 | ids (all (map item-to-ssa catch-body)) | |
583 | _ (add-instruction (->ProcessExceptionWithValue (last ids))) | |
584 | _ (pop-binding :locals) | |
585 | _ (set-block cur-blk) | |
586 | _ (push-alter-binding :catch (fnil conj []) [ex blk])] | |
587 | blk) | |
588 | (no-op)) | |
589 | body-blk (add-block) | |
590 | _ (add-instruction (->Jmp nil body-blk)) | |
591 | _ (set-block body-blk) | |
592 | _ (add-instruction (->Try catch-blk ex finally-blk end-blk)) | |
593 | ids (all (map item-to-ssa body)) | |
594 | _ (if catch | |
595 | (pop-binding :catch) | |
620 | finally-blk) | |
621 | (gen-plan [] exit-block)) | |
622 | catch-blocks (all | |
623 | (for [[_ ex ex-bind & catch-body] catches] | |
624 | (gen-plan | |
625 | [cur-blk (get-block) | |
626 | catch-blk (add-block) | |
627 | _ (set-block catch-blk) | |
628 | ex-id (add-instruction (->Const ::value)) | |
629 | ;; TODO: type hint ex-bind? | |
630 | _ (push-alter-binding :locals assoc ex-bind ex-id) | |
631 | result-id (item-to-ssa (cons 'do catch-body)) | |
632 | ;; if there is a finally, jump to it after | |
633 | ;; handling the exception, if not jump to exit | |
634 | _ (add-instruction (->Jmp result-id finally-blk)) | |
635 | _ (pop-binding :locals) | |
636 | _ (set-block cur-blk)] | |
637 | [catch-blk ex]))) | |
638 | catch-handler-block (add-block) | |
639 | cur-blk (get-block) | |
640 | _ (set-block catch-handler-block) | |
641 | _ (add-instruction (->PopTry)) | |
642 | _ (add-instruction (->CatchHandler catch-blocks)) | |
643 | _ (set-block cur-blk) | |
644 | _ (add-instruction (->Jmp nil body-block)) | |
645 | _ (set-block body-block) | |
646 | ;; the finally gets pushed on to the exception handler stack, so | |
647 | ;; it will be executed if there is an exception | |
648 | _ (if finally | |
649 | (add-instruction (->PushTry finally-blk)) | |
596 | 650 | (no-op)) |
597 | _ (add-instruction (->ProcessExceptionWithValue (last ids))) | |
598 | _ (set-block end-blk) | |
651 | _ (add-instruction (->PushTry catch-handler-block)) | |
652 | body (item-to-ssa (cons 'do body)) | |
653 | _ (add-instruction (->PopTry)) | |
654 | ;; if the body finishes executing normally, jump to the finally | |
655 | ;; block, if it exists | |
656 | _ (add-instruction (->Jmp body finally-blk)) | |
657 | _ (set-block exit-block) | |
599 | 658 | ret (add-instruction (->Const ::value))] |
600 | 659 | ret))) |
601 | 660 | |
722 | 781 | (fn [p] |
723 | 782 | [(locals x) p]) |
724 | 783 | (fn [p] |
725 | [x p]) | |
726 | #_(add-instruction (->Const x)))] | |
784 | [(vary-meta x assoc ::global true) p]))] | |
727 | 785 | inst-id)) |
728 | 786 | |
729 | 787 | (defmethod -item-to-ssa :map |
857 | 915 | (if (cljs.core/keyword-identical? result# :recur) |
858 | 916 | (recur) |
859 | 917 | result#))) |
860 | (catch js/Object ex# | |
861 | (aset-all! ~state-sym ~CURRENT-EXCEPTION ex#) | |
862 | (cljs.core.async.impl.ioc-helpers/process-exception ~state-sym) | |
918 | (catch :default ex# | |
919 | (aset-all! ~state-sym ~VALUE-IDX ex#) | |
920 | (if (seq (aget ~state-sym ~EXCEPTION-FRAMES)) | |
921 | (aset-all! ~state-sym | |
922 | ~STATE-IDX (first (aget ~state-sym ~EXCEPTION-FRAMES))) | |
923 | (throw ex#)) | |
863 | 924 | :recur))] |
864 | 925 | (if (cljs.core/keyword-identical? ret-value# :recur) |
865 | 926 | (recur ~state-sym) |
45 | 45 | ([x k level update] |
46 | 46 | (if-not (neg? level) |
47 | 47 | (let [x (loop [x x] |
48 | (if-let [x' (aget (.-forward x) level)] | |
48 | (if-let [x' (when (< level (alength (.-forward x))) | |
49 | (aget (.-forward x) level))] | |
49 | 50 | (if (< (.-key x') k) |
50 | 51 | (recur x') |
51 | 52 | x) |
75 | 76 | (when (<= i level) |
76 | 77 | (let [links (.-forward (aget update i))] |
77 | 78 | (aset (.-forward x) i (aget links i)) |
78 | (aset links i x))))))))) | |
79 | (aset links i x)) | |
80 | (recur (inc i))))))))) | |
79 | 81 | |
80 | 82 | (remove [coll k] |
81 | 83 | (let [update (make-array MAX_LEVEL) |
82 | 84 | x (least-greater-node header k level update) |
83 | x (aget (.-forward x) 0)] | |
85 | x (when-not (zero? (alength (.-forward x))) | |
86 | (aget (.-forward x) 0))] | |
84 | 87 | (when (and (not (nil? x)) (== (.-key x) k)) |
85 | 88 | (loop [i 0] |
86 | 89 | (when (<= i level) |
87 | 90 | (let [links (.-forward (aget update i))] |
88 | (if (identical? (aget links i) x) | |
91 | (if (identical? x (when (< i (alength links)) | |
92 | (aget links i))) | |
89 | 93 | (do |
90 | 94 | (aset links i (aget (.-forward x) i)) |
91 | 95 | (recur (inc i))) |
92 | 96 | (recur (inc i)))))) |
93 | (while (and (> level 0) | |
97 | (while (and (< 0 level (alength (.-forward header))) | |
94 | 98 | (nil? (aget (.-forward header) level))) |
95 | 99 | (set! level (dec level)))))) |
96 | 100 | |
98 | 102 | (loop [x header level level] |
99 | 103 | (if-not (neg? level) |
100 | 104 | (let [nx (loop [x x] |
101 | (let [x' (aget (.-forward x) level)] | |
102 | (when-not (nil? x') | |
103 | (if (>= (.-key x') k) | |
104 | x' | |
105 | (recur x')))))] | |
106 | (if-not (nil? nx) | |
105 | (let [x' (when (< level (alength (.-forward x))) | |
106 | (aget (.-forward x) level))] | |
107 | (if-not (nil? x') | |
108 | (if (> (.-key x') k) | |
109 | x | |
110 | (recur x')) | |
111 | (when (zero? level) | |
112 | x))))] | |
113 | (if nx | |
107 | 114 | (recur nx (dec level)) |
108 | 115 | (recur x (dec level)))) |
109 | (when-not (identical? x header) | |
110 | x)))) | |
111 | ||
116 | (if (= (.-key x) k) | |
117 | x | |
118 | (aget (.-forward x) 0))))) | |
119 | ||
112 | 120 | (floorEntry [coll k] |
113 | 121 | (loop [x header level level] |
114 | 122 | (if-not (neg? level) |
115 | 123 | (let [nx (loop [x x] |
116 | (let [x' (aget (.-forward x) level)] | |
124 | (let [x' (when (< level (alength (.-forward x))) | |
125 | (aget (.-forward x) level))] | |
117 | 126 | (if-not (nil? x') |
118 | 127 | (if (> (.-key x') k) |
119 | 128 | x |
163 | 172 | (impl/close! timeout-channel)) |
164 | 173 | msecs) |
165 | 174 | timeout-channel)))) |
166 |
0 | ;; Copyright (c) Rich Hickey and contributors. All rights reserved. | |
1 | ;; The use and distribution terms for this software are covered by the | |
2 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
3 | ;; which can be found in the file epl-v10.html at the root of this distribution. | |
4 | ;; By using this software in any fashion, you are agreeing to be bound by | |
5 | ;; the terms of this license. | |
6 | ;; You must not remove this notice, or any other, from this software. | |
7 | ||
8 | (ns cljs.core.async.interop) | |
9 | ||
10 | (defmacro <p! | |
11 | "EXPERIMENTAL: Takes the value of a promise resolution. The value of a rejected promise | |
12 | will be thrown wrapped in a instance of ExceptionInfo, acessible via ex-cause." | |
13 | [exp] | |
14 | `(let [v# (cljs.core.async/<! (cljs.core.async.interop/p->c ~exp))] | |
15 | (if (and | |
16 | (instance? cljs.core/ExceptionInfo v#) | |
17 | (= (:error (ex-data v#)) :promise-error)) | |
18 | (throw v#) | |
19 | v#))) |
0 | ;; Copyright (c) Rich Hickey and contributors. All rights reserved. | |
1 | ;; The use and distribution terms for this software are covered by the | |
2 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
3 | ;; which can be found in the file epl-v10.html at the root of this distribution. | |
4 | ;; By using this software in any fashion, you are agreeing to be bound by | |
5 | ;; the terms of this license. | |
6 | ;; You must not remove this notice, or any other, from this software. | |
7 | ||
8 | (ns cljs.core.async.interop | |
9 | (:require-macros [cljs.core.async.interop]) | |
10 | (:require [cljs.core.async :as async])) | |
11 | ||
12 | (defn p->c | |
13 | "EXPERIMENTAL: Puts the promise resolution into a promise-chan and returns it. | |
14 | The value of a rejected promise will be wrapped in a instance of | |
15 | ExceptionInfo, acessible via ex-cause." | |
16 | [p] | |
17 | (let [c (async/promise-chan)] | |
18 | (.then p | |
19 | (fn [res] | |
20 | (if (nil? res) | |
21 | (async/close! c) | |
22 | (async/put! c res))) | |
23 | (fn [err] | |
24 | (async/put! c | |
25 | (ex-info "Promise error" | |
26 | {:error :promise-error} | |
27 | err)))) | |
28 | c)) |
0 | ;; Copyright (c) Rich Hickey and contributors. All rights reserved. | |
1 | ;; The use and distribution terms for this software are covered by the | |
2 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
3 | ;; which can be found in the file epl-v10.html at the root of this distribution. | |
4 | ;; By using this software in any fashion, you are agreeing to be bound by | |
5 | ;; the terms of this license. | |
6 | ;; You must not remove this notice, or any other, from this software. | |
7 | ||
0 | 8 | (ns cljs.core.async.macros |
1 | (:require [cljs.core.async.impl.ioc-macros :as ioc])) | |
9 | (:require [cljs.core.async :as async])) | |
2 | 10 | |
3 | (defmacro go | |
4 | "Asynchronously executes the body, returning immediately to the | |
5 | calling thread. Additionally, any visible calls to <!, >! and alt!/alts! | |
6 | channel operations within the body will block (if necessary) by | |
7 | 'parking' the calling thread rather than tying up an OS thread (or | |
8 | the only JS thread when in ClojureScript). Upon completion of the | |
9 | operation, the body will be resumed. | |
11 | ;; Idea taken from Potemkin: https://github.com/ztellman/potemkin/blob/master/src/potemkin/namespaces.clj | |
12 | (defn- setup-macro-shim | |
13 | [src dst] | |
14 | (alter-meta! dst merge (dissoc (meta src) :name)) | |
15 | (.setMacro dst) | |
16 | (add-watch src dst | |
17 | (fn [_ src old new] | |
18 | (alter-var-root dst (constantly @src)) | |
19 | (alter-meta! dst merge (dissoc (meta src) :name))))) | |
10 | 20 | |
11 | Returns a channel which will receive the result of the body when | |
12 | completed" | |
13 | [& body] | |
14 | `(let [c# (cljs.core.async/chan 1)] | |
15 | (cljs.core.async.impl.dispatch/run | |
16 | (fn [] | |
17 | (let [f# ~(ioc/state-machine body 1 &env ioc/async-custom-terminators) | |
18 | state# (-> (f#) | |
19 | (ioc/aset-all! cljs.core.async.impl.ioc-helpers/USER-START-IDX c#))] | |
20 | (cljs.core.async.impl.ioc-helpers/run-state-machine-wrapped state#)))) | |
21 | c#)) | |
21 | (def go #'async/go) | |
22 | (setup-macro-shim #'async/go #'go) | |
22 | 23 | |
24 | (def go-loop #'async/go-loop) | |
25 | (setup-macro-shim #'async/go-loop #'go-loop) | |
23 | 26 | |
24 | (defn do-alt [alts clauses] | |
25 | (assert (even? (count clauses)) "unbalanced clauses") | |
26 | (let [clauses (partition 2 clauses) | |
27 | opt? #(keyword? (first %)) | |
28 | opts (filter opt? clauses) | |
29 | clauses (remove opt? clauses) | |
30 | [clauses bindings] | |
31 | (reduce | |
32 | (fn [[clauses bindings] [ports expr]] | |
33 | (let [ports (if (vector? ports) ports [ports]) | |
34 | [ports bindings] | |
35 | (reduce | |
36 | (fn [[ports bindings] port] | |
37 | (if (vector? port) | |
38 | (let [[port val] port | |
39 | gp (gensym) | |
40 | gv (gensym)] | |
41 | [(conj ports [gp gv]) (conj bindings [gp port] [gv val])]) | |
42 | (let [gp (gensym)] | |
43 | [(conj ports gp) (conj bindings [gp port])]))) | |
44 | [[] bindings] ports)] | |
45 | [(conj clauses [ports expr]) bindings])) | |
46 | [[] []] clauses) | |
47 | gch (gensym "ch") | |
48 | gret (gensym "ret")] | |
49 | `(let [~@(mapcat identity bindings) | |
50 | [val# ~gch :as ~gret] (~alts [~@(apply concat (map first clauses))] ~@(apply concat opts))] | |
51 | (cond | |
52 | ~@(mapcat (fn [[ports expr]] | |
53 | [`(or ~@(map (fn [port] | |
54 | `(= ~gch ~(if (vector? port) (first port) port))) | |
55 | ports)) | |
56 | (if (and (seq? expr) (vector? (first expr))) | |
57 | `(let [~(first expr) ~gret] ~@(rest expr)) | |
58 | expr)]) | |
59 | clauses) | |
60 | (= ~gch :default) val#)))) | |
61 | ||
62 | (defmacro alt! | |
63 | "Makes a single choice between one of several channel operations, | |
64 | as if by alts!, returning the value of the result expr corresponding | |
65 | to the operation completed. Must be called inside a (go ...) block. | |
66 | ||
67 | Each clause takes the form of: | |
68 | ||
69 | channel-op[s] result-expr | |
70 | ||
71 | where channel-ops is one of: | |
72 | ||
73 | take-port - a single port to take | |
74 | [take-port | [put-port put-val] ...] - a vector of ports as per alts! | |
75 | :default | :priority - an option for alts! | |
76 | ||
77 | and result-expr is either a list beginning with a vector, whereupon that | |
78 | vector will be treated as a binding for the [val port] return of the | |
79 | operation, else any other expression. | |
80 | ||
81 | (alt! | |
82 | [c t] ([val ch] (foo ch val)) | |
83 | x ([v] v) | |
84 | [[out val]] :wrote | |
85 | :default 42) | |
86 | ||
87 | Each option may appear at most once. The choice and parking | |
88 | characteristics are those of alts!." | |
89 | ||
90 | [& clauses] | |
91 | (do-alt 'alts! clauses)) | |
92 | ||
93 | ||
94 | (defmacro go-loop | |
95 | "Like (go (loop ...))" | |
96 | [bindings & body] | |
97 | `(go (loop ~bindings ~@body))) | |
27 | (def alt! #'async/alt!) | |
28 | (setup-macro-shim #'async/alt! #'alt!) |
0 | ;; Copyright (c) Rich Hickey and contributors. All rights reserved. | |
1 | ;; The use and distribution terms for this software are covered by the | |
2 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
3 | ;; which can be found in the file epl-v10.html at the root of this distribution. | |
4 | ;; By using this software in any fashion, you are agreeing to be bound by | |
5 | ;; the terms of this license. | |
6 | ;; You must not remove this notice, or any other, from this software. | |
7 | ||
8 | (ns cljs.core.async | |
9 | (:require [cljs.core.async.impl.ioc-macros :as ioc])) | |
10 | ||
11 | (defmacro go | |
12 | "Asynchronously executes the body, returning immediately to the | |
13 | calling thread. Additionally, any visible calls to <!, >! and alt!/alts! | |
14 | channel operations within the body will block (if necessary) by | |
15 | 'parking' the calling thread rather than tying up an OS thread (or | |
16 | the only JS thread when in ClojureScript). Upon completion of the | |
17 | operation, the body will be resumed. | |
18 | ||
19 | Returns a channel which will receive the result of the body when | |
20 | completed" | |
21 | [& body] | |
22 | `(let [c# (cljs.core.async/chan 1)] | |
23 | (cljs.core.async.impl.dispatch/run | |
24 | (fn [] | |
25 | (let [f# ~(ioc/state-machine body 1 &env ioc/async-custom-terminators) | |
26 | state# (-> (f#) | |
27 | (ioc/aset-all! cljs.core.async.impl.ioc-helpers/USER-START-IDX c#))] | |
28 | (cljs.core.async.impl.ioc-helpers/run-state-machine-wrapped state#)))) | |
29 | c#)) | |
30 | ||
31 | ||
32 | (defn do-alt [alts clauses] | |
33 | (assert (even? (count clauses)) "unbalanced clauses") | |
34 | (let [clauses (partition 2 clauses) | |
35 | opt? #(keyword? (first %)) | |
36 | opts (filter opt? clauses) | |
37 | clauses (remove opt? clauses) | |
38 | [clauses bindings] | |
39 | (reduce | |
40 | (fn [[clauses bindings] [ports expr]] | |
41 | (let [ports (if (vector? ports) ports [ports]) | |
42 | [ports bindings] | |
43 | (reduce | |
44 | (fn [[ports bindings] port] | |
45 | (if (vector? port) | |
46 | (let [[port val] port | |
47 | gp (gensym) | |
48 | gv (gensym)] | |
49 | [(conj ports [gp gv]) (conj bindings [gp port] [gv val])]) | |
50 | (let [gp (gensym)] | |
51 | [(conj ports gp) (conj bindings [gp port])]))) | |
52 | [[] bindings] ports)] | |
53 | [(conj clauses [ports expr]) bindings])) | |
54 | [[] []] clauses) | |
55 | gch (gensym "ch") | |
56 | gret (gensym "ret")] | |
57 | `(let [~@(mapcat identity bindings) | |
58 | [val# ~gch :as ~gret] (~alts [~@(apply concat (map first clauses))] ~@(apply concat opts))] | |
59 | (cond | |
60 | ~@(mapcat (fn [[ports expr]] | |
61 | [`(or ~@(map (fn [port] | |
62 | `(= ~gch ~(if (vector? port) (first port) port))) | |
63 | ports)) | |
64 | (if (and (seq? expr) (vector? (first expr))) | |
65 | `(let [~(first expr) ~gret] ~@(rest expr)) | |
66 | expr)]) | |
67 | clauses) | |
68 | (= ~gch :default) val#)))) | |
69 | ||
70 | (defmacro alt! | |
71 | "Makes a single choice between one of several channel operations, | |
72 | as if by alts!, returning the value of the result expr corresponding | |
73 | to the operation completed. Must be called inside a (go ...) block. | |
74 | ||
75 | Each clause takes the form of: | |
76 | ||
77 | channel-op[s] result-expr | |
78 | ||
79 | where channel-ops is one of: | |
80 | ||
81 | take-port - a single port to take | |
82 | [take-port | [put-port put-val] ...] - a vector of ports as per alts! | |
83 | :default | :priority - an option for alts! | |
84 | ||
85 | and result-expr is either a list beginning with a vector, whereupon that | |
86 | vector will be treated as a binding for the [val port] return of the | |
87 | operation, else any other expression. | |
88 | ||
89 | (alt! | |
90 | [c t] ([val ch] (foo ch val)) | |
91 | x ([v] v) | |
92 | [[out val]] :wrote | |
93 | :default 42) | |
94 | ||
95 | Each option may appear at most once. The choice and parking | |
96 | characteristics are those of alts!." | |
97 | ||
98 | [& clauses] | |
99 | (do-alt 'alts! clauses)) | |
100 | ||
101 | ||
102 | (defmacro go-loop | |
103 | "Like (go (loop ...))" | |
104 | [bindings & body] | |
105 | `(go (loop ~bindings ~@body))) |
0 | ;; Copyright (c) Rich Hickey and contributors. All rights reserved. | |
1 | ;; The use and distribution terms for this software are covered by the | |
2 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
3 | ;; which can be found in the file epl-v10.html at the root of this distribution. | |
4 | ;; By using this software in any fashion, you are agreeing to be bound by | |
5 | ;; the terms of this license. | |
6 | ;; You must not remove this notice, or any other, from this software. | |
7 | ||
0 | 8 | (ns cljs.core.async |
1 | 9 | (:refer-clojure :exclude [reduce transduce into merge map take partition partition-by]) |
2 | 10 | (:require [cljs.core.async.impl.protocols :as impl] |
4 | 12 | [cljs.core.async.impl.buffers :as buffers] |
5 | 13 | [cljs.core.async.impl.timers :as timers] |
6 | 14 | [cljs.core.async.impl.dispatch :as dispatch] |
7 | [cljs.core.async.impl.ioc-helpers :as helpers]) | |
15 | [cljs.core.async.impl.ioc-helpers :as helpers] | |
16 | [goog.array :as garray]) | |
8 | 17 | (:require-macros [cljs.core.async.impl.ioc-macros :as ioc] |
9 | [cljs.core.async.macros :refer [go go-loop]])) | |
18 | [cljs.core.async :refer [go go-loop]])) | |
10 | 19 | |
11 | 20 | (defn- fn-handler |
12 | 21 | ([f] (fn-handler f true)) |
112 | 121 | (throw (js/Error. ">! used not in (go ...) block"))) |
113 | 122 | |
114 | 123 | (defn put! |
115 | "Asynchronously puts a val into port, calling fn0 (if supplied) when | |
124 | "Asynchronously puts a val into port, calling fn1 (if supplied) when | |
116 | 125 | complete. nil values are not allowed. Will throw if closed. If |
117 | 126 | on-caller? (default true) is true, and the put is immediately |
118 | accepted, will call fn0 on calling thread. Returns nil." | |
127 | accepted, will call fn1 on calling thread. Returns nil." | |
119 | 128 | ([port val] |
120 | 129 | (if-let [ret (impl/put! port val fhnop)] |
121 | 130 | @ret |
139 | 148 | [n] |
140 | 149 | (let [a (make-array n)] |
141 | 150 | (dotimes [x n] |
142 | (aset a x 0)) | |
143 | (loop [i 1] | |
144 | (if (= i n) | |
145 | a | |
146 | (do | |
147 | (let [j (rand-int i)] | |
148 | (aset a i (aget a j)) | |
149 | (aset a j i) | |
150 | (recur (inc i)))))))) | |
151 | (aset a x x)) | |
152 | (garray/shuffle a) | |
153 | a)) | |
151 | 154 | |
152 | 155 | (defn- alt-flag [] |
153 | 156 | (let [flag (atom true)] |
171 | 174 | (defn do-alts |
172 | 175 | "returns derefable [val port] if immediate, nil if enqueued" |
173 | 176 | [fret ports opts] |
177 | (assert (pos? (count ports)) "alts must have at least one channel operation") | |
174 | 178 | (let [flag (alt-flag) |
175 | 179 | n (count ports) |
176 | 180 | idxs (random-array n) |
381 | 385 | (let [ret (<! (reduce f init ch))] |
382 | 386 | (f ret))))) |
383 | 387 | |
384 | (defn onto-chan | |
388 | (defn onto-chan! | |
385 | 389 | "Puts the contents of coll into the supplied channel. |
386 | 390 | |
387 | 391 | By default the channel will be closed after the items are copied, |
388 | 392 | but can be determined by the close? parameter. |
389 | 393 | |
390 | 394 | Returns a channel which will close after the items are copied." |
391 | ([ch coll] (onto-chan ch coll true)) | |
395 | ([ch coll] (onto-chan! ch coll true)) | |
392 | 396 | ([ch coll close?] |
393 | 397 | (go-loop [vs (seq coll)] |
394 | 398 | (if (and vs (>! ch (first vs))) |
397 | 401 | (close! ch)))))) |
398 | 402 | |
399 | 403 | |
400 | (defn to-chan | |
404 | (defn to-chan! | |
401 | 405 | "Creates and returns a channel which contains the contents of coll, |
402 | 406 | closing when exhausted." |
403 | 407 | [coll] |
404 | 408 | (let [ch (chan (bounded-count 100 coll))] |
405 | (onto-chan ch coll) | |
409 | (onto-chan! ch coll) | |
406 | 410 | ch)) |
407 | 411 | |
412 | (defn onto-chan | |
413 | "Deprecated - use onto-chan!" | |
414 | {:deprecated "1.2"} | |
415 | ([ch coll] (onto-chan! ch coll true)) | |
416 | ([ch coll close?] (onto-chan! ch coll close?))) | |
417 | ||
418 | (defn to-chan | |
419 | "Deprecated - use to-chan!" | |
420 | {:deprecated "1.2"} | |
421 | [coll] | |
422 | (to-chan! coll)) | |
408 | 423 | |
409 | 424 | (defprotocol Mux |
410 | 425 | (muxch* [_])) |
449 | 464 | (reset! dctr (count chs)) |
450 | 465 | (doseq [c chs] |
451 | 466 | (when-not (put! c val done) |
452 | (done nil) | |
453 | 467 | (untap* m c))) |
454 | 468 | ;;wait for all |
455 | 469 | (when (seq chs) |
516 | 530 | solo-modes #{:mute :pause} |
517 | 531 | attrs (conj solo-modes :solo) |
518 | 532 | solo-mode (atom :mute) |
519 | change (chan) | |
533 | change (chan (sliding-buffer 1)) | |
520 | 534 | changed #(put! change true) |
521 | 535 | pick (fn [attr chs] |
522 | 536 | (reduce-kv |
51 | 51 | [this] |
52 | 52 | (let [iter (.iterator puts)] |
53 | 53 | (when (.hasNext iter) |
54 | (loop [^Lock putter (.next iter)] | |
54 | (loop [[^Lock putter] (.next iter)] | |
55 | 55 | (.lock putter) |
56 | 56 | (let [put-cb (and (impl/active? putter) (impl/commit putter))] |
57 | 57 | (.unlock putter) |
174 | 174 | (let [val (impl/remove! buf) |
175 | 175 | iter (.iterator puts) |
176 | 176 | [done? cbs] |
177 | (when (.hasNext iter) | |
177 | (when (and (not (impl/full? buf)) (.hasNext iter)) | |
178 | 178 | (loop [cbs [] |
179 | 179 | [^Lock putter val] (.next iter)] |
180 | 180 | (.lock putter) |
299 | 299 | (add! buf val) |
300 | 300 | (catch Throwable t |
301 | 301 | (handle buf exh t))))))))) |
302 |
14 | 14 | (defn counted-thread-factory |
15 | 15 | "Create a ThreadFactory that maintains a counter for naming Threads. |
16 | 16 | name-format specifies thread names - use %d to include counter |
17 | daemon is a flag for whether threads are daemons or not" | |
18 | [name-format daemon] | |
19 | (let [counter (atom 0)] | |
20 | (reify | |
21 | ThreadFactory | |
22 | (newThread [this runnable] | |
23 | (doto (Thread. runnable) | |
24 | (.setName (format name-format (swap! counter inc))) | |
25 | (.setDaemon daemon)))))) | |
17 | daemon is a flag for whether threads are daemons or not | |
18 | opts is an options map: | |
19 | init-fn - function to run when thread is created" | |
20 | ([name-format daemon] | |
21 | (counted-thread-factory name-format daemon nil)) | |
22 | ([name-format daemon {:keys [init-fn] :as opts}] | |
23 | (let [counter (atom 0)] | |
24 | (reify | |
25 | ThreadFactory | |
26 | (newThread [this runnable] | |
27 | (let [body (if init-fn | |
28 | (fn [] (init-fn) (.run ^Runnable runnable)) | |
29 | runnable) | |
30 | t (Thread. ^Runnable body)] | |
31 | (doto t | |
32 | (.setName (format name-format (swap! counter inc))) | |
33 | (.setDaemon daemon)))))))) | |
26 | 34 | |
27 | 35 | (defonce |
28 | 36 | ^{:doc "Number of processors reported by the JVM"} |
12 | 12 | |
13 | 13 | (set! *warn-on-reflection* true) |
14 | 14 | |
15 | (defonce executor (delay (tp/thread-pool-executor))) | |
15 | (defonce ^:private in-dispatch (ThreadLocal.)) | |
16 | ||
17 | (defonce executor | |
18 | (delay (tp/thread-pool-executor #(.set ^ThreadLocal in-dispatch true)))) | |
19 | ||
20 | (defn in-dispatch-thread? | |
21 | "Returns true if the current thread is a go block dispatch pool thread" | |
22 | [] | |
23 | (boolean (.get ^ThreadLocal in-dispatch))) | |
24 | ||
25 | (defn check-blocking-in-dispatch | |
26 | "If the current thread is a dispatch pool thread, throw an exception" | |
27 | [] | |
28 | (when (.get ^ThreadLocal in-dispatch) | |
29 | (throw (IllegalStateException. "Invalid blocking call in dispatch thread")))) | |
16 | 30 | |
17 | 31 | (defn run |
18 | 32 | "Runs Runnable r in a thread pool thread" |
16 | 16 | "Value is set via clojure.core.async.pool-size system property; defaults to 8; uses a |
17 | 17 | delay so property can be set from code after core.async namespace is loaded but before |
18 | 18 | any use of the async thread pool." |
19 | (delay (or (when-let [prop (System/getProperty "clojure.core.async.pool-size")] | |
20 | (Long/parseLong prop)) | |
21 | 8))) | |
19 | (delay (or (Long/getLong "clojure.core.async.pool-size") 8))) | |
22 | 20 | |
23 | 21 | (defn thread-pool-executor |
24 | [] | |
25 | (let [executor-svc (Executors/newFixedThreadPool | |
26 | @pool-size | |
27 | (conc/counted-thread-factory "async-dispatch-%d" true))] | |
28 | (reify impl/Executor | |
29 | (impl/exec [this r] | |
30 | (.execute executor-svc ^Runnable r))))) | |
22 | ([] | |
23 | (thread-pool-executor nil)) | |
24 | ([init-fn] | |
25 | (let [executor-svc (Executors/newFixedThreadPool | |
26 | @pool-size | |
27 | (conc/counted-thread-factory "async-dispatch-%d" true | |
28 | {:init-fn init-fn}))] | |
29 | (reify impl/Executor | |
30 | (impl/exec [this r] | |
31 | (.execute executor-svc ^Runnable r)))))) |
35 | 35 | (def ^:const VALUE-IDX 2) |
36 | 36 | (def ^:const BINDINGS-IDX 3) |
37 | 37 | (def ^:const EXCEPTION-FRAMES 4) |
38 | (def ^:const CURRENT-EXCEPTION 5) | |
39 | (def ^:const USER-START-IDX 6) | |
38 | (def ^:const USER-START-IDX 5) | |
40 | 39 | |
41 | 40 | (defn aset-object [^AtomicReferenceArray arr idx ^Object o] |
42 | 41 | (.set arr idx o)) |
226 | 225 | (defrecord RawCode [ast locals] |
227 | 226 | IInstruction |
228 | 227 | (reads-from [this] |
229 | (keep (or locals #{}) | |
230 | (map :name (-> ast :env :locals vals)))) | |
228 | (for [local (map :name (-> ast :env :locals vals)) | |
229 | :when (contains? locals local)] | |
230 | (get locals local))) | |
231 | 231 | (writes-to [this] [(:id this)]) |
232 | 232 | (block-references [this] []) |
233 | 233 | IEmittableInstruction |
236 | 236 | `[~@(->> (-> ast :env :locals vals) |
237 | 237 | (map #(select-keys % [:op :name :form])) |
238 | 238 | (filter (fn [local] |
239 | (when locals | |
240 | (get locals (:name local))))) | |
239 | (contains? locals (:name local)))) | |
241 | 240 | set |
242 | 241 | (mapcat |
243 | 242 | (fn [local] |
412 | 411 | (terminate-block [this state-sym _] |
413 | 412 | (let [ex (gensym 'ex)] |
414 | 413 | `(let [~ex (aget-object ~state-sym ~VALUE-IDX)] |
415 | (aset-all! ~state-sym ~CURRENT-EXCEPTION ~ex) | |
416 | 414 | (cond |
417 | 415 | ~@(for [[handler-idx type] catches |
418 | i [`(instance? ~type ~ex) ` (aset-all! ~state-sym | |
419 | ~STATE-IDX ~handler-idx | |
420 | ~CURRENT-EXCEPTION nil)]] | |
416 | i [`(instance? ~type ~ex) `(aset-all! ~state-sym ~STATE-IDX ~handler-idx)]] | |
421 | 417 | i) |
422 | 418 | :else (throw ~ex)) |
423 | 419 | :recur)))) |
424 | 420 | |
425 | (defrecord EndFinally [] | |
426 | IInstruction | |
427 | (reads-from [this] []) | |
421 | (defrecord EndFinally [exception-local] | |
422 | IInstruction | |
423 | (reads-from [this] [exception-local]) | |
428 | 424 | (writes-to [this] []) |
429 | 425 | (block-references [this] []) |
430 | 426 | IEmittableInstruction |
431 | 427 | (emit-instruction [this state-sym] |
432 | `[~'_ (when-let [e# (aget-object ~state-sym ~CURRENT-EXCEPTION)] | |
433 | (throw e#))])) | |
428 | `[~'_ (throw ~exception-local)])) | |
434 | 429 | |
435 | 430 | ;; Dispatch clojure forms based on :op |
436 | 431 | (def -item-to-ssa nil) ;; for help in the repl |
643 | 638 | |
644 | 639 | (defmethod -item-to-ssa :try |
645 | 640 | [{:keys [catches body finally] :as ast}] |
646 | (gen-plan | |
647 | [body-block (add-block) | |
648 | exit-block (add-block) | |
649 | ;; Two routes to the finally block, via normal execution and | |
650 | ;; exception execution | |
651 | finally-blk (if finally | |
652 | (gen-plan | |
653 | [cur-blk (get-block) | |
654 | finally-blk (add-block) | |
655 | _ (set-block finally-blk) | |
656 | result-id (add-instruction (->Const ::value)) | |
657 | _ (item-to-ssa finally) | |
658 | ;; rethrow exception on exception path | |
659 | _ (add-instruction (->EndFinally)) | |
660 | _ (add-instruction (->Jmp result-id exit-block)) | |
661 | _ (set-block cur-blk)] | |
662 | finally-blk) | |
663 | (gen-plan [] exit-block)) | |
664 | catch-blocks (all | |
665 | (for [{ex-bind :local {ex :val} :class catch-body :body} catches] | |
666 | (gen-plan | |
667 | [cur-blk (get-block) | |
668 | catch-blk (add-block) | |
669 | _ (set-block catch-blk) | |
670 | ex-id (add-instruction (->Const ::value)) | |
671 | _ (push-alter-binding :locals assoc (:name ex-bind) | |
672 | (vary-meta ex-id merge (when (:tag ex-bind) | |
673 | {:tag (.getName ^Class (:tag ex-bind))}))) | |
674 | result-id (item-to-ssa catch-body) | |
675 | ;; if there is a finally, jump to it after | |
676 | ;; handling the exception, if not jump to exit | |
677 | _ (add-instruction (->Jmp result-id finally-blk)) | |
678 | _ (pop-binding :locals) | |
679 | _ (set-block cur-blk)] | |
680 | [catch-blk ex]))) | |
681 | ;; catch block handler routes exceptions to the correct handler, | |
682 | ;; rethrows if there is no match | |
683 | catch-handler-block (add-block) | |
684 | cur-blk (get-block) | |
685 | _ (set-block catch-handler-block) | |
686 | _ (add-instruction (->CatchHandler catch-blocks)) | |
687 | _ (set-block cur-blk) | |
688 | _ (add-instruction (->Jmp nil body-block)) | |
689 | _ (set-block body-block) | |
690 | ;; the finally gets pushed on to the exception handler stack, so | |
691 | ;; it will be executed if there is an exception | |
692 | _ (if finally | |
693 | (add-instruction (->PushTry finally-blk)) | |
694 | (no-op)) | |
695 | _ (add-instruction (->PushTry catch-handler-block)) | |
696 | body (item-to-ssa body) | |
697 | _ (add-instruction (->PopTry)) | |
698 | _ (if finally | |
699 | (add-instruction (->PopTry)) | |
700 | (no-op)) | |
701 | ;; if the body finishes executing normally, jump to the finally | |
702 | ;; block, if it exists | |
703 | _ (add-instruction (->Jmp body finally-blk)) | |
704 | _ (set-block exit-block) | |
705 | ret (add-instruction (->Const ::value))] | |
706 | ret)) | |
641 | (let [make-finally (fn [exit-block rethrow?] | |
642 | (if finally | |
643 | (gen-plan | |
644 | [cur-blk (get-block) | |
645 | finally-blk (add-block) | |
646 | _ (set-block finally-blk) | |
647 | ;; catch block has to pop itself off of | |
648 | ;; EXCEPTION-FRAMES. every try/catch pushes at | |
649 | ;; least 1 frame on to EXCEPTION-FRAMES, | |
650 | ;; try/catch/finally pushes 2. The exception | |
651 | ;; handling machinery around the state machine | |
652 | ;; pops one off when handling an exception. | |
653 | _ (add-instruction (->PopTry)) | |
654 | result-id (add-instruction (->Const ::value)) | |
655 | _ (item-to-ssa finally) | |
656 | ;; rethrow exception on exception path | |
657 | _ (if rethrow? | |
658 | (add-instruction (->EndFinally result-id)) | |
659 | (no-op)) | |
660 | _ (add-instruction (->Jmp result-id exit-block)) | |
661 | _ (set-block cur-blk)] | |
662 | finally-blk) | |
663 | (gen-plan [] exit-block)))] | |
664 | (gen-plan | |
665 | [body-block (add-block) | |
666 | exit-block (add-block) | |
667 | ;; Two routes to the finally block, via normal execution and | |
668 | ;; exception execution | |
669 | finally-blk (make-finally exit-block false) | |
670 | exception-finally-blk (make-finally exit-block true) | |
671 | catch-blocks (all | |
672 | (for [{ex-bind :local {ex :val} :class catch-body :body} catches] | |
673 | (gen-plan | |
674 | [cur-blk (get-block) | |
675 | catch-blk (add-block) | |
676 | _ (set-block catch-blk) | |
677 | ex-id (add-instruction (->Const ::value)) | |
678 | _ (push-alter-binding :locals assoc (:name ex-bind) | |
679 | (vary-meta ex-id merge (when (:tag ex-bind) | |
680 | {:tag (.getName ^Class (:tag ex-bind))}))) | |
681 | result-id (item-to-ssa catch-body) | |
682 | ;; if there is a finally, jump to it after | |
683 | ;; handling the exception, if not jump to exit | |
684 | _ (add-instruction (->Jmp result-id finally-blk)) | |
685 | _ (pop-binding :locals) | |
686 | _ (set-block cur-blk)] | |
687 | [catch-blk ex]))) | |
688 | ;; catch block handler routes exceptions to the correct handler, | |
689 | ;; rethrows if there is no match | |
690 | catch-handler-block (add-block) | |
691 | cur-blk (get-block) | |
692 | _ (set-block catch-handler-block) | |
693 | _ (add-instruction (->PopTry)) ; pop catch-handler-block | |
694 | _ (add-instruction (->CatchHandler catch-blocks)) | |
695 | _ (set-block cur-blk) | |
696 | _ (add-instruction (->Jmp nil body-block)) | |
697 | _ (set-block body-block) | |
698 | ;; the finally gets pushed on to the exception handler stack, so | |
699 | ;; it will be executed if there is an exception | |
700 | _ (if finally | |
701 | (add-instruction (->PushTry exception-finally-blk)) | |
702 | (no-op)) | |
703 | _ (add-instruction (->PushTry catch-handler-block)) | |
704 | body (item-to-ssa body) | |
705 | _ (add-instruction (->PopTry)) ; pop catch-handler-block | |
706 | ;; if the body finishes executing normally, jump to the finally | |
707 | ;; block, if it exists | |
708 | _ (add-instruction (->Jmp body finally-blk)) | |
709 | _ (set-block exit-block) | |
710 | ret (add-instruction (->Const ::value))] | |
711 | ret))) | |
707 | 712 | |
708 | 713 | (defmethod -item-to-ssa :throw |
709 | 714 | [{:keys [exception] :as ast}] |
939 | 944 | (catch Throwable ex# |
940 | 945 | (aset-all! ~state-sym ~VALUE-IDX ex#) |
941 | 946 | (if (seq (aget-object ~state-sym ~EXCEPTION-FRAMES)) |
942 | (aset-all! ~state-sym ~STATE-IDX (first (aget-object ~state-sym ~EXCEPTION-FRAMES)) | |
943 | ~EXCEPTION-FRAMES (rest (aget-object ~state-sym ~EXCEPTION-FRAMES))) | |
947 | (aset-all! ~state-sym ~STATE-IDX (first (aget-object ~state-sym ~EXCEPTION-FRAMES))) | |
944 | 948 | (throw ex#)) |
945 | 949 | :recur) |
946 | 950 | (finally |
951 | (aset-object ~state-sym ~BINDINGS-IDX (clojure.lang.Var/getThreadBindingFrame)) | |
947 | 952 | (clojure.lang.Var/resetThreadBindingFrame old-frame#)))] |
948 | 953 | (if (identical? ret-value# :recur) |
949 | 954 | (recur ~state-sym) |
8 | 8 | (ns ^{:skip-wiki true} |
9 | 9 | clojure.core.async.impl.mutex |
10 | 10 | (:require [clojure.core.async.impl.protocols :as impl]) |
11 | (:import [clojure.core.async Mutex] | |
12 | [java.util.concurrent.locks Lock ReentrantLock])) | |
11 | (:import [java.util.concurrent.locks Lock ReentrantLock])) | |
13 | 12 | |
14 | 13 | (defn mutex [] |
15 | 14 | (let [m (ReentrantLock.)] |
39 | 39 | (close! [this] |
40 | 40 | (impl/close! channel))) |
41 | 41 | |
42 | (defn timeout | |
43 | "returns a channel that will close after msecs" | |
44 | [^long msecs] | |
45 | (let [timeout (+ (System/currentTimeMillis) msecs) | |
46 | me (.ceilingEntry timeouts-map timeout)] | |
47 | (or (when (and me (< (.getKey me) (+ timeout TIMEOUT_RESOLUTION_MS))) | |
48 | (.channel ^TimeoutQueueEntry (.getValue me))) | |
49 | (let [timeout-channel (channels/chan nil) | |
50 | timeout-entry (TimeoutQueueEntry. timeout-channel timeout)] | |
51 | (.put timeouts-map timeout timeout-entry) | |
52 | (.put timeouts-queue timeout-entry) | |
53 | timeout-channel)))) | |
54 | ||
55 | 42 | (defn- timeout-worker |
56 | 43 | [] |
57 | 44 | (let [q timeouts-queue] |
62 | 49 | (recur)))) |
63 | 50 | |
64 | 51 | (defonce timeout-daemon |
65 | (doto (Thread. ^Runnable timeout-worker "clojure.core.async.timers/timeout-daemon") | |
66 | (.setDaemon true) | |
67 | (.start))) | |
52 | (delay | |
53 | (doto (Thread. ^Runnable timeout-worker "clojure.core.async.timers/timeout-daemon") | |
54 | (.setDaemon true) | |
55 | (.start)))) | |
56 | ||
57 | (defn timeout | |
58 | "returns a channel that will close after msecs" | |
59 | [^long msecs] | |
60 | @timeout-daemon | |
61 | (let [timeout (+ (System/currentTimeMillis) msecs) | |
62 | me (.ceilingEntry timeouts-map timeout)] | |
63 | (or (when (and me (< (.getKey me) (+ timeout TIMEOUT_RESOLUTION_MS))) | |
64 | (.channel ^TimeoutQueueEntry (.getValue me))) | |
65 | (let [timeout-channel (channels/chan nil) | |
66 | timeout-entry (TimeoutQueueEntry. timeout-channel timeout)] | |
67 | (.put timeouts-map timeout timeout-entry) | |
68 | (.put timeouts-queue timeout-entry) | |
69 | timeout-channel)))) |
5 | 5 | ;; the terms of this license. |
6 | 6 | ;; You must not remove this notice, or any other, from this software. |
7 | 7 | |
8 | (ns clojure.core.async.lab | |
8 | (ns ^{:skip-wiki true} clojure.core.async.lab | |
9 | 9 | "core.async HIGHLY EXPERIMENTAL feature exploration |
10 | 10 | |
11 | 11 | Caveats: |
104 | 104 | strongly advised that each of the underlying ports support buffered |
105 | 105 | writes." |
106 | 106 | [& ports] |
107 | (->BroadcastingWritePort (set ports)))⏎ | |
107 | (->BroadcastingWritePort (set ports))) |
10 | 10 | |
11 | 11 | go blocks are dispatched over an internal thread pool, which |
12 | 12 | defaults to 8 threads. The size of this pool can be modified using |
13 | the Java system property `clojure.core.async.pool-size`." | |
13 | the Java system property `clojure.core.async.pool-size`. | |
14 | ||
15 | Set Java system property `clojure.core.async.go-checking` to true | |
16 | to validate go blocks do not invoke core.async blocking operations. | |
17 | Property is read once, at namespace load time. Recommended for use | |
18 | primarily during development. Invalid blocking calls will throw in | |
19 | go block threads - use Thread.setDefaultUncaughtExceptionHandler() | |
20 | to catch and handle." | |
14 | 21 | (:refer-clojure :exclude [reduce transduce into merge map take partition |
15 | 22 | partition-by bounded-count]) |
16 | 23 | (:require [clojure.core.async.impl.protocols :as impl] |
22 | 29 | [clojure.core.async.impl.mutex :as mutex] |
23 | 30 | [clojure.core.async.impl.concurrent :as conc] |
24 | 31 | ) |
25 | (:import [clojure.core.async ThreadLocalRandom] | |
26 | [java.util.concurrent.locks Lock] | |
27 | [java.util.concurrent Executors Executor] | |
32 | (:import [java.util.concurrent.locks Lock] | |
33 | [java.util.concurrent Executors Executor ThreadLocalRandom] | |
28 | 34 | [java.util ArrayList])) |
29 | 35 | |
30 | 36 | (alias 'core 'clojure.core) |
49 | 55 | (defn buffer |
50 | 56 | "Returns a fixed buffer of size n. When full, puts will block/park." |
51 | 57 | [n] |
58 | (assert (pos? n) "fixed buffers must have size > 0") | |
52 | 59 | (buffers/fixed-buffer n)) |
53 | 60 | |
54 | 61 | (defn dropping-buffer |
83 | 90 | ([buf-or-n] (chan buf-or-n nil)) |
84 | 91 | ([buf-or-n xform] (chan buf-or-n xform nil)) |
85 | 92 | ([buf-or-n xform ex-handler] |
86 | (when (and buf-or-n (number? buf-or-n)) (assert (pos? buf-or-n) "fixed buffers must have size > 0")) | |
87 | 93 | (when xform (assert buf-or-n "buffer must be supplied when transducer is")) |
88 | 94 | (channels/chan (if (number? buf-or-n) (buffer buf-or-n) buf-or-n) xform ex-handler))) |
89 | 95 | |
92 | 98 | exception-handler. A promise channel can take exactly one value that consumers |
93 | 99 | will receive. Once full, puts complete but val is dropped (no transfer). |
94 | 100 | Consumers will block until either a value is placed in the channel or the |
95 | channel is closed. See chan for the semantics of xform and ex-handler." | |
101 | channel is closed, then return the value (or nil) forever. See chan for the | |
102 | semantics of xform and ex-handler." | |
96 | 103 | ([] (promise-chan nil)) |
97 | 104 | ([xform] (promise-chan xform nil)) |
98 | 105 | ([xform ex-handler] |
103 | 110 | [^long msecs] |
104 | 111 | (timers/timeout msecs)) |
105 | 112 | |
106 | (defn <!! | |
113 | (defmacro defblockingop | |
114 | [op doc arglist & body] | |
115 | (let [as (mapv #(list 'quote %) arglist)] | |
116 | `(def ~(with-meta op {:arglists `(list ~as) :doc doc}) | |
117 | (if (Boolean/getBoolean "clojure.core.async.go-checking") | |
118 | (fn ~arglist | |
119 | (dispatch/check-blocking-in-dispatch) | |
120 | ~@body) | |
121 | (fn ~arglist | |
122 | ~@body))))) | |
123 | ||
124 | (defblockingop <!! | |
107 | 125 | "takes a val from port. Will return nil if closed. Will block |
108 | if nothing is available." | |
126 | if nothing is available. | |
127 | Not intended for use in direct or transitive calls from (go ...) blocks. | |
128 | Use the clojure.core.async.go-checking flag to detect invalid use (see | |
129 | namespace docs)." | |
109 | 130 | [port] |
110 | 131 | (let [p (promise) |
111 | 132 | ret (impl/take! port (fn-handler (fn [v] (deliver p v))))] |
123 | 144 | "Asynchronously takes a val from port, passing to fn1. Will pass nil |
124 | 145 | if closed. If on-caller? (default true) is true, and value is |
125 | 146 | immediately available, will call fn1 on calling thread. |
147 | ||
148 | fn1 may be run in a fixed-size dispatch thread pool and should not | |
149 | perform blocking IO, including core.async blocking ops (those that | |
150 | end in !!). | |
151 | ||
126 | 152 | Returns nil." |
127 | 153 | ([port fn1] (take! port fn1 true)) |
128 | 154 | ([port fn1 on-caller?] |
134 | 160 | (dispatch/run #(fn1 val))))) |
135 | 161 | nil))) |
136 | 162 | |
137 | (defn >!! | |
163 | (defblockingop >!! | |
138 | 164 | "puts a val into port. nil values are not allowed. Will block if no |
139 | buffer space is available. Returns true unless port is already closed." | |
165 | buffer space is available. Returns true unless port is already closed. | |
166 | Not intended for use in direct or transitive calls from (go ...) blocks. | |
167 | Use the clojure.core.async.go-checking flag to detect invalid use (see | |
168 | namespace docs)." | |
140 | 169 | [port val] |
141 | 170 | (let [p (promise) |
142 | 171 | ret (impl/put! port val (fn-handler (fn [open?] (deliver p open?))))] |
158 | 187 | "Asynchronously puts a val into port, calling fn1 (if supplied) when |
159 | 188 | complete, passing false iff port is already closed. nil values are |
160 | 189 | not allowed. If on-caller? (default true) is true, and the put is |
161 | immediately accepted, will call fn1 on calling thread. Returns | |
162 | true unless port is already closed." | |
190 | immediately accepted, will call fn1 on calling thread. | |
191 | ||
192 | fn1 may be run in a fixed-size dispatch thread pool and should not | |
193 | perform blocking IO, including core.async blocking ops (those that | |
194 | end in !!). | |
195 | ||
196 | Returns true unless port is already closed." | |
163 | 197 | ([port val] |
164 | 198 | (if-let [ret (impl/put! port val fhnop)] |
165 | 199 | @ret |
236 | 270 | (defn do-alts |
237 | 271 | "returns derefable [val port] if immediate, nil if enqueued" |
238 | 272 | [fret ports opts] |
273 | (assert (pos? (count ports)) "alts must have at least one channel operation") | |
239 | 274 | (let [flag (alt-flag) |
240 | 275 | n (count ports) |
241 | 276 | ^ints idxs (random-array n) |
262 | 297 | (when got |
263 | 298 | (channels/box [(:default opts) :default]))))))) |
264 | 299 | |
265 | (defn alts!! | |
300 | (defblockingop alts!! | |
266 | 301 | "Like alts!, except takes will be made as if by <!!, and puts will |
267 | be made as if by >!!, will block until completed, and not intended | |
268 | for use in (go ...) blocks." | |
269 | [ports & {:as opts}] | |
302 | be made as if by >!!, will block until completed. | |
303 | Not intended for use in direct or transitive calls from (go ...) blocks. | |
304 | Use the clojure.core.async.go-checking flag to detect invalid use (see | |
305 | namespace docs)." | |
306 | [ports & opts] | |
270 | 307 | (let [p (promise) |
271 | ret (do-alts (partial deliver p) ports opts)] | |
308 | ret (do-alts (partial deliver p) ports (apply hash-map opts))] | |
272 | 309 | (if ret |
273 | 310 | @ret |
274 | 311 | (deref p)))) |
408 | 445 | the only JS thread when in ClojureScript). Upon completion of the |
409 | 446 | operation, the body will be resumed. |
410 | 447 | |
448 | go blocks should not (either directly or indirectly) perform operations | |
449 | that may block indefinitely. Doing so risks depleting the fixed pool of | |
450 | go block threads, causing all go block processing to stop. This includes | |
451 | core.async blocking ops (those ending in !!) and other blocking IO. | |
452 | ||
411 | 453 | Returns a channel which will receive the result of the body when |
412 | 454 | completed" |
413 | 455 | [& body] |
501 | 543 | true)))] |
502 | 544 | (dotimes [_ n] |
503 | 545 | (case type |
504 | :blocking (thread | |
505 | (let [job (<!! jobs)] | |
506 | (when (process job) | |
507 | (recur)))) | |
508 | :compute (go-loop [] | |
509 | (let [job (<! jobs)] | |
510 | (when (process job) | |
511 | (recur)))) | |
546 | (:blocking :compute) (thread | |
547 | (let [job (<!! jobs)] | |
548 | (when (process job) | |
549 | (recur)))) | |
512 | 550 | :async (go-loop [] |
513 | 551 | (let [job (<! jobs)] |
514 | 552 | (when (async job) |
545 | 583 | should be used for computational parallelism. If you have multiple |
546 | 584 | blocking operations to put in flight, use pipeline-blocking instead, |
547 | 585 | If you have multiple asynchronous operations to put in flight, use |
548 | pipeline-async instead." | |
586 | pipeline-async instead. See chan for semantics of ex-handler." | |
549 | 587 | ([n to xf from] (pipeline n to xf from true)) |
550 | 588 | ([n to xf from close?] (pipeline n to xf from close? nil)) |
551 | 589 | ([n to xf from close? ex-handler] (pipeline* n to xf from close? ex-handler :compute))) |
630 | 668 | (recur (inc i) (next s)) |
631 | 669 | i)))) |
632 | 670 | |
633 | (defn onto-chan | |
671 | (defn onto-chan! | |
634 | 672 | "Puts the contents of coll into the supplied channel. |
635 | 673 | |
636 | 674 | By default the channel will be closed after the items are copied, |
637 | 675 | but can be determined by the close? parameter. |
638 | 676 | |
639 | Returns a channel which will close after the items are copied." | |
640 | ([ch coll] (onto-chan ch coll true)) | |
677 | Returns a channel which will close after the items are copied. | |
678 | ||
679 | If accessing coll might block, use onto-chan!! instead" | |
680 | ([ch coll] (onto-chan! ch coll true)) | |
641 | 681 | ([ch coll close?] |
642 | 682 | (go-loop [vs (seq coll)] |
643 | 683 | (if (and vs (>! ch (first vs))) |
645 | 685 | (when close? |
646 | 686 | (close! ch)))))) |
647 | 687 | |
648 | (defn to-chan | |
688 | (defn to-chan! | |
649 | 689 | "Creates and returns a channel which contains the contents of coll, |
650 | closing when exhausted." | |
690 | closing when exhausted. | |
691 | ||
692 | If accessing coll might block, use to-chan!! instead" | |
651 | 693 | [coll] |
652 | 694 | (let [c (bounded-count 100 coll)] |
653 | 695 | (if (pos? c) |
654 | 696 | (let [ch (chan c)] |
655 | (onto-chan ch coll) | |
697 | (onto-chan! ch coll) | |
698 | ch) | |
699 | (let [ch (chan)] | |
700 | (close! ch) | |
701 | ch)))) | |
702 | ||
703 | (defn onto-chan | |
704 | "Deprecated - use onto-chan! or onto-chan!!" | |
705 | {:deprecated "1.2"} | |
706 | ([ch coll] (onto-chan! ch coll true)) | |
707 | ([ch coll close?] (onto-chan! ch coll close?))) | |
708 | ||
709 | (defn to-chan | |
710 | "Deprecated - use to-chan! or to-chan!!" | |
711 | {:deprecated "1.2"} | |
712 | [coll] | |
713 | (to-chan! coll)) | |
714 | ||
715 | (defn onto-chan!! | |
716 | "Like onto-chan! for use when accessing coll might block, | |
717 | e.g. a lazy seq of blocking operations" | |
718 | ([ch coll] (onto-chan!! ch coll true)) | |
719 | ([ch coll close?] | |
720 | (thread | |
721 | (loop [vs (seq coll)] | |
722 | (if (and vs (>!! ch (first vs))) | |
723 | (recur (next vs)) | |
724 | (when close? | |
725 | (close! ch))))))) | |
726 | ||
727 | (defn to-chan!! | |
728 | "Like to-chan! for use when accessing coll might block, | |
729 | e.g. a lazy seq of blocking operations" | |
730 | [coll] | |
731 | (let [c (bounded-count 100 coll)] | |
732 | (if (pos? c) | |
733 | (let [ch (chan c)] | |
734 | (onto-chan!! ch coll) | |
656 | 735 | ch) |
657 | 736 | (let [ch (chan)] |
658 | 737 | (close! ch) |
701 | 780 | (reset! dctr (count chs)) |
702 | 781 | (doseq [c chs] |
703 | 782 | (when-not (put! c val done) |
704 | (done nil) | |
705 | 783 | (untap* m c))) |
706 | 784 | ;;wait for all |
707 | 785 | (when (seq chs) |
757 | 835 | solo-modes #{:mute :pause} |
758 | 836 | attrs (conj solo-modes :solo) |
759 | 837 | solo-mode (atom :mute) |
760 | change (chan) | |
838 | change (chan (sliding-buffer 1)) | |
761 | 839 | changed #(put! change true) |
762 | 840 | pick (fn [attr chs] |
763 | 841 | (reduce-kv |
998 | 1076 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; deprecated - do not use ;;;;;;;;;;;;;;;;;;;;;;;;; |
999 | 1077 | (defn map< |
1000 | 1078 | "Deprecated - this function will be removed. Use transducer instead" |
1001 | {:deprecated "0.1.319.0-6b1aca-alpha"} | |
1079 | {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} | |
1002 | 1080 | [f ch] |
1003 | 1081 | (reify |
1004 | 1082 | impl/Channel |
1030 | 1108 | |
1031 | 1109 | (defn map> |
1032 | 1110 | "Deprecated - this function will be removed. Use transducer instead" |
1033 | {:deprecated "0.1.319.0-6b1aca-alpha"} | |
1111 | {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} | |
1034 | 1112 | [f ch] |
1035 | 1113 | (reify |
1036 | 1114 | impl/Channel |
1046 | 1124 | |
1047 | 1125 | (defn filter> |
1048 | 1126 | "Deprecated - this function will be removed. Use transducer instead" |
1049 | {:deprecated "0.1.319.0-6b1aca-alpha"} | |
1127 | {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} | |
1050 | 1128 | [p ch] |
1051 | 1129 | (reify |
1052 | 1130 | impl/Channel |
1064 | 1142 | |
1065 | 1143 | (defn remove> |
1066 | 1144 | "Deprecated - this function will be removed. Use transducer instead" |
1067 | {:deprecated "0.1.319.0-6b1aca-alpha"} | |
1145 | {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} | |
1068 | 1146 | [p ch] |
1069 | 1147 | (filter> (complement p) ch)) |
1070 | 1148 | |
1071 | 1149 | (defn filter< |
1072 | 1150 | "Deprecated - this function will be removed. Use transducer instead" |
1073 | {:deprecated "0.1.319.0-6b1aca-alpha"} | |
1151 | {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} | |
1074 | 1152 | ([p ch] (filter< p ch nil)) |
1075 | 1153 | ([p ch buf-or-n] |
1076 | 1154 | (let [out (chan buf-or-n)] |
1085 | 1163 | |
1086 | 1164 | (defn remove< |
1087 | 1165 | "Deprecated - this function will be removed. Use transducer instead" |
1088 | {:deprecated "0.1.319.0-6b1aca-alpha"} | |
1166 | {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} | |
1089 | 1167 | ([p ch] (remove< p ch nil)) |
1090 | 1168 | ([p ch buf-or-n] (filter< (complement p) ch buf-or-n))) |
1091 | 1169 | |
1101 | 1179 | |
1102 | 1180 | (defn mapcat< |
1103 | 1181 | "Deprecated - this function will be removed. Use transducer instead" |
1104 | {:deprecated "0.1.319.0-6b1aca-alpha"} | |
1182 | {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} | |
1105 | 1183 | ([f in] (mapcat< f in nil)) |
1106 | 1184 | ([f in buf-or-n] |
1107 | 1185 | (let [out (chan buf-or-n)] |
1110 | 1188 | |
1111 | 1189 | (defn mapcat> |
1112 | 1190 | "Deprecated - this function will be removed. Use transducer instead" |
1113 | {:deprecated "0.1.319.0-6b1aca-alpha"} | |
1191 | {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} | |
1114 | 1192 | ([f out] (mapcat> f out nil)) |
1115 | 1193 | ([f out buf-or-n] |
1116 | 1194 | (let [in (chan buf-or-n)] |
1119 | 1197 | |
1120 | 1198 | (defn unique |
1121 | 1199 | "Deprecated - this function will be removed. Use transducer instead" |
1122 | {:deprecated "0.1.319.0-6b1aca-alpha"} | |
1200 | {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} | |
1123 | 1201 | ([ch] |
1124 | 1202 | (unique ch nil)) |
1125 | 1203 | ([ch buf-or-n] |
1137 | 1215 | |
1138 | 1216 | (defn partition |
1139 | 1217 | "Deprecated - this function will be removed. Use transducer instead" |
1140 | {:deprecated "0.1.319.0-6b1aca-alpha"} | |
1218 | {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} | |
1141 | 1219 | ([n ch] |
1142 | 1220 | (partition n ch nil)) |
1143 | 1221 | ([n ch buf-or-n] |
1162 | 1240 | |
1163 | 1241 | (defn partition-by |
1164 | 1242 | "Deprecated - this function will be removed. Use transducer instead" |
1165 | {:deprecated "0.1.319.0-6b1aca-alpha"} | |
1243 | {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} | |
1166 | 1244 | ([f ch] |
1167 | 1245 | (partition-by f ch nil)) |
1168 | 1246 | ([f ch buf-or-n] |
0 | /* | |
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 | ||
10 | package clojure.core.async; | |
11 | ||
12 | import java.util.concurrent.locks.AbstractQueuedSynchronizer; | |
13 | ||
14 | // non-recursive, non-reentrant mutex implementation based on example | |
15 | // from Doug Lea's "The java.util.concurrent Synchronizer Framework" | |
16 | // http://gee.cs.oswego.edu/dl/papers/aqs.pdf | |
17 | public class Mutex { | |
18 | private static class Sync extends AbstractQueuedSynchronizer { | |
19 | public boolean tryAcquire(int ignored) { | |
20 | return compareAndSetState(0, 1); | |
21 | } | |
22 | ||
23 | public boolean tryRelease(int ignored) { | |
24 | setState(0); | |
25 | return true; | |
26 | } | |
27 | } | |
28 | ||
29 | private final Sync sync = new Sync(); | |
30 | ||
31 | public Mutex() {} | |
32 | ||
33 | public void lock() { | |
34 | sync.acquire(1); | |
35 | } | |
36 | ||
37 | public void unlock() { | |
38 | sync.release(1); | |
39 | } | |
40 | } |
0 | /* | |
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 | ||
10 | package clojure.core.async; | |
11 | ||
12 | import java.util.Random; | |
13 | ||
14 | public class ThreadLocalRandom extends Random { | |
15 | ||
16 | private static final long serialVersionUID = -2599376724352996934L; | |
17 | ||
18 | private static ThreadLocal<ThreadLocalRandom> currentThreadLocalRandom = new ThreadLocal<ThreadLocalRandom>() { | |
19 | protected ThreadLocalRandom initialValue() { | |
20 | return new ThreadLocalRandom(); | |
21 | } | |
22 | }; | |
23 | ||
24 | ||
25 | /** | |
26 | * Returns the current ThreadLocalRandom for this thread. Clients must call current, | |
27 | * rather than constructing instances themselves. The ThreadLocalRandom instance will | |
28 | * be returned from a ThreadLocal variable. | |
29 | * | |
30 | * @return A ThreadLocalRandom for the current thread | |
31 | * | |
32 | * @see ThreadLocal | |
33 | * @see Random | |
34 | */ | |
35 | public static ThreadLocalRandom current() { | |
36 | return currentThreadLocalRandom.get(); | |
37 | } | |
38 | ||
39 | private ThreadLocalRandom() { | |
40 | super(); | |
41 | } | |
42 | ||
43 | private ThreadLocalRandom(long seed) { | |
44 | super(seed); | |
45 | } | |
46 | ||
47 | } |
0 | ;; Copyright (c) Rich Hickey and contributors. All rights reserved. | |
1 | ;; The use and distribution terms for this software are covered by the | |
2 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
3 | ;; which can be found in the file epl-v10.html at the root of this distribution. | |
4 | ;; By using this software in any fashion, you are agreeing to be bound by | |
5 | ;; the terms of this license. | |
6 | ;; You must not remove this notice, or any other, from this software. | |
7 | ||
0 | 8 | (ns cljs.core.async.buffer-tests |
1 | 9 | (:require-macros [cljs.core.async.macros :as m :refer [go]]) |
2 | 10 | (:require [cljs.core.async |
29 | 37 | (is (full? fb)) |
30 | 38 | #_(assert (throws? (add! fb :3))) |
31 | 39 | |
40 | ; already overflown | |
41 | (add! fb :3) | |
42 | (is (= 3 (count fb))) | |
43 | (is (full? fb)) | |
44 | ||
32 | 45 | (is (= :1 (remove! fb))) |
46 | (is (= 2 (count fb))) | |
47 | (is (full? fb)) | |
48 | ||
49 | (is (= :2 (remove! fb))) | |
50 | (is (= 1 (count fb))) | |
33 | 51 | (is (not (full? fb))) |
34 | 52 | |
35 | (is (= 1 (count fb))) | |
36 | (is (= :2 (remove! fb))) | |
37 | ||
53 | (is (= :3 (remove! fb))) | |
38 | 54 | (is (= 0 (count fb))) |
39 | 55 | #_(is (helpers/throws? (remove! fb))))) |
40 | 56 |
0 | ;; Copyright (c) Rich Hickey and contributors. All rights reserved. | |
1 | ;; The use and distribution terms for this software are covered by the | |
2 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
3 | ;; which can be found in the file epl-v10.html at the root of this distribution. | |
4 | ;; By using this software in any fashion, you are agreeing to be bound by | |
5 | ;; the terms of this license. | |
6 | ;; You must not remove this notice, or any other, from this software. | |
7 | ||
8 | (ns cljs.core.async.interop-tests | |
9 | (:require-macros [cljs.core.async.macros :refer [go]]) | |
10 | (:require [cljs.core.async :refer [<!]] | |
11 | [cljs.core.async.interop :refer [p->c] :refer-macros [<p!]] | |
12 | [cljs.test :refer-macros [deftest is async]])) | |
13 | ||
14 | (deftest interop-resolve | |
15 | (async done | |
16 | (go | |
17 | (is (= (<p! (js/Promise.resolve 42)) 42)) | |
18 | (done)))) | |
19 | ||
20 | (deftest interop-resolve-nil | |
21 | (async done | |
22 | (go | |
23 | (is (= (<p! (js/Promise.resolve)) nil)) | |
24 | (done)))) | |
25 | ||
26 | (deftest interop-multiple-resolve | |
27 | (async done | |
28 | (go | |
29 | (let [total (atom 0)] | |
30 | (swap! total + (<p! (js/Promise.resolve 1))) | |
31 | (swap! total + (<p! (js/Promise.resolve 2))) | |
32 | (swap! total + (<p! (js/Promise.resolve 3))) | |
33 | (is (= @total 6)) | |
34 | (done))))) | |
35 | ||
36 | (deftest interop-catch | |
37 | (async done | |
38 | (let [err (js/Error. "Rejected")] | |
39 | (go | |
40 | (is (= err | |
41 | (ex-cause | |
42 | (is (thrown? | |
43 | js/Error | |
44 | (<p! (js/Promise.reject err))))))) | |
45 | (done))))) | |
46 | ||
47 | (deftest interop-catch-non-error | |
48 | (async done | |
49 | (let [err "Rejected"] | |
50 | (go | |
51 | (is (= err | |
52 | (ex-cause | |
53 | (is (thrown? | |
54 | js/Error | |
55 | (<p! (js/Promise.reject err))))))) | |
56 | (done))))) | |
57 | ||
58 | (deftest interop-nested | |
59 | (async done | |
60 | (go | |
61 | (let [total (atom 0) | |
62 | first-res (<p! (js/Promise.resolve 1)) | |
63 | second-res (<p! (js/Promise.resolve 2))] | |
64 | (swap! total + (<p! (js/Promise.resolve 3))) | |
65 | (swap! total + (<p! (js/Promise.resolve 5))) | |
66 | (swap! total + first-res) | |
67 | (swap! total + second-res) | |
68 | (is (= @total 11)) | |
69 | (done))))) | |
70 | ||
71 | (deftest interop-multiple-consumer | |
72 | (async done | |
73 | (go | |
74 | (let [p (js/Promise.resolve 42)] | |
75 | (is (= (<p! p) 42)) | |
76 | (is (= (<p! p) 42)) | |
77 | (done))))) | |
78 | ||
79 | (deftest interop-p->c-semantics | |
80 | (async done | |
81 | (go | |
82 | (let [c (p->c (js/Promise.resolve 42))] | |
83 | (is (= (<! c) 42)) | |
84 | (is (= (<! c) 42)) | |
85 | (done))))) |
0 | ;; Copyright (c) Rich Hickey and contributors. All rights reserved. | |
1 | ;; The use and distribution terms for this software are covered by the | |
2 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
3 | ;; which can be found in the file epl-v10.html at the root of this distribution. | |
4 | ;; By using this software in any fashion, you are agreeing to be bound by | |
5 | ;; the terms of this license. | |
6 | ;; You must not remove this notice, or any other, from this software. | |
7 | ||
0 | 8 | (ns cljs.core.async.pipeline-test |
1 | 9 | (:require-macros [cljs.core.async.macros :as m :refer [go go-loop]]) |
2 | 10 | (:require [cljs.core.async.test-helpers :refer [latch inc!]] |
3 | 11 | [cljs.core.async :as a |
4 | :refer [<! >! chan close! to-chan pipeline-async pipeline put!]] | |
12 | :refer [<! >! chan close! to-chan! pipeline-async pipeline put!]] | |
5 | 13 | [cljs.test :refer-macros [deftest is testing async]])) |
6 | 14 | |
7 | 15 | (defn pipeline-tester [pipeline-fn n inputs xf] |
8 | (let [cin (to-chan inputs) | |
16 | (let [cin (to-chan! inputs) | |
9 | 17 | cout (chan 1)] |
10 | 18 | (pipeline-fn n cout xf cin) |
11 | 19 | (go-loop [acc []] |
49 | 57 | (async done |
50 | 58 | (go |
51 | 59 | (let [cout (chan 1)] |
52 | (pipeline 5 cout (map identity) (to-chan [1]) true) | |
60 | (pipeline 5 cout (map identity) (to-chan! [1]) true) | |
53 | 61 | (is (= 1 (<! cout))) |
54 | 62 | (is (= nil (<! cout)))) |
55 | 63 | (let [cout (chan 1)] |
56 | (pipeline 5 cout (map identity) (to-chan [1]) false) | |
64 | (pipeline 5 cout (map identity) (to-chan! [1]) false) | |
57 | 65 | (is (= 1 (<! cout))) |
58 | 66 | (>! cout :more) |
59 | 67 | (is (= :more (<! cout)))) |
60 | 68 | (let [cout (chan 1)] |
61 | (pipeline 5 cout (map identity) (to-chan [1]) nil) | |
69 | (pipeline 5 cout (map identity) (to-chan! [1]) nil) | |
62 | 70 | (is (= 1 (<! cout))) |
63 | 71 | (>! cout :more) |
64 | 72 | (is (= :more (<! cout)))) |
71 | 79 | chex (chan 1) |
72 | 80 | ex-mapping (map (fn [x] (if (= x 3) (throw (ex-info "err" {:data x})) x))) |
73 | 81 | ex-handler (fn [e] (do (put! chex e) :err))] |
74 | (pipeline 5 cout ex-mapping (to-chan [1 2 3 4]) true ex-handler) | |
82 | (pipeline 5 cout ex-mapping (to-chan! [1 2 3 4]) true ex-handler) | |
75 | 83 | (is (= 1 (<! cout))) |
76 | 84 | (is (= 2 (<! cout))) |
77 | 85 | (is (= :err (<! cout))) |
0 | ;; Copyright (c) Rich Hickey and contributors. All rights reserved. | |
1 | ;; The use and distribution terms for this software are covered by the | |
2 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
3 | ;; which can be found in the file epl-v10.html at the root of this distribution. | |
4 | ;; By using this software in any fashion, you are agreeing to be bound by | |
5 | ;; the terms of this license. | |
6 | ;; You must not remove this notice, or any other, from this software. | |
7 | ||
0 | 8 | (ns cljs.core.async.runner-tests |
1 | 9 | (:require [cljs.core.async :refer [buffer dropping-buffer sliding-buffer put! take! chan close!]] |
2 | 10 | [cljs.core.async.impl.dispatch :as dispatch] |
184 | 192 | (finally (reset! a true))))] |
185 | 193 | (is (and @a v))) |
186 | 194 | |
195 | (testing "https://dev.clojure.org/jira/browse/ASYNC-73" | |
196 | (let [a (atom false)] | |
197 | (runner | |
198 | (try | |
199 | (throw (js/Error. "asdf")) | |
200 | (catch ExceptionInfo e) | |
201 | (catch js/Error e) | |
202 | (finally | |
203 | (reset! a true)))) | |
204 | (is @a)) | |
205 | (is (runner | |
206 | (try | |
207 | (throw (new js/TypeError "unexpected")) | |
208 | (catch ExceptionInfo e | |
209 | false) | |
210 | (catch :default e | |
211 | true))))) | |
212 | ||
213 | (testing "https://dev.clojure.org/jira/browse/ASYNC-172" | |
214 | (is (= 123 (runner | |
215 | (try (throw 123) | |
216 | (catch :default e 123)))))) | |
187 | 217 | |
188 | 218 | (let [a (atom false) |
189 | 219 | v (try (runner |
192 | 222 | (finally (reset! a true)))) |
193 | 223 | (catch js/Error ex ex))] |
194 | 224 | (is (and @a v))) |
195 | ||
196 | 225 | |
197 | 226 | (let [a (atom 0) |
198 | 227 | v (runner |
0 | ;; Copyright (c) Rich Hickey and contributors. All rights reserved. | |
1 | ;; The use and distribution terms for this software are covered by the | |
2 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
3 | ;; which can be found in the file epl-v10.html at the root of this distribution. | |
4 | ;; By using this software in any fashion, you are agreeing to be bound by | |
5 | ;; the terms of this license. | |
6 | ;; You must not remove this notice, or any other, from this software. | |
7 | ||
0 | 8 | (ns cljs.core.async.test-helpers |
1 | 9 | (:require [cljs.core.async.impl.ioc-macros :as ioc])) |
2 | 10 | |
22 | 30 | c#))] |
23 | 31 | (when (satisfies? cljs.core.async.impl.protocols.Channel body-chan#) |
24 | 32 | (cljs.core.async.macros/go |
25 | (let [[v# _] (cljs.core.async/alts! [body-chan# (timeout#)] :priority true)] | |
33 | (let [[v# c#] (cljs.core.async/alts! [body-chan# (timeout#)] :priority true)] | |
26 | 34 | (assert (not= ::timeout v#) |
27 | 35 | (str "test timed out: " ~nm )))) |
28 | 36 | true))) |
0 | ;; Copyright (c) Rich Hickey and contributors. All rights reserved. | |
1 | ;; The use and distribution terms for this software are covered by the | |
2 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
3 | ;; which can be found in the file epl-v10.html at the root of this distribution. | |
4 | ;; By using this software in any fashion, you are agreeing to be bound by | |
5 | ;; the terms of this license. | |
6 | ;; You must not remove this notice, or any other, from this software. | |
7 | ||
0 | 8 | (ns cljs.core.async.test-helpers) |
1 | 9 | |
2 | 10 | (defn latch [m f] |
0 | ;; Copyright (c) Rich Hickey and contributors. All rights reserved. | |
1 | ;; The use and distribution terms for this software are covered by the | |
2 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
3 | ;; which can be found in the file epl-v10.html at the root of this distribution. | |
4 | ;; By using this software in any fashion, you are agreeing to be bound by | |
5 | ;; the terms of this license. | |
6 | ;; You must not remove this notice, or any other, from this software. | |
7 | ||
0 | 8 | (ns cljs.core.async.test-runner |
1 | 9 | (:require [cljs.test :refer-macros [run-tests]] |
2 | 10 | [cljs.core.async.buffer-tests] |
3 | 11 | [cljs.core.async.pipeline-test] |
4 | [cljs.core.async.tests])) | |
12 | [cljs.core.async.timers-test] | |
13 | [cljs.core.async.interop-tests] | |
14 | [cljs.core.async.tests] | |
15 | [cljs.core.async.runner-tests])) | |
5 | 16 | |
6 | 17 | (run-tests |
18 | 'cljs.core.async.runner-tests | |
7 | 19 | 'cljs.core.async.pipeline-test |
8 | 20 | 'cljs.core.async.buffer-tests |
21 | 'cljs.core.async.timers-test | |
22 | 'cljs.core.async.interop-tests | |
9 | 23 | 'cljs.core.async.tests) |
0 | ;; Copyright (c) Rich Hickey and contributors. All rights reserved. | |
1 | ;; The use and distribution terms for this software are covered by the | |
2 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
3 | ;; which can be found in the file epl-v10.html at the root of this distribution. | |
4 | ;; By using this software in any fashion, you are agreeing to be bound by | |
5 | ;; the terms of this license. | |
6 | ;; You must not remove this notice, or any other, from this software. | |
7 | ||
0 | 8 | (ns cljs.core.async.tests |
1 | 9 | (:require-macros |
2 | 10 | [cljs.core.async.macros :as m :refer [go alt!]]) |
141 | 149 | (async done |
142 | 150 | (go |
143 | 151 | (is (= [2 3 4 5] |
144 | (<! (async/into [] (async/map< inc (async/to-chan [1 2 3 4])))))) | |
152 | (<! (async/into [] (async/map< inc (async/to-chan! [1 2 3 4])))))) | |
145 | 153 | (done)))) |
146 | 154 | |
147 | 155 | (deftest test-map> |
150 | 158 | (is (= [2 3 4 5] |
151 | 159 | (let [out (chan) |
152 | 160 | in (async/map> inc out)] |
153 | (async/onto-chan in [1 2 3 4]) | |
161 | (async/onto-chan! in [1 2 3 4]) | |
154 | 162 | (<! (async/into [] out))))) |
155 | 163 | (done)))) |
156 | 164 | |
158 | 166 | (async done |
159 | 167 | (go |
160 | 168 | (is (= [2 4 6] |
161 | (<! (async/into [] (async/filter< even? (async/to-chan [1 2 3 4 5 6])))))) | |
169 | (<! (async/into [] (async/filter< even? (async/to-chan! [1 2 3 4 5 6])))))) | |
162 | 170 | (done)))) |
163 | 171 | |
164 | 172 | (deftest test-remoev< |
165 | 173 | (async done |
166 | 174 | (go |
167 | 175 | (is (= [1 3 5] |
168 | (<! (async/into [] (async/remove< even? (async/to-chan [1 2 3 4 5 6])))))) | |
176 | (<! (async/into [] (async/remove< even? (async/to-chan! [1 2 3 4 5 6])))))) | |
169 | 177 | (done)))) |
170 | 178 | |
171 | 179 | (deftest test-filter> |
174 | 182 | (is (= [2 4 6] |
175 | 183 | (let [out (chan) |
176 | 184 | in (async/filter> even? out)] |
177 | (async/onto-chan in [1 2 3 4 5 6]) | |
185 | (async/onto-chan! in [1 2 3 4 5 6]) | |
178 | 186 | (<! (async/into [] out))))) |
179 | 187 | (done)))) |
180 | 188 | |
184 | 192 | (is (= [1 3 5] |
185 | 193 | (let [out (chan) |
186 | 194 | in (async/remove> even? out)] |
187 | (async/onto-chan in [1 2 3 4 5 6]) | |
195 | (async/onto-chan! in [1 2 3 4 5 6]) | |
188 | 196 | (<! (async/into [] out))))) |
189 | 197 | (done)))) |
190 | 198 | |
192 | 200 | (async done |
193 | 201 | (go |
194 | 202 | (is (= [0 0 1 0 1 2] |
195 | (<! (async/into [] (async/mapcat< range (async/to-chan [1 2 3])))))) | |
203 | (<! (async/into [] (async/mapcat< range (async/to-chan! [1 2 3])))))) | |
196 | 204 | (done)))) |
197 | 205 | |
198 | 206 | (deftest test-mapcat> |
201 | 209 | (is (= [0 0 1 0 1 2] |
202 | 210 | (let [out (chan) |
203 | 211 | in (async/mapcat> range out)] |
204 | (async/onto-chan in [1 2 3]) | |
212 | (async/onto-chan! in [1 2 3]) | |
205 | 213 | (<! (async/into [] out))))) |
206 | 214 | (done)))) |
207 | 215 | |
210 | 218 | (go |
211 | 219 | (is (= [1 2 3 4 5] |
212 | 220 | (let [out (chan)] |
213 | (async/pipe (async/to-chan [1 2 3 4 5]) | |
221 | (async/pipe (async/to-chan! [1 2 3 4 5]) | |
214 | 222 | out) |
215 | 223 | (<! (async/into [] out))))) |
216 | 224 | (done)))) |
219 | 227 | (async done |
220 | 228 | ;; Must provide buffers for channels else the tests won't complete |
221 | 229 | (go |
222 | (let [[even odd] (async/split even? (async/to-chan [1 2 3 4 5 6]) 5 5)] | |
230 | (let [[even odd] (async/split even? (async/to-chan! [1 2 3 4 5 6]) 5 5)] | |
223 | 231 | (is (= [2 4 6] (<! (async/into [] even)))) |
224 | 232 | (is (= [1 3 5] (<! (async/into [] odd))))) |
225 | 233 | (done)))) |
230 | 238 | (is (= [0 4 8 12] |
231 | 239 | (<! (async/into [] |
232 | 240 | (async/map + |
233 | [(async/to-chan (range 4)) | |
234 | (async/to-chan (range 4)) | |
235 | (async/to-chan (range 4)) | |
236 | (async/to-chan (range 4))]))))) | |
241 | [(async/to-chan! (range 4)) | |
242 | (async/to-chan! (range 4)) | |
243 | (async/to-chan! (range 4)) | |
244 | (async/to-chan! (range 4))]))))) | |
237 | 245 | (done)))) |
238 | 246 | |
239 | 247 | (deftest test-merge |
245 | 253 | (frequencies |
246 | 254 | (<! (async/into [] |
247 | 255 | (async/merge |
248 | [(async/to-chan (range 4)) | |
249 | (async/to-chan (range 4)) | |
250 | (async/to-chan (range 4)) | |
251 | (async/to-chan (range 4))])))))) | |
256 | [(async/to-chan! (range 4)) | |
257 | (async/to-chan! (range 4)) | |
258 | (async/to-chan! (range 4)) | |
259 | (async/to-chan! (range 4))])))))) | |
252 | 260 | (done)))) |
253 | 261 | |
254 | 262 | (deftest test-mult |
260 | 268 | m (async/mult src)] |
261 | 269 | (async/tap m a) |
262 | 270 | (async/tap m b) |
263 | (async/pipe (async/to-chan (range 4)) src) | |
271 | (async/pipe (async/to-chan! (range 4)) src) | |
264 | 272 | (is (= [0 1 2 3] (<! (async/into [] a)))) |
265 | 273 | (is (= [0 1 2 3] (<! (async/into [] b)))) |
266 | 274 | (done))))) |
274 | 282 | take6 (go (dotimes [x 6] |
275 | 283 | (>! take-out (<! out))) |
276 | 284 | (close! take-out))] |
277 | (async/admix mx (async/to-chan [1 2 3])) | |
278 | (async/admix mx (async/to-chan [4 5 6])) | |
285 | (async/admix mx (async/to-chan! [1 2 3])) | |
286 | (async/admix mx (async/to-chan! [4 5 6])) | |
279 | 287 | (is (= #{1 2 3 4 5 6} (<! (async/into #{} take-out)))) |
280 | 288 | (done))))) |
281 | 289 | |
295 | 303 | (async/sub p :string b-strs) |
296 | 304 | (async/sub p :int a-ints) |
297 | 305 | (async/sub p :int b-ints) |
298 | (async/pipe (async/to-chan [1 "a" 2 "b" 3 "c"]) src) | |
306 | (async/pipe (async/to-chan! [1 "a" 2 "b" 3 "c"]) src) | |
299 | 307 | (is (= [1 2 3] |
300 | 308 | (<! (async/into [] a-ints)))) |
301 | 309 | (is (= [1 2 3] |
310 | 318 | (async done |
311 | 319 | (go |
312 | 320 | (is (= [1 2 3 4] |
313 | (<! (async/into [] (async/unique (async/to-chan [1 1 2 2 3 3 3 3 4])))))) | |
321 | (<! (async/into [] (async/unique (async/to-chan! [1 1 2 2 3 3 3 3 4])))))) | |
314 | 322 | (done)))) |
315 | 323 | |
316 | 324 | (deftest test-partition |
317 | 325 | (async done |
318 | 326 | (go |
319 | 327 | (is (= [[1 2] [2 3]] |
320 | (<! (async/into [] (async/partition 2 (async/to-chan [1 2 2 3])))))) | |
328 | (<! (async/into [] (async/partition 2 (async/to-chan! [1 2 2 3])))))) | |
321 | 329 | (done)))) |
322 | 330 | |
323 | 331 | |
325 | 333 | (async done |
326 | 334 | (go |
327 | 335 | (is (= [["a" "b"] [1 :2 3] ["c"]] |
328 | (<! (async/into [] (async/partition-by string? (async/to-chan ["a" "b" 1 :2 3 "c"])))))) | |
336 | (<! (async/into [] (async/partition-by string? (async/to-chan! ["a" "b" 1 :2 3 "c"])))))) | |
329 | 337 | (done)))) |
330 | 338 | |
331 | 339 | (deftest test-reduce |
332 | 340 | (async done |
333 | 341 | (let [l (latch 3 done)] |
334 | (go (is (= 0 (<! (async/reduce + 0 (async/to-chan []))))) | |
342 | (go (is (= 0 (<! (async/reduce + 0 (async/to-chan! []))))) | |
335 | 343 | (inc! l)) |
336 | (go (is (= 45 (<! (async/reduce + 0 (async/to-chan (range 10)))))) | |
344 | (go (is (= 45 (<! (async/reduce + 0 (async/to-chan! (range 10)))))) | |
337 | 345 | (inc! l)) |
338 | 346 | (go (is (= :foo (<! (async/reduce #(if (= %2 2) (reduced :foo) %1) 0 |
339 | (async/to-chan (range 10)))))) | |
347 | (async/to-chan! (range 10)))))) | |
340 | 348 | (inc! l))))) |
341 | 349 | |
342 | 350 | (deftest dispatch-bugs |
465 | 473 | (deftest test-transduce |
466 | 474 | (go |
467 | 475 | (= [1 2 3 4 5] |
468 | (<! (async/transduce (map inc) conj [] (async/to-chan (range 5))))))) | |
476 | (<! (async/transduce (map inc) conj [] (async/to-chan! (range 5))))))) | |
477 | ||
478 | (def ^:dynamic foo 42) | |
479 | ||
480 | (deftest test-locals-alias-globals | |
481 | (async done | |
482 | (go | |
483 | (let [old foo] | |
484 | (set! foo 45) | |
485 | (is (= foo 45)) | |
486 | (is (= old 42)) | |
487 | (set! foo old) | |
488 | (is (= old 42)) | |
489 | (is (= foo 42))) | |
490 | (done)))) |
0 | ;; Copyright (c) Rich Hickey and contributors. All rights reserved. | |
1 | ;; The use and distribution terms for this software are covered by the | |
2 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
3 | ;; which can be found in the file epl-v10.html at the root of this distribution. | |
4 | ;; By using this software in any fashion, you are agreeing to be bound by | |
5 | ;; the terms of this license. | |
6 | ;; You must not remove this notice, or any other, from this software. | |
7 | ||
8 | (ns cljs.core.async.timers-test | |
9 | (:require [cljs.core.async.impl.timers :as timers] | |
10 | [cljs.test :refer-macros [deftest testing is are]])) | |
11 | ||
12 | (deftest skip-list-tests | |
13 | (testing "accessing empty skip list" | |
14 | (is (nil? (.ceilingEntry (timers/skip-list) 1000))) | |
15 | (is (nil? (.floorEntry (timers/skip-list) 1000)))) | |
16 | (testing "accessing singleton skip list" | |
17 | (let [skip-list (doto (timers/skip-list) | |
18 | (.put 1000 :a))] | |
19 | (are [entry k] (= entry (seq (.ceilingEntry skip-list k))) | |
20 | [1000 :a] 500 | |
21 | [1000 :a] 1000 | |
22 | nil 1500) | |
23 | (are [entry k] (= entry (seq (.floorEntry skip-list k))) | |
24 | nil 500 | |
25 | [1000 :a] 1000 | |
26 | [1000 :a] 1500))) | |
27 | (testing "accessing multi-entry skip list" | |
28 | (let [skip-list (doto (timers/skip-list) | |
29 | (.put 1000 :a) | |
30 | (.put 2000 :b) | |
31 | (.put 3000 :c) | |
32 | (.put 4000 :d) | |
33 | (.put 5000 :e) | |
34 | (.put 6000 :f))] | |
35 | (are [entry k] (= entry (seq (.ceilingEntry skip-list k))) | |
36 | [1000 :a] 500 | |
37 | [1000 :a] 1000 | |
38 | [2000 :b] 1500 | |
39 | [2000 :b] 2000 | |
40 | [3000 :c] 2500 | |
41 | [3000 :c] 3000 | |
42 | [4000 :d] 3500 | |
43 | [4000 :d] 4000 | |
44 | [5000 :e] 4500 | |
45 | [5000 :e] 5000 | |
46 | [6000 :f] 5500 | |
47 | [6000 :f] 6000 | |
48 | nil 6500) | |
49 | (are [entry k] (= entry (seq (.floorEntry skip-list k))) | |
50 | nil 500 | |
51 | [1000 :a] 1000 | |
52 | [1000 :a] 1500 | |
53 | [2000 :b] 2000 | |
54 | [2000 :b] 2500 | |
55 | [3000 :c] 3000 | |
56 | [3000 :c] 3500 | |
57 | [4000 :d] 4000 | |
58 | [4000 :d] 4500 | |
59 | [5000 :e] 5000 | |
60 | [5000 :e] 5500 | |
61 | [6000 :f] 6000 | |
62 | [6000 :f] 6500))) | |
63 | (testing "removing from singleton skip list" | |
64 | (let [skip-list (doto (timers/skip-list) | |
65 | (.put 1000 :a) | |
66 | (.remove 1000))] | |
67 | (are [entry k] (= entry (seq (.ceilingEntry skip-list k))) | |
68 | nil 500 | |
69 | nil 1000 | |
70 | nil 1500) | |
71 | (are [entry k] (= entry (seq (.floorEntry skip-list k))) | |
72 | nil 500 | |
73 | nil 1000 | |
74 | nil 1500))) | |
75 | (testing "removing from multi-entry skip list" | |
76 | (let [skip-list (doto (timers/skip-list) | |
77 | (.put 1000 :a) | |
78 | (.put 2000 :b) | |
79 | (.put 3000 :c) | |
80 | (.put 4000 :d) | |
81 | (.remove 2000) | |
82 | (.put 5000 :e) | |
83 | (.put 6000 :f) | |
84 | (.remove 4000))] | |
85 | (are [entry k] (= entry (seq (.ceilingEntry skip-list k))) | |
86 | [1000 :a] 500 | |
87 | [1000 :a] 1000 | |
88 | [3000 :c] 1500 | |
89 | [3000 :c] 2000 | |
90 | [3000 :c] 2500 | |
91 | [3000 :c] 3000 | |
92 | [5000 :e] 3500 | |
93 | [5000 :e] 4000 | |
94 | [5000 :e] 4500 | |
95 | [5000 :e] 5000 | |
96 | [6000 :f] 5500 | |
97 | [6000 :f] 6000 | |
98 | nil 6500) | |
99 | (are [entry k] (= entry (seq (.floorEntry skip-list k))) | |
100 | nil 500 | |
101 | [1000 :a] 1000 | |
102 | [1000 :a] 1500 | |
103 | [1000 :a] 2000 | |
104 | [1000 :a] 2500 | |
105 | [3000 :c] 3000 | |
106 | [3000 :c] 3500 | |
107 | [3000 :c] 4000 | |
108 | [3000 :c] 4500 | |
109 | [5000 :e] 5000 | |
110 | [5000 :e] 5500 | |
111 | [6000 :f] 6000 | |
112 | [6000 :f] 6500)))) |
2 | 2 | partition-by]) |
3 | 3 | (:require [clojure.core.async.impl.ioc-macros :as ioc] |
4 | 4 | [clojure.core.async :refer :all :as async] |
5 | [clojure.set :as set] | |
5 | 6 | [clojure.test :refer :all]) |
6 | 7 | (:import [java.io FileInputStream ByteArrayOutputStream File])) |
7 | 8 | |
338 | 339 | |
339 | 340 | |
340 | 341 | (defn identity-chan |
341 | "Defines a channel that instantly writes the given value" | |
342 | "Defines a channel that contains the given value" | |
342 | 343 | [x] |
343 | (let [c (chan 1)] | |
344 | (>!! c x) | |
345 | (close! c) | |
346 | c)) | |
344 | (to-chan! [x])) | |
347 | 345 | |
348 | 346 | (deftest async-test |
349 | 347 | (testing "values are returned correctly" |
435 | 433 | (chan) ([v] :failed) |
436 | 434 | :default 42)))))) |
437 | 435 | |
438 | (testing "alt obeys its random-array initialization" | |
439 | (is (= #{:two} | |
440 | (with-redefs [clojure.core.async/random-array | |
441 | (constantly (int-array [1 2 0]))] | |
442 | (<!! (go (loop [acc #{} | |
443 | cnt 0] | |
444 | (if (< cnt 10) | |
445 | (let [label (alt! | |
446 | (identity-chan :one) ([v] v) | |
447 | (identity-chan :two) ([v] v) | |
448 | (identity-chan :three) ([v] v))] | |
449 | (recur (conj acc label) (inc cnt))) | |
450 | acc))))))))) | |
436 | (testing "alt random checks all chans" | |
437 | (is (set/subset? | |
438 | (<!! (go (loop [acc #{} | |
439 | cnt 0] | |
440 | (if (< cnt 20) | |
441 | (let [label (alt! | |
442 | (identity-chan :one) ([v] v) | |
443 | (identity-chan :two) ([v] v) | |
444 | (identity-chan :three) ([v] v))] | |
445 | (recur (conj acc label) (inc cnt))) | |
446 | acc)))) | |
447 | #{:one :two :three})))) | |
451 | 448 | |
452 | 449 | (deftest close-on-exception-tests |
453 | (testing "threads" | |
454 | (is (nil? (<!! (thread (assert false "This exception is expected"))))) | |
455 | (is (nil? (<!! (thread (alts!! [(identity-chan 42)]) | |
456 | (assert false "This exception is expected")))))) | |
457 | (testing "go blocks" | |
458 | (is (nil? (<!! (go (assert false "This exception is expected"))))) | |
459 | (is (nil? (<!! (go (alts! [(identity-chan 42)]) | |
460 | (assert false "This exception is expected"))))))) | |
450 | (let [eh (Thread/getDefaultUncaughtExceptionHandler) | |
451 | msg "This exception is expected"] | |
452 | (try | |
453 | ;; don't spam stderr | |
454 | (Thread/setDefaultUncaughtExceptionHandler | |
455 | (reify java.lang.Thread$UncaughtExceptionHandler | |
456 | (uncaughtException [_ _thread _throwable]))) | |
457 | (testing "threads" | |
458 | (is (nil? (<!! (thread (assert false msg))))) | |
459 | (is (nil? (<!! (thread (alts!! [(identity-chan 42)]) | |
460 | (assert false msg)))))) | |
461 | (testing "go blocks" | |
462 | (is (nil? (<!! (go (assert false msg))))) | |
463 | (is (nil? (<!! (go (alts! [(identity-chan 42)]) | |
464 | (assert false msg)))))) | |
465 | (finally | |
466 | ;; restore | |
467 | (Thread/setDefaultUncaughtExceptionHandler eh))))) | |
461 | 468 | |
462 | 469 | (deftest resolution-tests |
463 | 470 | (let [<! (constantly 42)] |
504 | 511 | |
505 | 512 | (deftest ASYNC-186 |
506 | 513 | (is (let [y nil] (go)))) |
514 | ||
515 | (deftest ASYNC-198 | |
516 | (let [resp (runner | |
517 | (try | |
518 | (let [[r] (try | |
519 | (let [value (pause :any)] | |
520 | (throw (ex-info "Exception" {:type :inner}))) | |
521 | (catch Throwable e | |
522 | [:outer-ok]) | |
523 | (finally))] | |
524 | (throw (ex-info "Throwing outer exception" {:type :outer}))) | |
525 | (catch clojure.lang.ExceptionInfo ex | |
526 | (is (= (:outer (:type (ex-data ex))))) | |
527 | :ok) | |
528 | (catch UnsupportedOperationException ex | |
529 | :unsupported)))] | |
530 | (is (= :ok resp)))) | |
531 | ||
532 | (deftest ASYNC-212 | |
533 | (is (= 42 | |
534 | (<!! (go | |
535 | (let [a nil | |
536 | foo (identity a)] | |
537 | (if foo | |
538 | (<! foo) | |
539 | 42))))))) | |
540 | ||
541 | ;; The park/park-run/park-runner api is similar to the pause | |
542 | ;; counterpart above, but it actually parks the state machine so you | |
543 | ;; can test parking and unparking machines in different environments. | |
544 | (defn park [x] | |
545 | x) | |
546 | ||
547 | (defn park-run [state blk val] | |
548 | (ioc/aset-all! state ioc/STATE-IDX blk ioc/VALUE-IDX val) | |
549 | nil) | |
550 | ||
551 | (defmacro park-runner | |
552 | [& body] | |
553 | (let [terminators {`park `park-run} | |
554 | crossing-env (zipmap (keys &env) (repeatedly gensym))] | |
555 | `(let [captured-bindings# (clojure.lang.Var/getThreadBindingFrame) | |
556 | ~@(mapcat (fn [[l sym]] [sym `(^:once fn* [] ~(vary-meta l dissoc :tag))]) crossing-env) | |
557 | state# (~(ioc/state-machine | |
558 | `(do ~@body) | |
559 | 0 | |
560 | [crossing-env &env] | |
561 | terminators))] | |
562 | (ioc/aset-all! state# | |
563 | ~ioc/BINDINGS-IDX | |
564 | captured-bindings#) | |
565 | (ioc/run-state-machine state#) | |
566 | [state# (ioc/aget-object state# ioc/VALUE-IDX)]))) | |
567 | ||
568 | (deftest test-binding | |
569 | (let [results (atom {}) | |
570 | exception (atom nil)] | |
571 | ;; run the machine on another thread without any existing binding frames. | |
572 | (doto (Thread. | |
573 | (fn [] | |
574 | (try | |
575 | (let [[state result] (park-runner (binding [*1 2] (park 10) 100))] | |
576 | (ioc/run-state-machine state) | |
577 | ;; the test is macro relies on binding to convey | |
578 | ;; results, but we want a pristine binding | |
579 | ;; environment on this thread, so use an atom to | |
580 | ;; report results back to the main thread. | |
581 | (reset! results {:park-value result :final-value (ioc/aget-object state ioc/VALUE-IDX)})) | |
582 | (catch Throwable t | |
583 | (reset! exception t))))) | |
584 | (.start) | |
585 | (.join)) | |
586 | (is (= 10 (:park-value @results))) | |
587 | (is (= 100 (:final-value @results))) | |
588 | (is (if @exception (throw @exception) true)))) |
0 | (ns clojure.core.async.mutex-test | |
1 | (:use clojure.test) | |
2 | (:import (clojure.core.async Mutex))) | |
3 | ||
4 | (deftest mutex-test | |
5 | (let [lock (Mutex.)] | |
6 | (.lock lock) | |
7 | (try | |
8 | ;; do stuff | |
9 | (finally | |
10 | (.unlock lock))))) |
188 | 188 | (deftest ops-tests |
189 | 189 | (testing "map<" |
190 | 190 | (is (= [2 3 4 5] |
191 | (<!! (a/into [] (a/map< inc (a/to-chan [1 2 3 4]))))))) | |
191 | (<!! (a/into [] (a/map< inc (a/to-chan! [1 2 3 4]))))))) | |
192 | 192 | (testing "map>" |
193 | 193 | (is (= [2 3 4 5] |
194 | 194 | (let [out (chan) |
195 | 195 | in (a/map> inc out)] |
196 | (a/onto-chan in [1 2 3 4]) | |
196 | (a/onto-chan! in [1 2 3 4]) | |
197 | 197 | (<!! (a/into [] out)))))) |
198 | 198 | (testing "filter<" |
199 | 199 | (is (= [2 4 6] |
200 | (<!! (a/into [] (a/filter< even? (a/to-chan [1 2 3 4 5 6]))))))) | |
200 | (<!! (a/into [] (a/filter< even? (a/to-chan! [1 2 3 4 5 6]))))))) | |
201 | 201 | (testing "remove<" |
202 | 202 | (is (= [1 3 5] |
203 | (<!! (a/into [] (a/remove< even? (a/to-chan [1 2 3 4 5 6]))))))) | |
203 | (<!! (a/into [] (a/remove< even? (a/to-chan! [1 2 3 4 5 6]))))))) | |
204 | ||
205 | (testing "to-chan" | |
206 | (is (= (range 10) | |
207 | (<!! (a/into [] (a/to-chan (range 10)))))) | |
208 | (is (= (range 10) | |
209 | (<!! (a/into [] (a/to-chan! (range 10)))))) | |
210 | (is (= (range 10) | |
211 | (<!! (a/into [] (a/to-chan!! (range 10))))))) | |
204 | 212 | |
205 | 213 | (testing "onto-chan" |
206 | (is (= (range 10) | |
207 | (<!! (a/into [] (a/to-chan (range 10))))))) | |
214 | (let [ch (chan 10)] | |
215 | (a/onto-chan ch (range 10)) | |
216 | (is (= (range 10) (<!! (a/into [] ch))))) | |
217 | (let [ch (chan 10)] | |
218 | (a/onto-chan! ch (range 10)) | |
219 | (is (= (range 10) (<!! (a/into [] ch))))) | |
220 | (let [ch (chan 10)] | |
221 | (a/onto-chan!! ch (range 10)) | |
222 | (is (= (range 10) (<!! (a/into [] ch)))))) | |
208 | 223 | |
209 | 224 | (testing "filter>" |
210 | 225 | (is (= [2 4 6] |
211 | 226 | (let [out (chan) |
212 | 227 | in (filter> even? out)] |
213 | (a/onto-chan in [1 2 3 4 5 6]) | |
228 | (a/onto-chan! in [1 2 3 4 5 6]) | |
214 | 229 | (<!! (a/into [] out)))))) |
215 | 230 | (testing "remove>" |
216 | 231 | (is (= [1 3 5] |
217 | 232 | (let [out (chan) |
218 | 233 | in (remove> even? out)] |
219 | (a/onto-chan in [1 2 3 4 5 6]) | |
234 | (a/onto-chan! in [1 2 3 4 5 6]) | |
220 | 235 | (<!! (a/into [] out)))))) |
221 | 236 | (testing "mapcat<" |
222 | 237 | (is (= [0 0 1 0 1 2] |
223 | 238 | (<!! (a/into [] (mapcat< range |
224 | (a/to-chan [1 2 3]))))))) | |
239 | (a/to-chan! [1 2 3]))))))) | |
225 | 240 | (testing "mapcat>" |
226 | 241 | (is (= [0 0 1 0 1 2] |
227 | 242 | (let [out (chan) |
228 | 243 | in (mapcat> range out)] |
229 | (a/onto-chan in [1 2 3]) | |
244 | (a/onto-chan! in [1 2 3]) | |
230 | 245 | (<!! (a/into [] out)))))) |
231 | 246 | |
232 | 247 | |
233 | 248 | (testing "pipe" |
234 | 249 | (is (= [1 2 3 4 5] |
235 | 250 | (let [out (chan)] |
236 | (pipe (a/to-chan [1 2 3 4 5]) | |
251 | (pipe (a/to-chan! [1 2 3 4 5]) | |
237 | 252 | out) |
238 | 253 | (<!! (a/into [] out)))))) |
239 | 254 | (testing "split" |
240 | 255 | ;; Must provide buffers for channels else the tests won't complete |
241 | (let [[even odd] (a/split even? (a/to-chan [1 2 3 4 5 6]) 5 5)] | |
256 | (let [[even odd] (a/split even? (a/to-chan! [1 2 3 4 5 6]) 5 5)] | |
242 | 257 | (is (= [2 4 6] |
243 | 258 | (<!! (a/into [] even)))) |
244 | 259 | (is (= [1 3 5] |
245 | 260 | (<!! (a/into [] odd)))))) |
246 | 261 | (testing "map" |
247 | 262 | (is (= [0 4 8 12] |
248 | (<!! (a/into [] (a/map + [(a/to-chan (range 4)) | |
249 | (a/to-chan (range 4)) | |
250 | (a/to-chan (range 4)) | |
251 | (a/to-chan (range 4))])))))) | |
263 | (<!! (a/into [] (a/map + [(a/to-chan! (range 4)) | |
264 | (a/to-chan! (range 4)) | |
265 | (a/to-chan! (range 4)) | |
266 | (a/to-chan! (range 4))])))))) | |
252 | 267 | (testing "merge" |
253 | 268 | ;; merge uses alt, so results can be in any order, we're using |
254 | 269 | ;; frequencies as a way to make sure we get the right result. |
256 | 271 | 1 4 |
257 | 272 | 2 4 |
258 | 273 | 3 4} |
259 | (frequencies (<!! (a/into [] (a/merge [(a/to-chan (range 4)) | |
260 | (a/to-chan (range 4)) | |
261 | (a/to-chan (range 4)) | |
262 | (a/to-chan (range 4))]))))))) | |
274 | (frequencies (<!! (a/into [] (a/merge [(a/to-chan! (range 4)) | |
275 | (a/to-chan! (range 4)) | |
276 | (a/to-chan! (range 4)) | |
277 | (a/to-chan! (range 4))]))))))) | |
263 | 278 | |
264 | 279 | (testing "mult" |
265 | 280 | (let [a (chan 4) |
268 | 283 | m (mult src)] |
269 | 284 | (tap m a) |
270 | 285 | (tap m b) |
271 | (pipe (a/to-chan (range 4)) src) | |
286 | (pipe (a/to-chan! (range 4)) src) | |
272 | 287 | (is (= [0 1 2 3] |
273 | 288 | (<!! (a/into [] a)))) |
274 | 289 | (is (= [0 1 2 3] |
275 | (<!! (a/into [] b)))))) | |
276 | ||
290 | (<!! (a/into [] b))))) | |
291 | ||
292 | ;; ASYNC-127 | |
293 | (let [ch (to-chan! [1 2 3]) | |
294 | m (mult ch) | |
295 | t-1 (chan) | |
296 | t-2 (chan) | |
297 | t-3 (chan)] | |
298 | (tap m t-1) | |
299 | (tap m t-2) | |
300 | (tap m t-3) | |
301 | (close! t-3) | |
302 | (is (= 1 (<!! t-1))) | |
303 | (is (= nil (a/poll! t-1))) ;; t-2 hasn't taken yet | |
304 | (is (= 1 (<!! t-2))) | |
305 | (is (= 2 (<!! t-1))) ;; now available | |
306 | (is (= nil (a/poll! t-1))))) | |
277 | 307 | |
278 | 308 | (testing "mix" |
279 | 309 | (let [out (chan) |
280 | 310 | mx (mix out)] |
281 | (admix mx (a/to-chan [1 2 3])) | |
282 | (admix mx (a/to-chan [4 5 6])) | |
311 | (admix mx (a/to-chan! [1 2 3])) | |
312 | (admix mx (a/to-chan! [4 5 6])) | |
283 | 313 | |
284 | 314 | (is (= #{1 2 3 4 5 6} |
285 | (<!! (a/into #{} (a/take 6 out))))))) | |
315 | (<!! (a/into #{} (a/take 6 out)))))) | |
316 | ||
317 | ;; ASYNC-145 | |
318 | (let [out (chan 2500) | |
319 | mix (mix out)] | |
320 | (dotimes [i 2048] | |
321 | (let [c (chan)] | |
322 | (admix mix c) | |
323 | (put! c i))) | |
324 | ||
325 | (is (= (set (range 2048)) | |
326 | (<!! (a/into #{} (a/take 2048 out))))))) | |
286 | 327 | |
287 | 328 | (testing "pub-sub" |
288 | 329 | (let [a-ints (chan 5) |
298 | 339 | (sub p :string b-strs) |
299 | 340 | (sub p :int a-ints) |
300 | 341 | (sub p :int b-ints) |
301 | (pipe (a/to-chan [1 "a" 2 "b" 3 "c"]) src) | |
342 | (pipe (a/to-chan! [1 "a" 2 "b" 3 "c"]) src) | |
302 | 343 | (is (= [1 2 3] |
303 | 344 | (<!! (a/into [] a-ints)))) |
304 | 345 | (is (= [1 2 3] |
310 | 351 | |
311 | 352 | (testing "unique" |
312 | 353 | (is (= [1 2 3 4] |
313 | (<!! (a/into [] (a/unique (a/to-chan [1 1 2 2 3 3 3 3 4]))))))) | |
354 | (<!! (a/into [] (a/unique (a/to-chan! [1 1 2 2 3 3 3 3 4]))))))) | |
314 | 355 | |
315 | 356 | (testing "partition" |
316 | 357 | (is (= [[1 2] [2 3]] |
317 | (<!! (a/into [] (a/partition 2 (a/to-chan [1 2 2 3]))))))) | |
358 | (<!! (a/into [] (a/partition 2 (a/to-chan! [1 2 2 3]))))))) | |
318 | 359 | (testing "partition-by" |
319 | 360 | (is (= [["a" "b"] [1 :2 3] ["c"]] |
320 | (<!! (a/into [] (a/partition-by string? (a/to-chan ["a" "b" 1 :2 3 "c"]))))))) | |
361 | (<!! (a/into [] (a/partition-by string? (a/to-chan! ["a" "b" 1 :2 3 "c"]))))))) | |
321 | 362 | |
322 | 363 | (testing "reduce" |
323 | (is (= 0 (<!! (a/reduce + 0 (a/to-chan []))))) | |
324 | (is (= 45 (<!! (a/reduce + 0 (a/to-chan (range 10)))))) | |
325 | (is (= :foo (<!! (a/reduce #(if (= %2 2) (reduced :foo) %1) 0 (a/to-chan (range 10))))))) | |
364 | (is (= 0 (<!! (a/reduce + 0 (a/to-chan! []))))) | |
365 | (is (= 45 (<!! (a/reduce + 0 (a/to-chan! (range 10)))))) | |
366 | (is (= :foo (<!! (a/reduce #(if (= %2 2) (reduced :foo) %1) 0 (a/to-chan! (range 10))))))) | |
326 | 367 | ) |
327 | 368 | |
328 | 369 | ;; transducer yielding n copies of each input value |
353 | 394 | (take! c #(do |
354 | 395 | (when (some? %) (swap! res conj %)) |
355 | 396 | (swap! counter inc)))) |
356 | (onto-chan c input) | |
397 | (onto-chan! c input) | |
357 | 398 | |
358 | 399 | ;; wait for all takers to report |
359 | 400 | (while (< @counter takers) |
367 | 408 | (doseq [b (range 1 10) |
368 | 409 | t (range 1 10)] |
369 | 410 | (check-expanding-transducer b 3 3 t))) |
411 | ||
412 | (deftest expanding-transducer-puts-can-ignore-buffer-fullness | |
413 | (testing "non-blocking puts behave as expected" | |
414 | ;; put coll, expanding xf, | |
415 | (let [c (chan 1 (mapcat identity))] | |
416 | (is (true? (>!! c [1 2 3]))) | |
417 | (is (= 1 (<!! c))) | |
418 | (is (nil? (offer! c [4 5 6]))) | |
419 | (is (= 2 (<!! c))) | |
420 | (is (= 3 (<!! c))) | |
421 | (is (true? (offer! c [4 5 6]))))) | |
422 | ||
423 | (testing "blocking puts can execute during takes even when the buffer is full" | |
424 | (let [c (chan 1 (mapcat identity))] | |
425 | (is (true? (>!! c [1 2 3]))) | |
426 | (is (= 1 (<!! c))) | |
427 | (is (nil? (offer! c [4 5 6]))) | |
428 | (let [counter (atom 0) | |
429 | blocking-put (future (let [r (>!! c [4 5 6])] | |
430 | (swap! counter inc) | |
431 | r))] | |
432 | (is (= 0 @counter)) | |
433 | (is (= 2 (<!! c))) | |
434 | ||
435 | ;; don't allow puts, buffer still full | |
436 | (is (false? (deref blocking-put 10 false))) | |
437 | (is (= 0 @counter)) | |
438 | ||
439 | (is (nil? (offer! c [7 8 9]))))))) | |
370 | 440 | |
371 | 441 | ;; in 1.7+, use (map f) |
372 | 442 | (defn mapping [f] |
381 | 451 | |
382 | 452 | (deftest test-transduce |
383 | 453 | (is (= [1 2 3 4 5] |
384 | (<!! (a/transduce (mapping inc) conj [] (a/to-chan (range 5)))))))⏎ | |
454 | (<!! (a/transduce (mapping inc) conj [] (a/to-chan! (range 5))))))) |
0 | 0 | (ns clojure.core.pipeline-test |
1 | 1 | (:require [clojure.test :refer (deftest is are)] |
2 | [clojure.core.async :as a :refer [<! >! <!! >!! go go-loop thread chan close! to-chan | |
2 | [clojure.core.async :as a :refer [<! >! <!! >!! go go-loop thread chan close! to-chan! | |
3 | 3 | pipeline pipeline-blocking pipeline-async]])) |
4 | 4 | |
5 | 5 | ;; in Clojure 1.7, use (map f) instead of this |
14 | 14 | (f1 result (apply f input inputs)))))) |
15 | 15 | |
16 | 16 | (defn pipeline-tester [pipeline-fn n inputs xf] |
17 | (let [cin (to-chan inputs) | |
17 | (let [cin (to-chan! inputs) | |
18 | 18 | cout (chan 1)] |
19 | 19 | (pipeline-fn n cout xf cin) |
20 | 20 | (<!! (go-loop [acc []] |
42 | 42 | (deftest test-close? |
43 | 43 | (doseq [pf [pipeline pipeline-blocking]] |
44 | 44 | (let [cout (chan 1)] |
45 | (pf 5 cout identity-mapping (to-chan [1]) true) | |
45 | (pf 5 cout identity-mapping (to-chan! [1]) true) | |
46 | 46 | (is (= 1 (<!! cout))) |
47 | 47 | (is (= nil (<!! cout)))) |
48 | 48 | (let [cout (chan 1)] |
49 | (pf 5 cout identity-mapping (to-chan [1]) false) | |
49 | (pf 5 cout identity-mapping (to-chan! [1]) false) | |
50 | 50 | (is (= 1 (<!! cout))) |
51 | 51 | (>!! cout :more) |
52 | 52 | (is (= :more (<!! cout)))) |
53 | 53 | (let [cout (chan 1)] |
54 | (pf 5 cout identity-mapping (to-chan [1]) nil) | |
54 | (pf 5 cout identity-mapping (to-chan! [1]) nil) | |
55 | 55 | (is (= 1 (<!! cout))) |
56 | 56 | (>!! cout :more) |
57 | 57 | (is (= :more (<!! cout)))))) |
62 | 62 | chex (chan 1) |
63 | 63 | ex-mapping (mapping (fn [x] (if (= x 3) (throw (ex-info "err" {:data x})) x))) |
64 | 64 | ex-handler (fn [e] (do (>!! chex e) :err))] |
65 | (pf 5 cout ex-mapping (to-chan [1 2 3 4]) true ex-handler) | |
65 | (pf 5 cout ex-mapping (to-chan! [1 2 3 4]) true ex-handler) | |
66 | 66 | (is (= 1 (<!! cout))) |
67 | 67 | (is (= 2 (<!! cout))) |
68 | 68 | (is (= :err (<!! cout))) |