Codebase list core-async-clojure / 66303a4
New upstream version 1.3.610 Louis-Philippe Véronneau 3 years ago
44 changed file(s) with 1808 addition(s) and 955 deletion(s). Raw diff Collapse all Expand all
1717 tests.js
1818 tests.js.map
1919 pom.xml.versionsBackup
20 .cpcache/
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
44
55 ## Releases and Dependency Information
66
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
810
911 * [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 ```
1018
1119 [Leiningen](https://github.com/technomancy/leiningen) dependency information:
1220
1321 ```clj
14 [org.clojure/clojure "1.6.0"]
15 [org.clojure/core.async "0.3.442"]
22 [org.clojure/core.async "1.2.603"]
1623 ```
1724
1825 [Maven](http://maven.apache.org/) dependency information:
2128 <dependency>
2229 <groupId>org.clojure</groupId>
2330 <artifactId>core.async</artifactId>
24 <version>0.3.442</version>
31 <version>1.2.603</version>
2532 </dependency>
2633 ```
2734
2835 ## Documentation
2936
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/)
3239 * [Code walkthrough](https://github.com/clojure/core.async/blob/master/examples/walkthrough.clj)
3340
3441 ## Presentations
3643 * [Rich Hickey on core.async](http://www.infoq.com/presentations/clojure-core-async)
3744 * [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)).
3845 * 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)
4046
4147 ## Contributing
4248
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.
4450
4551 To run the ClojureScript tests:
4652
5056
5157 ## License
5258
53 Copyright © 2017 Rich Hickey and contributors
59 Copyright © 2017-2020 Rich Hickey and contributors
5460
5561 Distributed under the Eclipse Public License, the same as Clojure.
5662
5763 ## Changelog
5864
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
61112 * Release 0.3.442 on 2017.03.14
62113 * Fix bad `:refer-clojure` clause that violates new spec in Clojure 1.9.0-alpha15
63114 * 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
68119 * 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
76127 * Update tools.analyzer.jvm dependency
77128 * Release 0.2.395 on 2016.10.12
78129 * Add async version of transduce
84135 * Release 0.2.382 on 2016.06.13
85136 * Important: Change default dispatch thread pool size to 8.
86137 * 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
88139 * 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
90141 * Updated tools.analyzer.jvm version (and other upstream deps)
91142 * Updated to latest clojurescript and cljsbuild versions
92143 * 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
99150 * Support (try (catch :default)) in CLJS exception handling
100151 * Use cljs.test
101152 * Updated tools.analyzer.jvm version (and other upstream deps)
0 0.3.GENERATED_VERSION
0 1.3.GENERATED_VERSION
0 {:paths ["src/main/clojure"]
1 :deps
2 {org.clojure/tools.analyzer.jvm {:mvn/version "1.1.0"}}}
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 (&quot;AGREEMENT&quot;). 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>&quot;Contribution&quot; 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>&quot;Contributor&quot; means any person or entity that distributes
55 the Program.</p>
56
57 <p>&quot;Licensed Patents&quot; 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>&quot;Program&quot; means the Contributions distributed in accordance
62 with this Agreement.</p>
63
64 <p>&quot;Recipient&quot; 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 (&quot;Commercial Contributor&quot;) hereby agrees to defend and
157 indemnify every other Contributor (&quot;Indemnified Contributor&quot;)
158 against any losses, damages and costs (collectively &quot;Losses&quot;)
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 &quot;AS IS&quot; 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
-261
epl.html less more
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 (&quot;AGREEMENT&quot;). 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>&quot;Contribution&quot; 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>&quot;Contributor&quot; means any person or entity that distributes
55 the Program.</p>
56
57 <p>&quot;Licensed Patents&quot; 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>&quot;Program&quot; means the Contributions distributed in accordance
62 with this Agreement.</p>
63
64 <p>&quot;Recipient&quot; 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 (&quot;Commercial Contributor&quot;) hereby agrees to defend and
157 indemnify every other Contributor (&quot;Indemnified Contributor&quot;)
158 against any losses, damages and costs (collectively &quot;Losses&quot;)
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 &quot;AS IS&quot; 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>
22 <groupId>org.clojure</groupId>
33 <artifactId>core.async</artifactId>
44 <!-- Don't set this manually! Call script/build/update_version -->
5 <version>0.3.443</version>
5 <version>1.3.610</version>
66 <packaging>jar</packaging>
77 <name>core.async</name>
88 <description>Facilities for async programming and communication in Clojure</description>
1919 <parent>
2020 <groupId>org.clojure</groupId>
2121 <artifactId>pom.contrib</artifactId>
22 <version>0.2.2</version>
22 <version>1.0.0</version>
2323 </parent>
2424
2525 <scm>
2626 <connection>scm:git:git://github.com/clojure/core.async.git</connection>
2727 <developerConnection>scm:git:git@github.com:clojure/core.async.git</developerConnection>
2828 <url>https://github.com/clojure/core.async</url>
29 <tag>core.async-0.3.443</tag>
29 <tag>core.async-1.3.610</tag>
3030 </scm>
3131
3232 <properties>
33 <clojure.version>1.7.0</clojure.version>
33 <clojure.version>1.9.0</clojure.version>
3434 </properties>
3535
3636 <dependencies>
3737 <dependency>
3838 <groupId>org.clojure</groupId>
3939 <artifactId>clojurescript</artifactId>
40 <version>0.0-2311</version>
40 <version>1.10.597</version>
4141 <scope>provided</scope>
4242 </dependency>
4343 <dependency>
4444 <groupId>org.clojure</groupId>
4545 <artifactId>tools.analyzer.jvm</artifactId>
46 <version>0.7.0</version>
46 <version>1.1.0</version>
4747 </dependency>
4848 </dependencies>
4949
5050 <build>
51 <sourceDirectory>src/main/clojure</sourceDirectory>
5152 <plugins>
5253 <plugin>
5354 <groupId>org.codehaus.mojo</groupId>
5455 <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>
5680 </plugin>
5781 </plugins>
5882 </build>
22 :url "https://github.com/clojure/core.async"
33 :license {:name "Eclipse Public License"
44 :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"]]
99 :global-vars {*warn-on-reflection* true}
1010 :source-paths ["src/main/clojure"]
1111 :test-paths ["src/test/clojure"]
1313 :java-source-paths ["src/main/java"]
1414 :profiles {:dev {:source-paths ["examples"]}}
1515
16 :plugins [[lein-cljsbuild "1.1.2"]]
16 :plugins [[lein-cljsbuild "1.1.7"]]
1717
1818 :clean-targets ["tests.js" "tests.js.map"
1919 "out" "out-simp" "out-simp-node"
7979 (deftype FixedBuffer [buf n]
8080 impl/Buffer
8181 (full? [this]
82 (== (.-length buf) n))
82 (>= (.-length buf) n))
8383 (remove! [this]
8484 (.pop buf))
8585 (add!* [this itm]
4242 (impl/close! this))
4343 impl/WritePort
4444 (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")
4646 ;; bug in CLJS compiler boolean inference - David
4747 (let [^boolean closed closed]
4848 (if (or closed (not ^boolean (impl/active? handler)))
9696 (do
9797 (if-let [take-cb (impl/commit handler)]
9898 (let [val (impl/remove! buf)
99 [done? cbs] (when (pos? (.-length puts))
99 [done? cbs] (when (and (not (impl/full? buf)) (pos? (.-length puts)))
100100 (loop [cbs []]
101101 (let [putter (.pop puts)
102102 ^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
08 (ns cljs.core.async.impl.dispatch
19 (:require [cljs.core.async.impl.buffers :as buffers]
210 [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
08 (ns cljs.core.async.impl.ioc-helpers
19 (:require [cljs.core.async.impl.protocols :as impl])
210 (:require-macros [cljs.core.async.impl.ioc-macros :as ioc]))
6472 (impl/close! c)
6573 c))
6674
67 (defrecord ExceptionFrame [catch-block
68 ^Class catch-exception
69 finally-block
70 continue-block
71 prev])
7275
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")))))
344344 :recur)))
345345
346346
347 (defrecord Try [catch-block catch-exception finally-block continue-block]
347 (defrecord PushTry [catch-block]
348348 IInstruction
349349 (reads-from [this] [])
350350 (writes-to [this] [])
351 (block-references [this] [catch-block finally-block continue-block])
351 (block-references [this] [catch-block])
352352 IEmittableInstruction
353353 (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] [])
363359 (writes-to [this] [])
364360 (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))
365370 ITerminator
366371 (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 []
374387 IInstruction
375388 (reads-from [this] [])
376389 (writes-to [this] [])
377390 (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#))]))
383395
384396
385397 ;; Dispatch clojure forms based on data type
411423 inst-id (add-instruction (->Call args-ids))]
412424 inst-id))
413425
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
414435 (defn let-binding-to-ssa
415436 [[sym bind]]
416437 (gen-plan
417 [bind-id (item-to-ssa bind)
438 [bind-id (local-init-to-ssa bind)
418439 _ (push-alter-binding :locals assoc sym bind-id)]
419440 bind-id))
420441
438459 [local-val-ids (all (map ; parallel bind
439460 (fn [sym init]
440461 (gen-plan
441 [itm-id (item-to-ssa init)
462 [itm-id (local-init-to-ssa init)
442463 _ (push-alter-binding :locals assoc sym itm-id)]
443464 itm-id))
444465 syms
550571 ret-id (add-instruction (->Dot target-id method args-ids))]
551572 ret-id)))
552573
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
553602 (defmethod sexpr-to-ssa 'try
554603 [[_ & 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)]
562605 (gen-plan
563 [end-blk (add-block)
606 [body-block (add-block)
607 exit-block (add-block)
564608 finally-blk (if finally
565609 (gen-plan
566610 [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))
572619 _ (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))
596650 (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)
599658 ret (add-instruction (->Const ::value))]
600659 ret)))
601660
722781 (fn [p]
723782 [(locals x) p])
724783 (fn [p]
725 [x p])
726 #_(add-instruction (->Const x)))]
784 [(vary-meta x assoc ::global true) p]))]
727785 inst-id))
728786
729787 (defmethod -item-to-ssa :map
857915 (if (cljs.core/keyword-identical? result# :recur)
858916 (recur)
859917 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#))
863924 :recur))]
864925 (if (cljs.core/keyword-identical? ret-value# :recur)
865926 (recur ~state-sym)
4545 ([x k level update]
4646 (if-not (neg? level)
4747 (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))]
4950 (if (< (.-key x') k)
5051 (recur x')
5152 x)
7576 (when (<= i level)
7677 (let [links (.-forward (aget update i))]
7778 (aset (.-forward x) i (aget links i))
78 (aset links i x)))))))))
79 (aset links i x))
80 (recur (inc i)))))))))
7981
8082 (remove [coll k]
8183 (let [update (make-array MAX_LEVEL)
8284 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))]
8487 (when (and (not (nil? x)) (== (.-key x) k))
8588 (loop [i 0]
8689 (when (<= i level)
8790 (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)))
8993 (do
9094 (aset links i (aget (.-forward x) i))
9195 (recur (inc i)))
9296 (recur (inc i))))))
93 (while (and (> level 0)
97 (while (and (< 0 level (alength (.-forward header)))
9498 (nil? (aget (.-forward header) level)))
9599 (set! level (dec level))))))
96100
98102 (loop [x header level level]
99103 (if-not (neg? level)
100104 (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
107114 (recur nx (dec level))
108115 (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
112120 (floorEntry [coll k]
113121 (loop [x header level level]
114122 (if-not (neg? level)
115123 (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))]
117126 (if-not (nil? x')
118127 (if (> (.-key x') k)
119128 x
163172 (impl/close! timeout-channel))
164173 msecs)
165174 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
08 (ns cljs.core.async.macros
1 (:require [cljs.core.async.impl.ioc-macros :as ioc]))
9 (:require [cljs.core.async :as async]))
210
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)))))
1020
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)
2223
24 (def go-loop #'async/go-loop)
25 (setup-macro-shim #'async/go-loop #'go-loop)
2326
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
08 (ns cljs.core.async
19 (:refer-clojure :exclude [reduce transduce into merge map take partition partition-by])
210 (:require [cljs.core.async.impl.protocols :as impl]
412 [cljs.core.async.impl.buffers :as buffers]
513 [cljs.core.async.impl.timers :as timers]
614 [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])
817 (: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]]))
1019
1120 (defn- fn-handler
1221 ([f] (fn-handler f true))
112121 (throw (js/Error. ">! used not in (go ...) block")))
113122
114123 (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
116125 complete. nil values are not allowed. Will throw if closed. If
117126 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."
119128 ([port val]
120129 (if-let [ret (impl/put! port val fhnop)]
121130 @ret
139148 [n]
140149 (let [a (make-array n)]
141150 (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))
151154
152155 (defn- alt-flag []
153156 (let [flag (atom true)]
171174 (defn do-alts
172175 "returns derefable [val port] if immediate, nil if enqueued"
173176 [fret ports opts]
177 (assert (pos? (count ports)) "alts must have at least one channel operation")
174178 (let [flag (alt-flag)
175179 n (count ports)
176180 idxs (random-array n)
381385 (let [ret (<! (reduce f init ch))]
382386 (f ret)))))
383387
384 (defn onto-chan
388 (defn onto-chan!
385389 "Puts the contents of coll into the supplied channel.
386390
387391 By default the channel will be closed after the items are copied,
388392 but can be determined by the close? parameter.
389393
390394 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))
392396 ([ch coll close?]
393397 (go-loop [vs (seq coll)]
394398 (if (and vs (>! ch (first vs)))
397401 (close! ch))))))
398402
399403
400 (defn to-chan
404 (defn to-chan!
401405 "Creates and returns a channel which contains the contents of coll,
402406 closing when exhausted."
403407 [coll]
404408 (let [ch (chan (bounded-count 100 coll))]
405 (onto-chan ch coll)
409 (onto-chan! ch coll)
406410 ch))
407411
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))
408423
409424 (defprotocol Mux
410425 (muxch* [_]))
449464 (reset! dctr (count chs))
450465 (doseq [c chs]
451466 (when-not (put! c val done)
452 (done nil)
453467 (untap* m c)))
454468 ;;wait for all
455469 (when (seq chs)
516530 solo-modes #{:mute :pause}
517531 attrs (conj solo-modes :solo)
518532 solo-mode (atom :mute)
519 change (chan)
533 change (chan (sliding-buffer 1))
520534 changed #(put! change true)
521535 pick (fn [attr chs]
522536 (reduce-kv
5151 [this]
5252 (let [iter (.iterator puts)]
5353 (when (.hasNext iter)
54 (loop [^Lock putter (.next iter)]
54 (loop [[^Lock putter] (.next iter)]
5555 (.lock putter)
5656 (let [put-cb (and (impl/active? putter) (impl/commit putter))]
5757 (.unlock putter)
174174 (let [val (impl/remove! buf)
175175 iter (.iterator puts)
176176 [done? cbs]
177 (when (.hasNext iter)
177 (when (and (not (impl/full? buf)) (.hasNext iter))
178178 (loop [cbs []
179179 [^Lock putter val] (.next iter)]
180180 (.lock putter)
299299 (add! buf val)
300300 (catch Throwable t
301301 (handle buf exh t)))))))))
302
1414 (defn counted-thread-factory
1515 "Create a ThreadFactory that maintains a counter for naming Threads.
1616 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))))))))
2634
2735 (defonce
2836 ^{:doc "Number of processors reported by the JVM"}
1212
1313 (set! *warn-on-reflection* true)
1414
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"))))
1630
1731 (defn run
1832 "Runs Runnable r in a thread pool thread"
1616 "Value is set via clojure.core.async.pool-size system property; defaults to 8; uses a
1717 delay so property can be set from code after core.async namespace is loaded but before
1818 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)))
2220
2321 (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))))))
3535 (def ^:const VALUE-IDX 2)
3636 (def ^:const BINDINGS-IDX 3)
3737 (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)
4039
4140 (defn aset-object [^AtomicReferenceArray arr idx ^Object o]
4241 (.set arr idx o))
226225 (defrecord RawCode [ast locals]
227226 IInstruction
228227 (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)))
231231 (writes-to [this] [(:id this)])
232232 (block-references [this] [])
233233 IEmittableInstruction
236236 `[~@(->> (-> ast :env :locals vals)
237237 (map #(select-keys % [:op :name :form]))
238238 (filter (fn [local]
239 (when locals
240 (get locals (:name local)))))
239 (contains? locals (:name local))))
241240 set
242241 (mapcat
243242 (fn [local]
412411 (terminate-block [this state-sym _]
413412 (let [ex (gensym 'ex)]
414413 `(let [~ex (aget-object ~state-sym ~VALUE-IDX)]
415 (aset-all! ~state-sym ~CURRENT-EXCEPTION ~ex)
416414 (cond
417415 ~@(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)]]
421417 i)
422418 :else (throw ~ex))
423419 :recur))))
424420
425 (defrecord EndFinally []
426 IInstruction
427 (reads-from [this] [])
421 (defrecord EndFinally [exception-local]
422 IInstruction
423 (reads-from [this] [exception-local])
428424 (writes-to [this] [])
429425 (block-references [this] [])
430426 IEmittableInstruction
431427 (emit-instruction [this state-sym]
432 `[~'_ (when-let [e# (aget-object ~state-sym ~CURRENT-EXCEPTION)]
433 (throw e#))]))
428 `[~'_ (throw ~exception-local)]))
434429
435430 ;; Dispatch clojure forms based on :op
436431 (def -item-to-ssa nil) ;; for help in the repl
643638
644639 (defmethod -item-to-ssa :try
645640 [{: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)))
707712
708713 (defmethod -item-to-ssa :throw
709714 [{:keys [exception] :as ast}]
939944 (catch Throwable ex#
940945 (aset-all! ~state-sym ~VALUE-IDX ex#)
941946 (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)))
944948 (throw ex#))
945949 :recur)
946950 (finally
951 (aset-object ~state-sym ~BINDINGS-IDX (clojure.lang.Var/getThreadBindingFrame))
947952 (clojure.lang.Var/resetThreadBindingFrame old-frame#)))]
948953 (if (identical? ret-value# :recur)
949954 (recur ~state-sym)
88 (ns ^{:skip-wiki true}
99 clojure.core.async.impl.mutex
1010 (: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]))
1312
1413 (defn mutex []
1514 (let [m (ReentrantLock.)]
3939 (close! [this]
4040 (impl/close! channel)))
4141
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
5542 (defn- timeout-worker
5643 []
5744 (let [q timeouts-queue]
6249 (recur))))
6350
6451 (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))))
55 ;; the terms of this license.
66 ;; You must not remove this notice, or any other, from this software.
77
8 (ns clojure.core.async.lab
8 (ns ^{:skip-wiki true} clojure.core.async.lab
99 "core.async HIGHLY EXPERIMENTAL feature exploration
1010
1111 Caveats:
104104 strongly advised that each of the underlying ports support buffered
105105 writes."
106106 [& ports]
107 (->BroadcastingWritePort (set ports)))
107 (->BroadcastingWritePort (set ports)))
1010
1111 go blocks are dispatched over an internal thread pool, which
1212 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."
1421 (:refer-clojure :exclude [reduce transduce into merge map take partition
1522 partition-by bounded-count])
1623 (:require [clojure.core.async.impl.protocols :as impl]
2229 [clojure.core.async.impl.mutex :as mutex]
2330 [clojure.core.async.impl.concurrent :as conc]
2431 )
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]
2834 [java.util ArrayList]))
2935
3036 (alias 'core 'clojure.core)
4955 (defn buffer
5056 "Returns a fixed buffer of size n. When full, puts will block/park."
5157 [n]
58 (assert (pos? n) "fixed buffers must have size > 0")
5259 (buffers/fixed-buffer n))
5360
5461 (defn dropping-buffer
8390 ([buf-or-n] (chan buf-or-n nil))
8491 ([buf-or-n xform] (chan buf-or-n xform nil))
8592 ([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"))
8793 (when xform (assert buf-or-n "buffer must be supplied when transducer is"))
8894 (channels/chan (if (number? buf-or-n) (buffer buf-or-n) buf-or-n) xform ex-handler)))
8995
9298 exception-handler. A promise channel can take exactly one value that consumers
9399 will receive. Once full, puts complete but val is dropped (no transfer).
94100 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."
96103 ([] (promise-chan nil))
97104 ([xform] (promise-chan xform nil))
98105 ([xform ex-handler]
103110 [^long msecs]
104111 (timers/timeout msecs))
105112
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 <!!
107125 "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)."
109130 [port]
110131 (let [p (promise)
111132 ret (impl/take! port (fn-handler (fn [v] (deliver p v))))]
123144 "Asynchronously takes a val from port, passing to fn1. Will pass nil
124145 if closed. If on-caller? (default true) is true, and value is
125146 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
126152 Returns nil."
127153 ([port fn1] (take! port fn1 true))
128154 ([port fn1 on-caller?]
134160 (dispatch/run #(fn1 val)))))
135161 nil)))
136162
137 (defn >!!
163 (defblockingop >!!
138164 "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)."
140169 [port val]
141170 (let [p (promise)
142171 ret (impl/put! port val (fn-handler (fn [open?] (deliver p open?))))]
158187 "Asynchronously puts a val into port, calling fn1 (if supplied) when
159188 complete, passing false iff port is already closed. nil values are
160189 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."
163197 ([port val]
164198 (if-let [ret (impl/put! port val fhnop)]
165199 @ret
236270 (defn do-alts
237271 "returns derefable [val port] if immediate, nil if enqueued"
238272 [fret ports opts]
273 (assert (pos? (count ports)) "alts must have at least one channel operation")
239274 (let [flag (alt-flag)
240275 n (count ports)
241276 ^ints idxs (random-array n)
262297 (when got
263298 (channels/box [(:default opts) :default])))))))
264299
265 (defn alts!!
300 (defblockingop alts!!
266301 "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]
270307 (let [p (promise)
271 ret (do-alts (partial deliver p) ports opts)]
308 ret (do-alts (partial deliver p) ports (apply hash-map opts))]
272309 (if ret
273310 @ret
274311 (deref p))))
408445 the only JS thread when in ClojureScript). Upon completion of the
409446 operation, the body will be resumed.
410447
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
411453 Returns a channel which will receive the result of the body when
412454 completed"
413455 [& body]
501543 true)))]
502544 (dotimes [_ n]
503545 (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))))
512550 :async (go-loop []
513551 (let [job (<! jobs)]
514552 (when (async job)
545583 should be used for computational parallelism. If you have multiple
546584 blocking operations to put in flight, use pipeline-blocking instead,
547585 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."
549587 ([n to xf from] (pipeline n to xf from true))
550588 ([n to xf from close?] (pipeline n to xf from close? nil))
551589 ([n to xf from close? ex-handler] (pipeline* n to xf from close? ex-handler :compute)))
630668 (recur (inc i) (next s))
631669 i))))
632670
633 (defn onto-chan
671 (defn onto-chan!
634672 "Puts the contents of coll into the supplied channel.
635673
636674 By default the channel will be closed after the items are copied,
637675 but can be determined by the close? parameter.
638676
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))
641681 ([ch coll close?]
642682 (go-loop [vs (seq coll)]
643683 (if (and vs (>! ch (first vs)))
645685 (when close?
646686 (close! ch))))))
647687
648 (defn to-chan
688 (defn to-chan!
649689 "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"
651693 [coll]
652694 (let [c (bounded-count 100 coll)]
653695 (if (pos? c)
654696 (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)
656735 ch)
657736 (let [ch (chan)]
658737 (close! ch)
701780 (reset! dctr (count chs))
702781 (doseq [c chs]
703782 (when-not (put! c val done)
704 (done nil)
705783 (untap* m c)))
706784 ;;wait for all
707785 (when (seq chs)
757835 solo-modes #{:mute :pause}
758836 attrs (conj solo-modes :solo)
759837 solo-mode (atom :mute)
760 change (chan)
838 change (chan (sliding-buffer 1))
761839 changed #(put! change true)
762840 pick (fn [attr chs]
763841 (reduce-kv
9981076 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; deprecated - do not use ;;;;;;;;;;;;;;;;;;;;;;;;;
9991077 (defn map<
10001078 "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}
10021080 [f ch]
10031081 (reify
10041082 impl/Channel
10301108
10311109 (defn map>
10321110 "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}
10341112 [f ch]
10351113 (reify
10361114 impl/Channel
10461124
10471125 (defn filter>
10481126 "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}
10501128 [p ch]
10511129 (reify
10521130 impl/Channel
10641142
10651143 (defn remove>
10661144 "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}
10681146 [p ch]
10691147 (filter> (complement p) ch))
10701148
10711149 (defn filter<
10721150 "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}
10741152 ([p ch] (filter< p ch nil))
10751153 ([p ch buf-or-n]
10761154 (let [out (chan buf-or-n)]
10851163
10861164 (defn remove<
10871165 "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}
10891167 ([p ch] (remove< p ch nil))
10901168 ([p ch buf-or-n] (filter< (complement p) ch buf-or-n)))
10911169
11011179
11021180 (defn mapcat<
11031181 "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}
11051183 ([f in] (mapcat< f in nil))
11061184 ([f in buf-or-n]
11071185 (let [out (chan buf-or-n)]
11101188
11111189 (defn mapcat>
11121190 "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}
11141192 ([f out] (mapcat> f out nil))
11151193 ([f out buf-or-n]
11161194 (let [in (chan buf-or-n)]
11191197
11201198 (defn unique
11211199 "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}
11231201 ([ch]
11241202 (unique ch nil))
11251203 ([ch buf-or-n]
11371215
11381216 (defn partition
11391217 "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}
11411219 ([n ch]
11421220 (partition n ch nil))
11431221 ([n ch buf-or-n]
11621240
11631241 (defn partition-by
11641242 "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}
11661244 ([f ch]
11671245 (partition-by f ch nil))
11681246 ([f ch buf-or-n]
+0
-41
src/main/java/clojure/core/async/Mutex.java less more
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
-48
src/main/java/clojure/core/async/ThreadLocalRandom.java less more
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
08 (ns cljs.core.async.buffer-tests
19 (:require-macros [cljs.core.async.macros :as m :refer [go]])
210 (:require [cljs.core.async
2937 (is (full? fb))
3038 #_(assert (throws? (add! fb :3)))
3139
40 ; already overflown
41 (add! fb :3)
42 (is (= 3 (count fb)))
43 (is (full? fb))
44
3245 (is (= :1 (remove! fb)))
46 (is (= 2 (count fb)))
47 (is (full? fb))
48
49 (is (= :2 (remove! fb)))
50 (is (= 1 (count fb)))
3351 (is (not (full? fb)))
3452
35 (is (= 1 (count fb)))
36 (is (= :2 (remove! fb)))
37
53 (is (= :3 (remove! fb)))
3854 (is (= 0 (count fb)))
3955 #_(is (helpers/throws? (remove! fb)))))
4056
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
08 (ns cljs.core.async.pipeline-test
19 (:require-macros [cljs.core.async.macros :as m :refer [go go-loop]])
210 (:require [cljs.core.async.test-helpers :refer [latch inc!]]
311 [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!]]
513 [cljs.test :refer-macros [deftest is testing async]]))
614
715 (defn pipeline-tester [pipeline-fn n inputs xf]
8 (let [cin (to-chan inputs)
16 (let [cin (to-chan! inputs)
917 cout (chan 1)]
1018 (pipeline-fn n cout xf cin)
1119 (go-loop [acc []]
4957 (async done
5058 (go
5159 (let [cout (chan 1)]
52 (pipeline 5 cout (map identity) (to-chan [1]) true)
60 (pipeline 5 cout (map identity) (to-chan! [1]) true)
5361 (is (= 1 (<! cout)))
5462 (is (= nil (<! cout))))
5563 (let [cout (chan 1)]
56 (pipeline 5 cout (map identity) (to-chan [1]) false)
64 (pipeline 5 cout (map identity) (to-chan! [1]) false)
5765 (is (= 1 (<! cout)))
5866 (>! cout :more)
5967 (is (= :more (<! cout))))
6068 (let [cout (chan 1)]
61 (pipeline 5 cout (map identity) (to-chan [1]) nil)
69 (pipeline 5 cout (map identity) (to-chan! [1]) nil)
6270 (is (= 1 (<! cout)))
6371 (>! cout :more)
6472 (is (= :more (<! cout))))
7179 chex (chan 1)
7280 ex-mapping (map (fn [x] (if (= x 3) (throw (ex-info "err" {:data x})) x)))
7381 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)
7583 (is (= 1 (<! cout)))
7684 (is (= 2 (<! cout)))
7785 (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
08 (ns cljs.core.async.runner-tests
19 (:require [cljs.core.async :refer [buffer dropping-buffer sliding-buffer put! take! chan close!]]
210 [cljs.core.async.impl.dispatch :as dispatch]
184192 (finally (reset! a true))))]
185193 (is (and @a v)))
186194
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))))))
187217
188218 (let [a (atom false)
189219 v (try (runner
192222 (finally (reset! a true))))
193223 (catch js/Error ex ex))]
194224 (is (and @a v)))
195
196225
197226 (let [a (atom 0)
198227 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
08 (ns cljs.core.async.test-helpers
19 (:require [cljs.core.async.impl.ioc-macros :as ioc]))
210
2230 c#))]
2331 (when (satisfies? cljs.core.async.impl.protocols.Channel body-chan#)
2432 (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)]
2634 (assert (not= ::timeout v#)
2735 (str "test timed out: " ~nm ))))
2836 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
08 (ns cljs.core.async.test-helpers)
19
210 (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
08 (ns cljs.core.async.test-runner
19 (:require [cljs.test :refer-macros [run-tests]]
210 [cljs.core.async.buffer-tests]
311 [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]))
516
617 (run-tests
18 'cljs.core.async.runner-tests
719 'cljs.core.async.pipeline-test
820 'cljs.core.async.buffer-tests
21 'cljs.core.async.timers-test
22 'cljs.core.async.interop-tests
923 '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
08 (ns cljs.core.async.tests
19 (:require-macros
210 [cljs.core.async.macros :as m :refer [go alt!]])
141149 (async done
142150 (go
143151 (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]))))))
145153 (done))))
146154
147155 (deftest test-map>
150158 (is (= [2 3 4 5]
151159 (let [out (chan)
152160 in (async/map> inc out)]
153 (async/onto-chan in [1 2 3 4])
161 (async/onto-chan! in [1 2 3 4])
154162 (<! (async/into [] out)))))
155163 (done))))
156164
158166 (async done
159167 (go
160168 (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]))))))
162170 (done))))
163171
164172 (deftest test-remoev<
165173 (async done
166174 (go
167175 (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]))))))
169177 (done))))
170178
171179 (deftest test-filter>
174182 (is (= [2 4 6]
175183 (let [out (chan)
176184 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])
178186 (<! (async/into [] out)))))
179187 (done))))
180188
184192 (is (= [1 3 5]
185193 (let [out (chan)
186194 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])
188196 (<! (async/into [] out)))))
189197 (done))))
190198
192200 (async done
193201 (go
194202 (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]))))))
196204 (done))))
197205
198206 (deftest test-mapcat>
201209 (is (= [0 0 1 0 1 2]
202210 (let [out (chan)
203211 in (async/mapcat> range out)]
204 (async/onto-chan in [1 2 3])
212 (async/onto-chan! in [1 2 3])
205213 (<! (async/into [] out)))))
206214 (done))))
207215
210218 (go
211219 (is (= [1 2 3 4 5]
212220 (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])
214222 out)
215223 (<! (async/into [] out)))))
216224 (done))))
219227 (async done
220228 ;; Must provide buffers for channels else the tests won't complete
221229 (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)]
223231 (is (= [2 4 6] (<! (async/into [] even))))
224232 (is (= [1 3 5] (<! (async/into [] odd)))))
225233 (done))))
230238 (is (= [0 4 8 12]
231239 (<! (async/into []
232240 (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))])))))
237245 (done))))
238246
239247 (deftest test-merge
245253 (frequencies
246254 (<! (async/into []
247255 (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))]))))))
252260 (done))))
253261
254262 (deftest test-mult
260268 m (async/mult src)]
261269 (async/tap m a)
262270 (async/tap m b)
263 (async/pipe (async/to-chan (range 4)) src)
271 (async/pipe (async/to-chan! (range 4)) src)
264272 (is (= [0 1 2 3] (<! (async/into [] a))))
265273 (is (= [0 1 2 3] (<! (async/into [] b))))
266274 (done)))))
274282 take6 (go (dotimes [x 6]
275283 (>! take-out (<! out)))
276284 (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]))
279287 (is (= #{1 2 3 4 5 6} (<! (async/into #{} take-out))))
280288 (done)))))
281289
295303 (async/sub p :string b-strs)
296304 (async/sub p :int a-ints)
297305 (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)
299307 (is (= [1 2 3]
300308 (<! (async/into [] a-ints))))
301309 (is (= [1 2 3]
310318 (async done
311319 (go
312320 (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]))))))
314322 (done))))
315323
316324 (deftest test-partition
317325 (async done
318326 (go
319327 (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]))))))
321329 (done))))
322330
323331
325333 (async done
326334 (go
327335 (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"]))))))
329337 (done))))
330338
331339 (deftest test-reduce
332340 (async done
333341 (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! [])))))
335343 (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))))))
337345 (inc! l))
338346 (go (is (= :foo (<! (async/reduce #(if (= %2 2) (reduced :foo) %1) 0
339 (async/to-chan (range 10))))))
347 (async/to-chan! (range 10))))))
340348 (inc! l)))))
341349
342350 (deftest dispatch-bugs
465473 (deftest test-transduce
466474 (go
467475 (= [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))))
22 partition-by])
33 (:require [clojure.core.async.impl.ioc-macros :as ioc]
44 [clojure.core.async :refer :all :as async]
5 [clojure.set :as set]
56 [clojure.test :refer :all])
67 (:import [java.io FileInputStream ByteArrayOutputStream File]))
78
338339
339340
340341 (defn identity-chan
341 "Defines a channel that instantly writes the given value"
342 "Defines a channel that contains the given value"
342343 [x]
343 (let [c (chan 1)]
344 (>!! c x)
345 (close! c)
346 c))
344 (to-chan! [x]))
347345
348346 (deftest async-test
349347 (testing "values are returned correctly"
435433 (chan) ([v] :failed)
436434 :default 42))))))
437435
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}))))
451448
452449 (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)))))
461468
462469 (deftest resolution-tests
463470 (let [<! (constantly 42)]
504511
505512 (deftest ASYNC-186
506513 (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
-11
src/test/clojure/clojure/core/async/mutex_test.clj less more
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)))))
188188 (deftest ops-tests
189189 (testing "map<"
190190 (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])))))))
192192 (testing "map>"
193193 (is (= [2 3 4 5]
194194 (let [out (chan)
195195 in (a/map> inc out)]
196 (a/onto-chan in [1 2 3 4])
196 (a/onto-chan! in [1 2 3 4])
197197 (<!! (a/into [] out))))))
198198 (testing "filter<"
199199 (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])))))))
201201 (testing "remove<"
202202 (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)))))))
204212
205213 (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))))))
208223
209224 (testing "filter>"
210225 (is (= [2 4 6]
211226 (let [out (chan)
212227 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])
214229 (<!! (a/into [] out))))))
215230 (testing "remove>"
216231 (is (= [1 3 5]
217232 (let [out (chan)
218233 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])
220235 (<!! (a/into [] out))))))
221236 (testing "mapcat<"
222237 (is (= [0 0 1 0 1 2]
223238 (<!! (a/into [] (mapcat< range
224 (a/to-chan [1 2 3])))))))
239 (a/to-chan! [1 2 3])))))))
225240 (testing "mapcat>"
226241 (is (= [0 0 1 0 1 2]
227242 (let [out (chan)
228243 in (mapcat> range out)]
229 (a/onto-chan in [1 2 3])
244 (a/onto-chan! in [1 2 3])
230245 (<!! (a/into [] out))))))
231246
232247
233248 (testing "pipe"
234249 (is (= [1 2 3 4 5]
235250 (let [out (chan)]
236 (pipe (a/to-chan [1 2 3 4 5])
251 (pipe (a/to-chan! [1 2 3 4 5])
237252 out)
238253 (<!! (a/into [] out))))))
239254 (testing "split"
240255 ;; 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)]
242257 (is (= [2 4 6]
243258 (<!! (a/into [] even))))
244259 (is (= [1 3 5]
245260 (<!! (a/into [] odd))))))
246261 (testing "map"
247262 (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))]))))))
252267 (testing "merge"
253268 ;; merge uses alt, so results can be in any order, we're using
254269 ;; frequencies as a way to make sure we get the right result.
256271 1 4
257272 2 4
258273 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))])))))))
263278
264279 (testing "mult"
265280 (let [a (chan 4)
268283 m (mult src)]
269284 (tap m a)
270285 (tap m b)
271 (pipe (a/to-chan (range 4)) src)
286 (pipe (a/to-chan! (range 4)) src)
272287 (is (= [0 1 2 3]
273288 (<!! (a/into [] a))))
274289 (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)))))
277307
278308 (testing "mix"
279309 (let [out (chan)
280310 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]))
283313
284314 (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)))))))
286327
287328 (testing "pub-sub"
288329 (let [a-ints (chan 5)
298339 (sub p :string b-strs)
299340 (sub p :int a-ints)
300341 (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)
302343 (is (= [1 2 3]
303344 (<!! (a/into [] a-ints))))
304345 (is (= [1 2 3]
310351
311352 (testing "unique"
312353 (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])))))))
314355
315356 (testing "partition"
316357 (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])))))))
318359 (testing "partition-by"
319360 (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"])))))))
321362
322363 (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)))))))
326367 )
327368
328369 ;; transducer yielding n copies of each input value
353394 (take! c #(do
354395 (when (some? %) (swap! res conj %))
355396 (swap! counter inc))))
356 (onto-chan c input)
397 (onto-chan! c input)
357398
358399 ;; wait for all takers to report
359400 (while (< @counter takers)
367408 (doseq [b (range 1 10)
368409 t (range 1 10)]
369410 (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])))))))
370440
371441 ;; in 1.7+, use (map f)
372442 (defn mapping [f]
381451
382452 (deftest test-transduce
383453 (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)))))))
00 (ns clojure.core.pipeline-test
11 (: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!
33 pipeline pipeline-blocking pipeline-async]]))
44
55 ;; in Clojure 1.7, use (map f) instead of this
1414 (f1 result (apply f input inputs))))))
1515
1616 (defn pipeline-tester [pipeline-fn n inputs xf]
17 (let [cin (to-chan inputs)
17 (let [cin (to-chan! inputs)
1818 cout (chan 1)]
1919 (pipeline-fn n cout xf cin)
2020 (<!! (go-loop [acc []]
4242 (deftest test-close?
4343 (doseq [pf [pipeline pipeline-blocking]]
4444 (let [cout (chan 1)]
45 (pf 5 cout identity-mapping (to-chan [1]) true)
45 (pf 5 cout identity-mapping (to-chan! [1]) true)
4646 (is (= 1 (<!! cout)))
4747 (is (= nil (<!! cout))))
4848 (let [cout (chan 1)]
49 (pf 5 cout identity-mapping (to-chan [1]) false)
49 (pf 5 cout identity-mapping (to-chan! [1]) false)
5050 (is (= 1 (<!! cout)))
5151 (>!! cout :more)
5252 (is (= :more (<!! cout))))
5353 (let [cout (chan 1)]
54 (pf 5 cout identity-mapping (to-chan [1]) nil)
54 (pf 5 cout identity-mapping (to-chan! [1]) nil)
5555 (is (= 1 (<!! cout)))
5656 (>!! cout :more)
5757 (is (= :more (<!! cout))))))
6262 chex (chan 1)
6363 ex-mapping (mapping (fn [x] (if (= x 3) (throw (ex-info "err" {:data x})) x)))
6464 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)
6666 (is (= 1 (<!! cout)))
6767 (is (= 2 (<!! cout)))
6868 (is (= :err (<!! cout)))