diff --git a/.gitignore b/.gitignore index 03c8081..f089031 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ tests.js tests.js.map pom.xml.versionsBackup +.cpcache/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e246f6a --- /dev/null +++ b/LICENSE @@ -0,0 +1,205 @@ +Eclipse Public License - v 1.0 + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC +LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM +CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + +a) in the case of the initial Contributor, the initial code and documentation + distributed under this Agreement, and +b) in the case of each subsequent Contributor: + i) changes to the Program, and + ii) additions to the Program; + + where such changes and/or additions to the Program originate from and are + distributed by that particular Contributor. A Contribution 'originates' + from a Contributor if it was added to the Program by such Contributor + itself or anyone acting on such Contributor's behalf. Contributions do not + include additions to the Program which: (i) are separate modules of + software distributed in conjunction with the Program under their own + license agreement, and (ii) are not derivative works of the Program. + +"Contributor" means any person or entity that distributes the Program. + +"Licensed Patents" mean patent claims licensable by a Contributor which are +necessarily infringed by the use or sale of its Contribution alone or when +combined with the Program. + +"Program" means the Contributions distributed in accordance with this +Agreement. + +"Recipient" means anyone who receives the Program under this Agreement, +including all Contributors. + +2. GRANT OF RIGHTS + a) Subject to the terms of this Agreement, each Contributor hereby grants + Recipient a non-exclusive, worldwide, royalty-free copyright license to + reproduce, prepare derivative works of, publicly display, publicly + perform, distribute and sublicense the Contribution of such Contributor, + if any, and such derivative works, in source code and object code form. + b) Subject to the terms of this Agreement, each Contributor hereby grants + Recipient a non-exclusive, worldwide, royalty-free patent license under + Licensed Patents to make, use, sell, offer to sell, import and otherwise + transfer the Contribution of such Contributor, if any, in source code and + object code form. This patent license shall apply to the combination of + the Contribution and the Program if, at the time the Contribution is + added by the Contributor, such addition of the Contribution causes such + combination to be covered by the Licensed Patents. The patent license + shall not apply to any other combinations which include the Contribution. + No hardware per se is licensed hereunder. + c) Recipient understands that although each Contributor grants the licenses + to its Contributions set forth herein, no assurances are provided by any + Contributor that the Program does not infringe the patent or other + intellectual property rights of any other entity. Each Contributor + disclaims any liability to Recipient for claims brought by any other + entity based on infringement of intellectual property rights or + otherwise. As a condition to exercising the rights and licenses granted + hereunder, each Recipient hereby assumes sole responsibility to secure + any other intellectual property rights needed, if any. For example, if a + third party patent license is required to allow Recipient to distribute + the Program, it is Recipient's responsibility to acquire that license + before distributing the Program. + d) Each Contributor represents that to its knowledge it has sufficient + copyright rights in its Contribution, if any, to grant the copyright + license set forth in this Agreement. + +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form under +its own license agreement, provided that: + + a) it complies with the terms and conditions of this Agreement; and + b) its license agreement: + i) effectively disclaims on behalf of all Contributors all warranties + and conditions, express and implied, including warranties or + conditions of title and non-infringement, and implied warranties or + conditions of merchantability and fitness for a particular purpose; + ii) effectively excludes on behalf of all Contributors all liability for + damages, including direct, indirect, special, incidental and + consequential damages, such as lost profits; + iii) states that any provisions which differ from this Agreement are + offered by that Contributor alone and not by any other party; and + iv) states that source code for the Program is available from such + Contributor, and informs licensees how to obtain it in a reasonable + manner on or through a medium customarily used for software exchange. + +When the Program is made available in source code form: + + a) it must be made available under this Agreement; and + b) a copy of this Agreement must be included with each copy of the Program. + Contributors may not remove or alter any copyright notices contained + within the Program. + +Each Contributor must identify itself as the originator of its Contribution, +if +any, in a manner that reasonably allows subsequent Recipients to identify the +originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities with +respect to end users, business partners and the like. While this license is +intended to facilitate the commercial use of the Program, the Contributor who +includes the Program in a commercial product offering should do so in a manner +which does not create potential liability for other Contributors. Therefore, +if a Contributor includes the Program in a commercial product offering, such +Contributor ("Commercial Contributor") hereby agrees to defend and indemnify +every other Contributor ("Indemnified Contributor") against any losses, +damages and costs (collectively "Losses") arising from claims, lawsuits and +other legal actions brought by a third party against the Indemnified +Contributor to the extent caused by the acts or omissions of such Commercial +Contributor in connection with its distribution of the Program in a commercial +product offering. The obligations in this section do not apply to any claims +or Losses relating to any actual or alleged intellectual property +infringement. In order to qualify, an Indemnified Contributor must: +a) promptly notify the Commercial Contributor in writing of such claim, and +b) allow the Commercial Contributor to control, and cooperate with the +Commercial Contributor in, the defense and any related settlement +negotiations. The Indemnified Contributor may participate in any such claim at +its own expense. + +For example, a Contributor might include the Program in a commercial product +offering, Product X. That Contributor is then a Commercial Contributor. If +that Commercial Contributor then makes performance claims, or offers +warranties related to Product X, those performance claims and warranties are +such Commercial Contributor's responsibility alone. Under this section, the +Commercial Contributor would have to defend claims against the other +Contributors related to those performance claims and warranties, and if a +court requires any other Contributor to pay any damages as a result, the +Commercial Contributor must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR +IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, +NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each +Recipient is solely responsible for determining the appropriateness of using +and distributing the Program and assumes all risks associated with its +exercise of rights under this Agreement , including but not limited to the +risks and costs of program errors, compliance with applicable laws, damage to +or loss of data, programs or equipment, and unavailability or interruption of +operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY +CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION +LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE +EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY +OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under +applicable law, it shall not affect the validity or enforceability of the +remainder of the terms of this Agreement, and without further action by the +parties hereto, such provision shall be reformed to the minimum extent +necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Program itself +(excluding combinations of the Program with other software or hardware) +infringes such Recipient's patent(s), then such Recipient's rights granted +under Section 2(b) shall terminate as of the date such litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it fails to +comply with any of the material terms or conditions of this Agreement and does +not cure such failure in a reasonable period of time after becoming aware of +such noncompliance. If all Recipient's rights under this Agreement terminate, +Recipient agrees to cease use and distribution of the Program as soon as +reasonably practicable. However, Recipient's obligations under this Agreement +and any licenses granted by Recipient relating to the Program shall continue +and survive. + +Everyone is permitted to copy and distribute copies of this Agreement, but in +order to avoid inconsistency the Agreement is copyrighted and may only be +modified in the following manner. The Agreement Steward reserves the right to +publish new versions (including revisions) of this Agreement from time to +time. No one other than the Agreement Steward has the right to modify this +Agreement. The Eclipse Foundation is the initial Agreement Steward. The +Eclipse Foundation may assign the responsibility to serve as the Agreement +Steward to a suitable separate entity. Each new version of the Agreement will +be given a distinguishing version number. The Program (including +Contributions) may always be distributed subject to the version of the +Agreement under which it was received. In addition, after a new version of the +Agreement is published, Contributor may elect to distribute the Program +(including its Contributions) under the new version. Except as expressly +stated in Sections 2(a) and 2(b) above, Recipient receives no rights or +licenses to the intellectual property of any Contributor under this Agreement, +whether expressly, by implication, estoppel or otherwise. All rights in the +Program not expressly granted under this Agreement are reserved. + +This Agreement is governed by the laws of the State of New York and the +intellectual property laws of the United States of America. No party to this +Agreement will bring a legal action under this Agreement more than one year +after the cause of action arose. Each party waives its rights to a jury trial in +any resulting litigation. + + diff --git a/README.md b/README.md index f05e9e6..fd4ab88 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,22 @@ ## Releases and Dependency Information -Latest release: 0.3.442 +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. + +Latest release: 1.2.603 * [All Released Versions](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.clojure%22%20AND%20a%3A%22core.async%22) + +[deps.edn](https://clojure.org/reference/deps_and_cli) dependency information: + +```clj + org.clojure/core.async {:mvn/version "1.2.603"} + ``` [Leiningen](https://github.com/technomancy/leiningen) dependency information: ```clj - [org.clojure/clojure "1.6.0"] - [org.clojure/core.async "0.3.442"] + [org.clojure/core.async "1.2.603"] ``` [Maven](http://maven.apache.org/) dependency information: @@ -22,14 +29,14 @@ org.clojure core.async - 0.3.442 + 1.2.603 ``` ## Documentation -* [Rationale](http://clojure.com/blog/2013/06/28/clojure-core-async-channels.html) -* [API docs](http://clojure.github.io/core.async/) +* [Rationale](https://clojure.org/news/2013/06/28/clojure-clore-async-channels) +* [API docs](https://clojure.github.io/core.async/) * [Code walkthrough](https://github.com/clojure/core.async/blob/master/examples/walkthrough.clj) ## Presentations @@ -37,11 +44,10 @@ * [Rich Hickey on core.async](http://www.infoq.com/presentations/clojure-core-async) * [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)). * 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) -* David Nolen [core.async webinar](http://go.cognitect.com/core_async_webinar_recording) ## Contributing -[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. +[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. To run the ClojureScript tests: @@ -51,29 +57,74 @@ ## License -Copyright © 2017 Rich Hickey and contributors +Copyright © 2017-2020 Rich Hickey and contributors Distributed under the Eclipse Public License, the same as Clojure. ## Changelog -* Release 0.3.xxx on 2017.05.26 - * +* Release 1.2.603 on 2020.05.11 + * Fix bug in cljs impl of onto-chan! in 1.2.598 +* Release 1.2.598 on 2020.05.11 + * Add onto-chan! and to-chan! to cljs core.async +* Release 1.2.593 on 2020.05.11 + * onto-chan use of go-loop incompatible with blocking colls, replace with onto-chan! and onto-chan!! +* Release 1.1.587 on 2020.04.01 + * Added :require-macros for the promise interop from 1.1.582 +* Release 1.1.582 on 2020.03.31 + * Bumped deps - clojure 1.9, clojurescript 1.10.1.597, cljsbuild 1.1.7, tools.analyzer.jvm 1.0.0 + * [ASYNC-165](https://clojure.atlassian.net/browse/ASYNC-165) (CLJS) Fix inlining of let binding + * [ASYNC-184](https://clojure.atlassian.net/browse/ASYNC-184) (CLJS) Port CLJ exception handling fixes + * [ASYNC-228](https://clojure.atlassian.net/browse/ASYNC-228) (CLJS) Fix skip list for CLJS timers + * [ASYNC-96](https://clojure.atlassian.net/browse/ASYNC-96) (CLJS) Fix full checking in fixed buffer + * [ASYNC-230](https://clojure.atlassian.net/browse/ASYNC-230) (CLJS) Add js/Promise interop via core.async.interop +* Release 1.0.567 on 2020.02.18 +* Release 0.7.559 on 2020.01.10 + * [ASYNC-198](https://clojure.atlassian.net/browse/ASYNC-198) (CLJ) Fix exception rewriting in go can replace return value + * [ASYNC-220](https://clojure.atlassian.net/browse/ASYNC-220) (CLJ) Fix exception in go finally swallows exception of outer try + * [ASYNC-229](https://clojure.atlassian.net/browse/ASYNC-229) (CLJ) Fix go finally block executed twice + * [ASYNC-212](https://clojure.atlassian.net/browse/ASYNC-212) (CLJ) Fix go fails to compile expressions with literal nil as let value + * [ASYNC-145](https://clojure.atlassian.net/browse/ASYNC-145) (CLJ, CLJS) Fix mix throws error when many channels added + * [ASYNC-170](https://clojure.atlassian.net/browse/ASYNC-170) (CLJ) Fix binding in go block throws assertion error + * [ASYNC-127](https://clojure.atlassian.net/browse/ASYNC-127) (CLJ, CLJS) Fix mult to work as doc'ed with all taps accepting before next + * [ASYNC-210](https://clojure.atlassian.net/browse/ASYNC-210) (CLJ) Fix puts allowed when buffer still full from expanding transducer +* Release 0.6.532 on 2019.12.02 + * Bump tools.analyzer.jvm dep to 0.7.3 +* Release 0.5.527 on 2019.11.12 + * Add system property clojure.core.async.go-checking that will throw if core.async blocking ops (>!!, 0 + * [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) + * [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) + * [ASYNC-155](https://clojure.atlassian.net/browse/ASYNC-155) - preserve loop binding metadata when inside a go block + * [ASYNC-54](https://clojure.atlassian.net/browse/ASYNC-54) - fix bad type hint on MAX-QUEUE-SIZE + * [ASYNC-177](https://clojure.atlassian.net/browse/ASYNC-177) - fix typo in Buffer protocol full? method + * [ASYNC-70](https://clojure.atlassian.net/browse/ASYNC-70) - docstring change in thread, thread-call + * [ASYNC-143](https://clojure.atlassian.net/browse/ASYNC-143) - assert that fixed buffers must have size > 0 * Update tools.analyzer.jvm dependency * Release 0.2.395 on 2016.10.12 * Add async version of transduce @@ -85,18 +136,18 @@ * Release 0.2.382 on 2016.06.13 * Important: Change default dispatch thread pool size to 8. * Add Java system property `clojure.core.async.pool-size` to set the dispatch thread pool size - * [ASYNC-152](http://dev.clojure.org/jira/browse/ASYNC-152) - disable t.a.jvm's warn-on-reflection pass + * [ASYNC-152](https://clojure.atlassian.net/browse/ASYNC-152) - disable t.a.jvm's warn-on-reflection pass * Release 0.2.374 on 2015.11.11 - * [ASYNC-149](http://dev.clojure.org/jira/browse/ASYNC-149) - fix error compiling recur inside case in a go block + * [ASYNC-149](https://clojure.atlassian.net/browse/ASYNC-149) - fix error compiling recur inside case in a go block * Updated tools.analyzer.jvm version (and other upstream deps) * Updated to latest clojurescript and cljsbuild versions * Release 0.2.371 on 2015.10.28 - * [ASYNC-124](http://dev.clojure.org/jira/browse/ASYNC-124) - dispatch multiple pending takers from expanding transducer - * [ASYNC-103](http://dev.clojure.org/jira/browse/ASYNC-103) - NEW promise-chan - * [ASYNC-104](http://dev.clojure.org/jira/browse/ASYNC-104) - NEW non-blocking offer!, poll! - * [ASYNC-101](http://dev.clojure.org/jira/browse/ASYNC-101) - async/reduce now respects reduced - * [ASYNC-112](http://dev.clojure.org/jira/browse/ASYNC-112) - replace "transformer" with "transducer" in deprecation messages - * [ASYNC-6](http://dev.clojure.org/jira/browse/ASYNC-6) - alts! docs updated to explicitly state ports is a vector + * [ASYNC-124](https://clojure.atlassian.net/browse/ASYNC-124) - dispatch multiple pending takers from expanding transducer + * [ASYNC-103](https://clojure.atlassian.net/browse/ASYNC-103) - NEW promise-chan + * [ASYNC-104](https://clojure.atlassian.net/browse/ASYNC-104) - NEW non-blocking offer!, poll! + * [ASYNC-101](https://clojure.atlassian.net/browse/ASYNC-101) - async/reduce now respects reduced + * [ASYNC-112](https://clojure.atlassian.net/browse/ASYNC-112) - replace "transformer" with "transducer" in deprecation messages + * [ASYNC-6](https://clojure.atlassian.net/browse/ASYNC-6) - alts! docs updated to explicitly state ports is a vector * Support (try (catch :default)) in CLJS exception handling * Use cljs.test * Updated tools.analyzer.jvm version (and other upstream deps) diff --git a/VERSION_TEMPLATE b/VERSION_TEMPLATE index 70ca0c6..4c5bd63 100755 --- a/VERSION_TEMPLATE +++ b/VERSION_TEMPLATE @@ -1 +1 @@ -0.3.GENERATED_VERSION +1.3.GENERATED_VERSION diff --git a/deps.edn b/deps.edn new file mode 100644 index 0000000..73de720 --- /dev/null +++ b/deps.edn @@ -0,0 +1,3 @@ +{:paths ["src/main/clojure"] + :deps + {org.clojure/tools.analyzer.jvm {:mvn/version "1.1.0"}}} diff --git a/epl-v10.html b/epl-v10.html new file mode 100644 index 0000000..84ec251 --- /dev/null +++ b/epl-v10.html @@ -0,0 +1,261 @@ + + + + + + +Eclipse Public License - Version 1.0 + + + + + + +

Eclipse Public License - v 1.0

+ +

THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE +PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR +DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS +AGREEMENT.

+ +

1. DEFINITIONS

+ +

"Contribution" means:

+ +

a) in the case of the initial Contributor, the initial +code and documentation distributed under this Agreement, and

+

b) in the case of each subsequent Contributor:

+

i) changes to the Program, and

+

ii) additions to the Program;

+

where such changes and/or additions to the Program +originate from and are distributed by that particular Contributor. A +Contribution 'originates' from a Contributor if it was added to the +Program by such Contributor itself or anyone acting on such +Contributor's behalf. Contributions do not include additions to the +Program which: (i) are separate modules of software distributed in +conjunction with the Program under their own license agreement, and (ii) +are not derivative works of the Program.

+ +

"Contributor" means any person or entity that distributes +the Program.

+ +

"Licensed Patents" mean patent claims licensable by a +Contributor which are necessarily infringed by the use or sale of its +Contribution alone or when combined with the Program.

+ +

"Program" means the Contributions distributed in accordance +with this Agreement.

+ +

"Recipient" means anyone who receives the Program under +this Agreement, including all Contributors.

+ +

2. GRANT OF RIGHTS

+ +

a) Subject to the terms of this Agreement, each +Contributor hereby grants Recipient a non-exclusive, worldwide, +royalty-free copyright license to reproduce, prepare derivative works +of, publicly display, publicly perform, distribute and sublicense the +Contribution of such Contributor, if any, and such derivative works, in +source code and object code form.

+ +

b) Subject to the terms of this Agreement, each +Contributor hereby grants Recipient a non-exclusive, worldwide, +royalty-free patent license under Licensed Patents to make, use, sell, +offer to sell, import and otherwise transfer the Contribution of such +Contributor, if any, in source code and object code form. This patent +license shall apply to the combination of the Contribution and the +Program if, at the time the Contribution is added by the Contributor, +such addition of the Contribution causes such combination to be covered +by the Licensed Patents. The patent license shall not apply to any other +combinations which include the Contribution. No hardware per se is +licensed hereunder.

+ +

c) Recipient understands that although each Contributor +grants the licenses to its Contributions set forth herein, no assurances +are provided by any Contributor that the Program does not infringe the +patent or other intellectual property rights of any other entity. Each +Contributor disclaims any liability to Recipient for claims brought by +any other entity based on infringement of intellectual property rights +or otherwise. As a condition to exercising the rights and licenses +granted hereunder, each Recipient hereby assumes sole responsibility to +secure any other intellectual property rights needed, if any. For +example, if a third party patent license is required to allow Recipient +to distribute the Program, it is Recipient's responsibility to acquire +that license before distributing the Program.

+ +

d) Each Contributor represents that to its knowledge it +has sufficient copyright rights in its Contribution, if any, to grant +the copyright license set forth in this Agreement.

+ +

3. REQUIREMENTS

+ +

A Contributor may choose to distribute the Program in object code +form under its own license agreement, provided that:

+ +

a) it complies with the terms and conditions of this +Agreement; and

+ +

b) its license agreement:

+ +

i) effectively disclaims on behalf of all Contributors +all warranties and conditions, express and implied, including warranties +or conditions of title and non-infringement, and implied warranties or +conditions of merchantability and fitness for a particular purpose;

+ +

ii) effectively excludes on behalf of all Contributors +all liability for damages, including direct, indirect, special, +incidental and consequential damages, such as lost profits;

+ +

iii) states that any provisions which differ from this +Agreement are offered by that Contributor alone and not by any other +party; and

+ +

iv) states that source code for the Program is available +from such Contributor, and informs licensees how to obtain it in a +reasonable manner on or through a medium customarily used for software +exchange.

+ +

When the Program is made available in source code form:

+ +

a) it must be made available under this Agreement; and

+ +

b) a copy of this Agreement must be included with each +copy of the Program.

+ +

Contributors may not remove or alter any copyright notices contained +within the Program.

+ +

Each Contributor must identify itself as the originator of its +Contribution, if any, in a manner that reasonably allows subsequent +Recipients to identify the originator of the Contribution.

+ +

4. COMMERCIAL DISTRIBUTION

+ +

Commercial distributors of software may accept certain +responsibilities with respect to end users, business partners and the +like. While this license is intended to facilitate the commercial use of +the Program, the Contributor who includes the Program in a commercial +product offering should do so in a manner which does not create +potential liability for other Contributors. Therefore, if a Contributor +includes the Program in a commercial product offering, such Contributor +("Commercial Contributor") hereby agrees to defend and +indemnify every other Contributor ("Indemnified Contributor") +against any losses, damages and costs (collectively "Losses") +arising from claims, lawsuits and other legal actions brought by a third +party against the Indemnified Contributor to the extent caused by the +acts or omissions of such Commercial Contributor in connection with its +distribution of the Program in a commercial product offering. The +obligations in this section do not apply to any claims or Losses +relating to any actual or alleged intellectual property infringement. In +order to qualify, an Indemnified Contributor must: a) promptly notify +the Commercial Contributor in writing of such claim, and b) allow the +Commercial Contributor to control, and cooperate with the Commercial +Contributor in, the defense and any related settlement negotiations. The +Indemnified Contributor may participate in any such claim at its own +expense.

+ +

For example, a Contributor might include the Program in a commercial +product offering, Product X. That Contributor is then a Commercial +Contributor. If that Commercial Contributor then makes performance +claims, or offers warranties related to Product X, those performance +claims and warranties are such Commercial Contributor's responsibility +alone. Under this section, the Commercial Contributor would have to +defend claims against the other Contributors related to those +performance claims and warranties, and if a court requires any other +Contributor to pay any damages as a result, the Commercial Contributor +must pay those damages.

+ +

5. NO WARRANTY

+ +

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS +PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS +OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, +ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY +OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely +responsible for determining the appropriateness of using and +distributing the Program and assumes all risks associated with its +exercise of rights under this Agreement , including but not limited to +the risks and costs of program errors, compliance with applicable laws, +damage to or loss of data, programs or equipment, and unavailability or +interruption of operations.

+ +

6. DISCLAIMER OF LIABILITY

+ +

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT +NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING +WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR +DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED +HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

+ +

7. GENERAL

+ +

If any provision of this Agreement is invalid or unenforceable under +applicable law, it shall not affect the validity or enforceability of +the remainder of the terms of this Agreement, and without further action +by the parties hereto, such provision shall be reformed to the minimum +extent necessary to make such provision valid and enforceable.

+ +

If Recipient institutes patent litigation against any entity +(including a cross-claim or counterclaim in a lawsuit) alleging that the +Program itself (excluding combinations of the Program with other +software or hardware) infringes such Recipient's patent(s), then such +Recipient's rights granted under Section 2(b) shall terminate as of the +date such litigation is filed.

+ +

All Recipient's rights under this Agreement shall terminate if it +fails to comply with any of the material terms or conditions of this +Agreement and does not cure such failure in a reasonable period of time +after becoming aware of such noncompliance. If all Recipient's rights +under this Agreement terminate, Recipient agrees to cease use and +distribution of the Program as soon as reasonably practicable. However, +Recipient's obligations under this Agreement and any licenses granted by +Recipient relating to the Program shall continue and survive.

+ +

Everyone is permitted to copy and distribute copies of this +Agreement, but in order to avoid inconsistency the Agreement is +copyrighted and may only be modified in the following manner. The +Agreement Steward reserves the right to publish new versions (including +revisions) of this Agreement from time to time. No one other than the +Agreement Steward has the right to modify this Agreement. The Eclipse +Foundation is the initial Agreement Steward. The Eclipse Foundation may +assign the responsibility to serve as the Agreement Steward to a +suitable separate entity. Each new version of the Agreement will be +given a distinguishing version number. The Program (including +Contributions) may always be distributed subject to the version of the +Agreement under which it was received. In addition, after a new version +of the Agreement is published, Contributor may elect to distribute the +Program (including its Contributions) under the new version. Except as +expressly stated in Sections 2(a) and 2(b) above, Recipient receives no +rights or licenses to the intellectual property of any Contributor under +this Agreement, whether expressly, by implication, estoppel or +otherwise. All rights in the Program not expressly granted under this +Agreement are reserved.

+ +

This Agreement is governed by the laws of the State of New York and +the intellectual property laws of the United States of America. No party +to this Agreement will bring a legal action under this Agreement more +than one year after the cause of action arose. Each party waives its +rights to a jury trial in any resulting litigation.

+ + + + diff --git a/epl.html b/epl.html deleted file mode 100644 index fd39122..0000000 --- a/epl.html +++ /dev/null @@ -1,261 +0,0 @@ - - - - - - -Eclipse Public License - Version 1.0 - - - - - - -

Eclipse Public License - v 1.0

- -

THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE -PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR -DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS -AGREEMENT.

- -

1. DEFINITIONS

- -

"Contribution" means:

- -

a) in the case of the initial Contributor, the initial -code and documentation distributed under this Agreement, and

-

b) in the case of each subsequent Contributor:

-

i) changes to the Program, and

-

ii) additions to the Program;

-

where such changes and/or additions to the Program -originate from and are distributed by that particular Contributor. A -Contribution 'originates' from a Contributor if it was added to the -Program by such Contributor itself or anyone acting on such -Contributor's behalf. Contributions do not include additions to the -Program which: (i) are separate modules of software distributed in -conjunction with the Program under their own license agreement, and (ii) -are not derivative works of the Program.

- -

"Contributor" means any person or entity that distributes -the Program.

- -

"Licensed Patents" mean patent claims licensable by a -Contributor which are necessarily infringed by the use or sale of its -Contribution alone or when combined with the Program.

- -

"Program" means the Contributions distributed in accordance -with this Agreement.

- -

"Recipient" means anyone who receives the Program under -this Agreement, including all Contributors.

- -

2. GRANT OF RIGHTS

- -

a) Subject to the terms of this Agreement, each -Contributor hereby grants Recipient a non-exclusive, worldwide, -royalty-free copyright license to reproduce, prepare derivative works -of, publicly display, publicly perform, distribute and sublicense the -Contribution of such Contributor, if any, and such derivative works, in -source code and object code form.

- -

b) Subject to the terms of this Agreement, each -Contributor hereby grants Recipient a non-exclusive, worldwide, -royalty-free patent license under Licensed Patents to make, use, sell, -offer to sell, import and otherwise transfer the Contribution of such -Contributor, if any, in source code and object code form. This patent -license shall apply to the combination of the Contribution and the -Program if, at the time the Contribution is added by the Contributor, -such addition of the Contribution causes such combination to be covered -by the Licensed Patents. The patent license shall not apply to any other -combinations which include the Contribution. No hardware per se is -licensed hereunder.

- -

c) Recipient understands that although each Contributor -grants the licenses to its Contributions set forth herein, no assurances -are provided by any Contributor that the Program does not infringe the -patent or other intellectual property rights of any other entity. Each -Contributor disclaims any liability to Recipient for claims brought by -any other entity based on infringement of intellectual property rights -or otherwise. As a condition to exercising the rights and licenses -granted hereunder, each Recipient hereby assumes sole responsibility to -secure any other intellectual property rights needed, if any. For -example, if a third party patent license is required to allow Recipient -to distribute the Program, it is Recipient's responsibility to acquire -that license before distributing the Program.

- -

d) Each Contributor represents that to its knowledge it -has sufficient copyright rights in its Contribution, if any, to grant -the copyright license set forth in this Agreement.

- -

3. REQUIREMENTS

- -

A Contributor may choose to distribute the Program in object code -form under its own license agreement, provided that:

- -

a) it complies with the terms and conditions of this -Agreement; and

- -

b) its license agreement:

- -

i) effectively disclaims on behalf of all Contributors -all warranties and conditions, express and implied, including warranties -or conditions of title and non-infringement, and implied warranties or -conditions of merchantability and fitness for a particular purpose;

- -

ii) effectively excludes on behalf of all Contributors -all liability for damages, including direct, indirect, special, -incidental and consequential damages, such as lost profits;

- -

iii) states that any provisions which differ from this -Agreement are offered by that Contributor alone and not by any other -party; and

- -

iv) states that source code for the Program is available -from such Contributor, and informs licensees how to obtain it in a -reasonable manner on or through a medium customarily used for software -exchange.

- -

When the Program is made available in source code form:

- -

a) it must be made available under this Agreement; and

- -

b) a copy of this Agreement must be included with each -copy of the Program.

- -

Contributors may not remove or alter any copyright notices contained -within the Program.

- -

Each Contributor must identify itself as the originator of its -Contribution, if any, in a manner that reasonably allows subsequent -Recipients to identify the originator of the Contribution.

- -

4. COMMERCIAL DISTRIBUTION

- -

Commercial distributors of software may accept certain -responsibilities with respect to end users, business partners and the -like. While this license is intended to facilitate the commercial use of -the Program, the Contributor who includes the Program in a commercial -product offering should do so in a manner which does not create -potential liability for other Contributors. Therefore, if a Contributor -includes the Program in a commercial product offering, such Contributor -("Commercial Contributor") hereby agrees to defend and -indemnify every other Contributor ("Indemnified Contributor") -against any losses, damages and costs (collectively "Losses") -arising from claims, lawsuits and other legal actions brought by a third -party against the Indemnified Contributor to the extent caused by the -acts or omissions of such Commercial Contributor in connection with its -distribution of the Program in a commercial product offering. The -obligations in this section do not apply to any claims or Losses -relating to any actual or alleged intellectual property infringement. In -order to qualify, an Indemnified Contributor must: a) promptly notify -the Commercial Contributor in writing of such claim, and b) allow the -Commercial Contributor to control, and cooperate with the Commercial -Contributor in, the defense and any related settlement negotiations. The -Indemnified Contributor may participate in any such claim at its own -expense.

- -

For example, a Contributor might include the Program in a commercial -product offering, Product X. That Contributor is then a Commercial -Contributor. If that Commercial Contributor then makes performance -claims, or offers warranties related to Product X, those performance -claims and warranties are such Commercial Contributor's responsibility -alone. Under this section, the Commercial Contributor would have to -defend claims against the other Contributors related to those -performance claims and warranties, and if a court requires any other -Contributor to pay any damages as a result, the Commercial Contributor -must pay those damages.

- -

5. NO WARRANTY

- -

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS -PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS -OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, -ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY -OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely -responsible for determining the appropriateness of using and -distributing the Program and assumes all risks associated with its -exercise of rights under this Agreement , including but not limited to -the risks and costs of program errors, compliance with applicable laws, -damage to or loss of data, programs or equipment, and unavailability or -interruption of operations.

- -

6. DISCLAIMER OF LIABILITY

- -

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT -NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING -WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR -DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED -HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

- -

7. GENERAL

- -

If any provision of this Agreement is invalid or unenforceable under -applicable law, it shall not affect the validity or enforceability of -the remainder of the terms of this Agreement, and without further action -by the parties hereto, such provision shall be reformed to the minimum -extent necessary to make such provision valid and enforceable.

- -

If Recipient institutes patent litigation against any entity -(including a cross-claim or counterclaim in a lawsuit) alleging that the -Program itself (excluding combinations of the Program with other -software or hardware) infringes such Recipient's patent(s), then such -Recipient's rights granted under Section 2(b) shall terminate as of the -date such litigation is filed.

- -

All Recipient's rights under this Agreement shall terminate if it -fails to comply with any of the material terms or conditions of this -Agreement and does not cure such failure in a reasonable period of time -after becoming aware of such noncompliance. If all Recipient's rights -under this Agreement terminate, Recipient agrees to cease use and -distribution of the Program as soon as reasonably practicable. However, -Recipient's obligations under this Agreement and any licenses granted by -Recipient relating to the Program shall continue and survive.

- -

Everyone is permitted to copy and distribute copies of this -Agreement, but in order to avoid inconsistency the Agreement is -copyrighted and may only be modified in the following manner. The -Agreement Steward reserves the right to publish new versions (including -revisions) of this Agreement from time to time. No one other than the -Agreement Steward has the right to modify this Agreement. The Eclipse -Foundation is the initial Agreement Steward. The Eclipse Foundation may -assign the responsibility to serve as the Agreement Steward to a -suitable separate entity. Each new version of the Agreement will be -given a distinguishing version number. The Program (including -Contributions) may always be distributed subject to the version of the -Agreement under which it was received. In addition, after a new version -of the Agreement is published, Contributor may elect to distribute the -Program (including its Contributions) under the new version. Except as -expressly stated in Sections 2(a) and 2(b) above, Recipient receives no -rights or licenses to the intellectual property of any Contributor under -this Agreement, whether expressly, by implication, estoppel or -otherwise. All rights in the Program not expressly granted under this -Agreement are reserved.

- -

This Agreement is governed by the laws of the State of New York and -the intellectual property laws of the United States of America. No party -to this Agreement will bring a legal action under this Agreement more -than one year after the cause of action arose. Each party waives its -rights to a jury trial in any resulting litigation.

- - - - diff --git a/pom.xml b/pom.xml index d388d45..5c625e9 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.clojure core.async - 0.3.443 + 1.3.610 jar core.async Facilities for async programming and communication in Clojure @@ -20,40 +20,64 @@ org.clojure pom.contrib - 0.2.2 + 1.0.0 scm:git:git://github.com/clojure/core.async.git scm:git:git@github.com:clojure/core.async.git https://github.com/clojure/core.async - core.async-0.3.443 + core.async-1.3.610 - 1.7.0 + 1.9.0 org.clojure clojurescript - 0.0-2311 + 1.10.597 provided org.clojure tools.analyzer.jvm - 0.7.0 + 1.1.0 + src/main/clojure org.codehaus.mojo versions-maven-plugin - 2.3 + 2.7 + + + com.theoryinpractise + clojure-maven-plugin + 1.7.1 + + true + + + + clojure-compile + compile + + compile + + + true + + !clojure.core.* + + + + diff --git a/project.clj b/project.clj index 20d307a..a8f5bd0 100644 --- a/project.clj +++ b/project.clj @@ -3,10 +3,10 @@ :url "https://github.com/clojure/core.async" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} - :parent [org.clojure/pom.contrib "0.1.2"] - :dependencies [[org.clojure/clojure "1.7.0"] - [org.clojure/tools.analyzer.jvm "0.7.0"] - [org.clojure/clojurescript "1.7.170" :scope "provided"]] + :parent [org.clojure/pom.contrib "1.0.0"] + :dependencies [[org.clojure/clojure "1.9.0"] + [org.clojure/tools.analyzer.jvm "1.0.0"] + [org.clojure/clojurescript "1.10.597" :scope "provided"]] :global-vars {*warn-on-reflection* true} :source-paths ["src/main/clojure"] :test-paths ["src/test/clojure"] @@ -14,7 +14,7 @@ :java-source-paths ["src/main/java"] :profiles {:dev {:source-paths ["examples"]}} - :plugins [[lein-cljsbuild "1.1.2"]] + :plugins [[lein-cljsbuild "1.1.7"]] :clean-targets ["tests.js" "tests.js.map" "out" "out-simp" "out-simp-node" diff --git a/src/main/clojure/cljs/core/async/impl/buffers.cljs b/src/main/clojure/cljs/core/async/impl/buffers.cljs index b981819..1444f68 100644 --- a/src/main/clojure/cljs/core/async/impl/buffers.cljs +++ b/src/main/clojure/cljs/core/async/impl/buffers.cljs @@ -80,7 +80,7 @@ (deftype FixedBuffer [buf n] impl/Buffer (full? [this] - (== (.-length buf) n)) + (>= (.-length buf) n)) (remove! [this] (.pop buf)) (add!* [this itm] diff --git a/src/main/clojure/cljs/core/async/impl/channels.cljs b/src/main/clojure/cljs/core/async/impl/channels.cljs index ce9b2fd..be04e94 100644 --- a/src/main/clojure/cljs/core/async/impl/channels.cljs +++ b/src/main/clojure/cljs/core/async/impl/channels.cljs @@ -43,7 +43,7 @@ (impl/close! this)) impl/WritePort (put! [this val ^not-native handler] - (assert (not (nil? val)) "Can't put nil in on a channel") + (assert (not (nil? val)) "Can't put nil on a channel") ;; bug in CLJS compiler boolean inference - David (let [^boolean closed closed] (if (or closed (not ^boolean (impl/active? handler))) @@ -97,7 +97,7 @@ (do (if-let [take-cb (impl/commit handler)] (let [val (impl/remove! buf) - [done? cbs] (when (pos? (.-length puts)) + [done? cbs] (when (and (not (impl/full? buf)) (pos? (.-length puts))) (loop [cbs []] (let [putter (.pop puts) ^not-native put-handler (.-handler putter) diff --git a/src/main/clojure/cljs/core/async/impl/dispatch.cljs b/src/main/clojure/cljs/core/async/impl/dispatch.cljs index 468bbdf..f158f14 100644 --- a/src/main/clojure/cljs/core/async/impl/dispatch.cljs +++ b/src/main/clojure/cljs/core/async/impl/dispatch.cljs @@ -1,3 +1,11 @@ +;; Copyright (c) Rich Hickey and contributors. All rights reserved. +;; The use and distribution terms for this software are covered by the +;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +;; which can be found in the file epl-v10.html at the root of this distribution. +;; By using this software in any fashion, you are agreeing to be bound by +;; the terms of this license. +;; You must not remove this notice, or any other, from this software. + (ns cljs.core.async.impl.dispatch (:require [cljs.core.async.impl.buffers :as buffers] [goog.async.nextTick])) diff --git a/src/main/clojure/cljs/core/async/impl/ioc_helpers.cljs b/src/main/clojure/cljs/core/async/impl/ioc_helpers.cljs index c849acc..7b612a0 100644 --- a/src/main/clojure/cljs/core/async/impl/ioc_helpers.cljs +++ b/src/main/clojure/cljs/core/async/impl/ioc_helpers.cljs @@ -1,3 +1,11 @@ +;; Copyright (c) Rich Hickey and contributors. All rights reserved. +;; The use and distribution terms for this software are covered by the +;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +;; which can be found in the file epl-v10.html at the root of this distribution. +;; By using this software in any fashion, you are agreeing to be bound by +;; the terms of this license. +;; You must not remove this notice, or any other, from this software. + (ns cljs.core.async.impl.ioc-helpers (:require [cljs.core.async.impl.protocols :as impl]) (:require-macros [cljs.core.async.impl.ioc-macros :as ioc])) @@ -65,82 +73,4 @@ (impl/close! c) c)) -(defrecord ExceptionFrame [catch-block - ^Class catch-exception - finally-block - continue-block - prev]) -(defn add-exception-frame [state catch-block catch-exception finally-block continue-block] - (ioc/aset-all! state - EXCEPTION-FRAMES - (->ExceptionFrame catch-block - catch-exception - finally-block - continue-block - (aget-object state EXCEPTION-FRAMES)))) - -(defn process-exception [state] - (let [exception-frame (aget-object state EXCEPTION-FRAMES) - catch-block (:catch-block exception-frame) - catch-exception (:catch-exception exception-frame) - exception (aget-object state CURRENT-EXCEPTION)] - (cond - (and exception - (not exception-frame)) - (throw exception) - - (and exception - catch-block - (or (= :default catch-exception) - (instance? catch-exception exception))) - (ioc/aset-all! state - STATE-IDX - catch-block - VALUE-IDX - exception - CURRENT-EXCEPTION - nil - EXCEPTION-FRAMES - (assoc exception-frame - :catch-block nil - :catch-exception nil)) - - - (and exception - (not catch-block) - (not (:finally-block exception-frame))) - - (do (ioc/aset-all! state - EXCEPTION-FRAMES - (:prev exception-frame)) - (recur state)) - - (and exception - (not catch-block) - (:finally-block exception-frame)) - (ioc/aset-all! state - STATE-IDX - (:finally-block exception-frame) - EXCEPTION-FRAMES - (assoc exception-frame - :finally-block nil)) - - (and (not exception) - (:finally-block exception-frame)) - (do (ioc/aset-all! state - STATE-IDX - (:finally-block exception-frame) - EXCEPTION-FRAMES - (assoc exception-frame - :finally-block nil))) - - (and (not exception) - (not (:finally-block exception-frame))) - (do (ioc/aset-all! state - STATE-IDX - (:continue-block exception-frame) - EXCEPTION-FRAMES - (:prev exception-frame))) - - :else (throw (js/Error. "No matching clause"))))) diff --git a/src/main/clojure/cljs/core/async/impl/ioc_macros.clj b/src/main/clojure/cljs/core/async/impl/ioc_macros.clj index 1108514..f308bd8 100644 --- a/src/main/clojure/cljs/core/async/impl/ioc_macros.clj +++ b/src/main/clojure/cljs/core/async/impl/ioc_macros.clj @@ -345,42 +345,54 @@ :recur))) -(defrecord Try [catch-block catch-exception finally-block continue-block] +(defrecord PushTry [catch-block] IInstruction (reads-from [this] []) (writes-to [this] []) - (block-references [this] [catch-block finally-block continue-block]) + (block-references [this] [catch-block]) IEmittableInstruction (emit-instruction [this state-sym] - `[~'_ (cljs.core.async.impl.ioc-helpers/add-exception-frame ~state-sym - ~catch-block - ~catch-exception - ~finally-block - ~continue-block)])) - -(defrecord ProcessExceptionWithValue [value] - IInstruction - (reads-from [this] [value]) + `[~'_ (aset-all! ~state-sym ~EXCEPTION-FRAMES (cons ~catch-block (aget ~state-sym ~EXCEPTION-FRAMES)))])) + +(defrecord PopTry [] + IInstruction + (reads-from [this] []) (writes-to [this] []) (block-references [this] []) + IEmittableInstruction + (emit-instruction [this state-sym] + `[~'_ (aset-all! ~state-sym ~EXCEPTION-FRAMES (rest (aget ~state-sym ~EXCEPTION-FRAMES)))])) + +(defrecord CatchHandler [catches] + IInstruction + (reads-from [this] []) + (writes-to [this] []) + (block-references [this] (map first catches)) ITerminator (terminate-block [this state-sym _] - `(do (aset-all! ~state-sym - ~VALUE-IDX - ~value) - (cljs.core.async.impl.ioc-helpers/process-exception ~state-sym) - :recur))) - -(defrecord EndCatchFinally [] + (let [ex (gensym 'ex)] + `(let [~ex (aget ~state-sym ~VALUE-IDX)] + (aset-all! ~state-sym ~CURRENT-EXCEPTION ~ex) + (cond + ~@(for [[handler-idx type] catches + i [(if (= type :default) + `true + `(instance? ~type ~ex)) ` (aset-all! ~state-sym + ~STATE-IDX ~handler-idx + ~CURRENT-EXCEPTION nil)]] + i) + :else (throw ~ex)) + :recur)))) + +(defrecord EndFinally [] IInstruction (reads-from [this] []) (writes-to [this] []) (block-references [this] []) - ITerminator - (terminate-block [this state-sym _] - `(do (cljs.core.async.impl.ioc-helpers/process-exception ~state-sym) - :recur))) - + IEmittableInstruction + (emit-instruction [this state-sym] + `[~'_ (when-let [e# (aget ~state-sym ~CURRENT-EXCEPTION)] + (throw e#))])) ;; Dispatch clojure forms based on data type @@ -412,10 +424,19 @@ inst-id (add-instruction (->Call args-ids))] inst-id)) + +(defn local-init-to-ssa [init] + (gen-plan + [bind-id (item-to-ssa init) + bind-id (if (::global (meta bind-id)) + (add-instruction (->Const bind-id)) + (fn [p] [bind-id p]))] + bind-id)) + (defn let-binding-to-ssa [[sym bind]] (gen-plan - [bind-id (item-to-ssa bind) + [bind-id (local-init-to-ssa bind) _ (push-alter-binding :locals assoc sym bind-id)] bind-id)) @@ -439,7 +460,7 @@ [local-val-ids (all (map ; parallel bind (fn [sym init] (gen-plan - [itm-id (item-to-ssa init) + [itm-id (local-init-to-ssa init) _ (push-alter-binding :locals assoc sym itm-id)] itm-id)) syms @@ -551,52 +572,90 @@ ret-id (add-instruction (->Dot target-id method args-ids))] ret-id))) +(defn destructure-try + [body] + (reduce + (fn [accum form] + (case (:state accum) + :body (cond + (and (seq? form) (= (first form) 'catch)) (-> accum + (assoc :state :catch) + (update-in [:catches] conj form)) + (and (seq? form) (= (first form) 'finally)) (-> accum + (assoc :state :finally) + (assoc :finally form)) + :else (update-in accum [:body] conj form)) + :catch (cond + (and (seq? form) (= (first form) 'catch)) (-> accum + (assoc :state :catch) + (update-in [:catches] conj form)) + (and (seq? form) (= (first form) 'finally)) (-> accum + (assoc :state :finally) + (assoc :finally form)) + :else (throw (Exception. "Only catch or finally clause can follow catch in try expression"))) + :finally (throw (Exception. "finally clause must be last in try expression")))) + {:state :body + :body [] + :catches [] + :finally nil} + body)) + (defmethod sexpr-to-ssa 'try [[_ & body]] - (let [finally-fn (every-pred seq? (comp (partial = 'finally) first)) - catch-fn (every-pred seq? (comp (partial = 'catch) first)) - finally (next (first (filter finally-fn body))) - body (remove finally-fn body) - catch (next (first (filter catch-fn body))) - [ex ex-bind & catch-body] catch - body (remove catch-fn body)] + (let [{:keys [body catches finally] :as m} (destructure-try body)] (gen-plan - [end-blk (add-block) + [body-block (add-block) + exit-block (add-block) finally-blk (if finally (gen-plan [cur-blk (get-block) - blk (add-block) - _ (set-block blk) - value-id (add-instruction (->Const ::value)) - _ (all (map item-to-ssa finally)) - _ (add-instruction (->EndCatchFinally)) + finally-blk (add-block) + _ (set-block finally-blk) + _ (add-instruction (->PopTry)) + result-id (add-instruction (->Const ::value)) + _ (item-to-ssa (cons 'do (rest finally))) + ;; rethrow exception on exception path + _ (add-instruction (->EndFinally)) + _ (add-instruction (->Jmp result-id exit-block)) _ (set-block cur-blk)] - blk) - (no-op)) - catch-blk (if catch - (gen-plan - [cur-blk (get-block) - blk (add-block) - _ (set-block blk) - ex-id (add-instruction (->Const ::value)) - _ (push-alter-binding :locals assoc ex-bind ex-id) - ids (all (map item-to-ssa catch-body)) - _ (add-instruction (->ProcessExceptionWithValue (last ids))) - _ (pop-binding :locals) - _ (set-block cur-blk) - _ (push-alter-binding :catch (fnil conj []) [ex blk])] - blk) - (no-op)) - body-blk (add-block) - _ (add-instruction (->Jmp nil body-blk)) - _ (set-block body-blk) - _ (add-instruction (->Try catch-blk ex finally-blk end-blk)) - ids (all (map item-to-ssa body)) - _ (if catch - (pop-binding :catch) + finally-blk) + (gen-plan [] exit-block)) + catch-blocks (all + (for [[_ ex ex-bind & catch-body] catches] + (gen-plan + [cur-blk (get-block) + catch-blk (add-block) + _ (set-block catch-blk) + ex-id (add-instruction (->Const ::value)) + ;; TODO: type hint ex-bind? + _ (push-alter-binding :locals assoc ex-bind ex-id) + result-id (item-to-ssa (cons 'do catch-body)) + ;; if there is a finally, jump to it after + ;; handling the exception, if not jump to exit + _ (add-instruction (->Jmp result-id finally-blk)) + _ (pop-binding :locals) + _ (set-block cur-blk)] + [catch-blk ex]))) + catch-handler-block (add-block) + cur-blk (get-block) + _ (set-block catch-handler-block) + _ (add-instruction (->PopTry)) + _ (add-instruction (->CatchHandler catch-blocks)) + _ (set-block cur-blk) + _ (add-instruction (->Jmp nil body-block)) + _ (set-block body-block) + ;; the finally gets pushed on to the exception handler stack, so + ;; it will be executed if there is an exception + _ (if finally + (add-instruction (->PushTry finally-blk)) (no-op)) - _ (add-instruction (->ProcessExceptionWithValue (last ids))) - _ (set-block end-blk) + _ (add-instruction (->PushTry catch-handler-block)) + body (item-to-ssa (cons 'do body)) + _ (add-instruction (->PopTry)) + ;; if the body finishes executing normally, jump to the finally + ;; block, if it exists + _ (add-instruction (->Jmp body finally-blk)) + _ (set-block exit-block) ret (add-instruction (->Const ::value))] ret))) @@ -723,8 +782,7 @@ (fn [p] [(locals x) p]) (fn [p] - [x p]) - #_(add-instruction (->Const x)))] + [(vary-meta x assoc ::global true) p]))] inst-id)) (defmethod -item-to-ssa :map @@ -858,9 +916,12 @@ (if (cljs.core/keyword-identical? result# :recur) (recur) result#))) - (catch js/Object ex# - (aset-all! ~state-sym ~CURRENT-EXCEPTION ex#) - (cljs.core.async.impl.ioc-helpers/process-exception ~state-sym) + (catch :default ex# + (aset-all! ~state-sym ~VALUE-IDX ex#) + (if (seq (aget ~state-sym ~EXCEPTION-FRAMES)) + (aset-all! ~state-sym + ~STATE-IDX (first (aget ~state-sym ~EXCEPTION-FRAMES))) + (throw ex#)) :recur))] (if (cljs.core/keyword-identical? ret-value# :recur) (recur ~state-sym) diff --git a/src/main/clojure/cljs/core/async/impl/timers.cljs b/src/main/clojure/cljs/core/async/impl/timers.cljs index 591e206..b0fc9be 100644 --- a/src/main/clojure/cljs/core/async/impl/timers.cljs +++ b/src/main/clojure/cljs/core/async/impl/timers.cljs @@ -46,7 +46,8 @@ ([x k level update] (if-not (neg? level) (let [x (loop [x x] - (if-let [x' (aget (.-forward x) level)] + (if-let [x' (when (< level (alength (.-forward x))) + (aget (.-forward x) level))] (if (< (.-key x') k) (recur x') x) @@ -76,22 +77,25 @@ (when (<= i level) (let [links (.-forward (aget update i))] (aset (.-forward x) i (aget links i)) - (aset links i x))))))))) + (aset links i x)) + (recur (inc i))))))))) (remove [coll k] (let [update (make-array MAX_LEVEL) x (least-greater-node header k level update) - x (aget (.-forward x) 0)] + x (when-not (zero? (alength (.-forward x))) + (aget (.-forward x) 0))] (when (and (not (nil? x)) (== (.-key x) k)) (loop [i 0] (when (<= i level) (let [links (.-forward (aget update i))] - (if (identical? (aget links i) x) + (if (identical? x (when (< i (alength links)) + (aget links i))) (do (aset links i (aget (.-forward x) i)) (recur (inc i))) (recur (inc i)))))) - (while (and (> level 0) + (while (and (< 0 level (alength (.-forward header))) (nil? (aget (.-forward header) level))) (set! level (dec level)))))) @@ -99,22 +103,27 @@ (loop [x header level level] (if-not (neg? level) (let [nx (loop [x x] - (let [x' (aget (.-forward x) level)] - (when-not (nil? x') - (if (>= (.-key x') k) - x' - (recur x')))))] - (if-not (nil? nx) + (let [x' (when (< level (alength (.-forward x))) + (aget (.-forward x) level))] + (if-not (nil? x') + (if (> (.-key x') k) + x + (recur x')) + (when (zero? level) + x))))] + (if nx (recur nx (dec level)) (recur x (dec level)))) - (when-not (identical? x header) - x)))) - + (if (= (.-key x) k) + x + (aget (.-forward x) 0))))) + (floorEntry [coll k] (loop [x header level level] (if-not (neg? level) (let [nx (loop [x x] - (let [x' (aget (.-forward x) level)] + (let [x' (when (< level (alength (.-forward x))) + (aget (.-forward x) level))] (if-not (nil? x') (if (> (.-key x') k) x @@ -164,4 +173,3 @@ (impl/close! timeout-channel)) msecs) timeout-channel)))) - diff --git a/src/main/clojure/cljs/core/async/interop.clj b/src/main/clojure/cljs/core/async/interop.clj new file mode 100644 index 0000000..4c66551 --- /dev/null +++ b/src/main/clojure/cljs/core/async/interop.clj @@ -0,0 +1,20 @@ +;; Copyright (c) Rich Hickey and contributors. All rights reserved. +;; The use and distribution terms for this software are covered by the +;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +;; which can be found in the file epl-v10.html at the root of this distribution. +;; By using this software in any fashion, you are agreeing to be bound by +;; the terms of this license. +;; You must not remove this notice, or any other, from this software. + +(ns cljs.core.async.interop) + +(defmacro c ~exp))] + (if (and + (instance? cljs.core/ExceptionInfo v#) + (= (:error (ex-data v#)) :promise-error)) + (throw v#) + v#))) diff --git a/src/main/clojure/cljs/core/async/interop.cljs b/src/main/clojure/cljs/core/async/interop.cljs new file mode 100644 index 0000000..2a9a5be --- /dev/null +++ b/src/main/clojure/cljs/core/async/interop.cljs @@ -0,0 +1,29 @@ +;; Copyright (c) Rich Hickey and contributors. All rights reserved. +;; The use and distribution terms for this software are covered by the +;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +;; which can be found in the file epl-v10.html at the root of this distribution. +;; By using this software in any fashion, you are agreeing to be bound by +;; the terms of this license. +;; You must not remove this notice, or any other, from this software. + +(ns cljs.core.async.interop + (:require-macros [cljs.core.async.interop]) + (:require [cljs.core.async :as async])) + +(defn p->c + "EXPERIMENTAL: Puts the promise resolution into a promise-chan and returns it. + The value of a rejected promise will be wrapped in a instance of + ExceptionInfo, acessible via ex-cause." + [p] + (let [c (async/promise-chan)] + (.then p + (fn [res] + (if (nil? res) + (async/close! c) + (async/put! c res))) + (fn [err] + (async/put! c + (ex-info "Promise error" + {:error :promise-error} + err)))) + c)) diff --git a/src/main/clojure/cljs/core/async/macros.clj b/src/main/clojure/cljs/core/async/macros.clj index 6c6a557..561f51b 100644 --- a/src/main/clojure/cljs/core/async/macros.clj +++ b/src/main/clojure/cljs/core/async/macros.clj @@ -1,98 +1,29 @@ +;; Copyright (c) Rich Hickey and contributors. All rights reserved. +;; The use and distribution terms for this software are covered by the +;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +;; which can be found in the file epl-v10.html at the root of this distribution. +;; By using this software in any fashion, you are agreeing to be bound by +;; the terms of this license. +;; You must not remove this notice, or any other, from this software. + (ns cljs.core.async.macros - (:require [cljs.core.async.impl.ioc-macros :as ioc])) + (:require [cljs.core.async :as async])) -(defmacro go - "Asynchronously executes the body, returning immediately to the - calling thread. Additionally, any visible calls to ! and alt!/alts! - channel operations within the body will block (if necessary) by - 'parking' the calling thread rather than tying up an OS thread (or - the only JS thread when in ClojureScript). Upon completion of the - operation, the body will be resumed. +;; Idea taken from Potemkin: https://github.com/ztellman/potemkin/blob/master/src/potemkin/namespaces.clj +(defn- setup-macro-shim + [src dst] + (alter-meta! dst merge (dissoc (meta src) :name)) + (.setMacro dst) + (add-watch src dst + (fn [_ src old new] + (alter-var-root dst (constantly @src)) + (alter-meta! dst merge (dissoc (meta src) :name))))) - Returns a channel which will receive the result of the body when - completed" - [& body] - `(let [c# (cljs.core.async/chan 1)] - (cljs.core.async.impl.dispatch/run - (fn [] - (let [f# ~(ioc/state-machine body 1 &env ioc/async-custom-terminators) - state# (-> (f#) - (ioc/aset-all! cljs.core.async.impl.ioc-helpers/USER-START-IDX c#))] - (cljs.core.async.impl.ioc-helpers/run-state-machine-wrapped state#)))) - c#)) +(def go #'async/go) +(setup-macro-shim #'async/go #'go) +(def go-loop #'async/go-loop) +(setup-macro-shim #'async/go-loop #'go-loop) -(defn do-alt [alts clauses] - (assert (even? (count clauses)) "unbalanced clauses") - (let [clauses (partition 2 clauses) - opt? #(keyword? (first %)) - opts (filter opt? clauses) - clauses (remove opt? clauses) - [clauses bindings] - (reduce - (fn [[clauses bindings] [ports expr]] - (let [ports (if (vector? ports) ports [ports]) - [ports bindings] - (reduce - (fn [[ports bindings] port] - (if (vector? port) - (let [[port val] port - gp (gensym) - gv (gensym)] - [(conj ports [gp gv]) (conj bindings [gp port] [gv val])]) - (let [gp (gensym)] - [(conj ports gp) (conj bindings [gp port])]))) - [[] bindings] ports)] - [(conj clauses [ports expr]) bindings])) - [[] []] clauses) - gch (gensym "ch") - gret (gensym "ret")] - `(let [~@(mapcat identity bindings) - [val# ~gch :as ~gret] (~alts [~@(apply concat (map first clauses))] ~@(apply concat opts))] - (cond - ~@(mapcat (fn [[ports expr]] - [`(or ~@(map (fn [port] - `(= ~gch ~(if (vector? port) (first port) port))) - ports)) - (if (and (seq? expr) (vector? (first expr))) - `(let [~(first expr) ~gret] ~@(rest expr)) - expr)]) - clauses) - (= ~gch :default) val#)))) - -(defmacro alt! - "Makes a single choice between one of several channel operations, - as if by alts!, returning the value of the result expr corresponding - to the operation completed. Must be called inside a (go ...) block. - - Each clause takes the form of: - - channel-op[s] result-expr - - where channel-ops is one of: - - take-port - a single port to take - [take-port | [put-port put-val] ...] - a vector of ports as per alts! - :default | :priority - an option for alts! - - and result-expr is either a list beginning with a vector, whereupon that - vector will be treated as a binding for the [val port] return of the - operation, else any other expression. - - (alt! - [c t] ([val ch] (foo ch val)) - x ([v] v) - [[out val]] :wrote - :default 42) - - Each option may appear at most once. The choice and parking - characteristics are those of alts!." - - [& clauses] - (do-alt 'alts! clauses)) - - -(defmacro go-loop - "Like (go (loop ...))" - [bindings & body] - `(go (loop ~bindings ~@body))) +(def alt! #'async/alt!) +(setup-macro-shim #'async/alt! #'alt!) diff --git a/src/main/clojure/cljs/core/async.clj b/src/main/clojure/cljs/core/async.clj new file mode 100644 index 0000000..74cfd6d --- /dev/null +++ b/src/main/clojure/cljs/core/async.clj @@ -0,0 +1,106 @@ +;; Copyright (c) Rich Hickey and contributors. All rights reserved. +;; The use and distribution terms for this software are covered by the +;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +;; which can be found in the file epl-v10.html at the root of this distribution. +;; By using this software in any fashion, you are agreeing to be bound by +;; the terms of this license. +;; You must not remove this notice, or any other, from this software. + +(ns cljs.core.async + (:require [cljs.core.async.impl.ioc-macros :as ioc])) + +(defmacro go + "Asynchronously executes the body, returning immediately to the + calling thread. Additionally, any visible calls to ! and alt!/alts! + channel operations within the body will block (if necessary) by + 'parking' the calling thread rather than tying up an OS thread (or + the only JS thread when in ClojureScript). Upon completion of the + operation, the body will be resumed. + + Returns a channel which will receive the result of the body when + completed" + [& body] + `(let [c# (cljs.core.async/chan 1)] + (cljs.core.async.impl.dispatch/run + (fn [] + (let [f# ~(ioc/state-machine body 1 &env ioc/async-custom-terminators) + state# (-> (f#) + (ioc/aset-all! cljs.core.async.impl.ioc-helpers/USER-START-IDX c#))] + (cljs.core.async.impl.ioc-helpers/run-state-machine-wrapped state#)))) + c#)) + + +(defn do-alt [alts clauses] + (assert (even? (count clauses)) "unbalanced clauses") + (let [clauses (partition 2 clauses) + opt? #(keyword? (first %)) + opts (filter opt? clauses) + clauses (remove opt? clauses) + [clauses bindings] + (reduce + (fn [[clauses bindings] [ports expr]] + (let [ports (if (vector? ports) ports [ports]) + [ports bindings] + (reduce + (fn [[ports bindings] port] + (if (vector? port) + (let [[port val] port + gp (gensym) + gv (gensym)] + [(conj ports [gp gv]) (conj bindings [gp port] [gv val])]) + (let [gp (gensym)] + [(conj ports gp) (conj bindings [gp port])]))) + [[] bindings] ports)] + [(conj clauses [ports expr]) bindings])) + [[] []] clauses) + gch (gensym "ch") + gret (gensym "ret")] + `(let [~@(mapcat identity bindings) + [val# ~gch :as ~gret] (~alts [~@(apply concat (map first clauses))] ~@(apply concat opts))] + (cond + ~@(mapcat (fn [[ports expr]] + [`(or ~@(map (fn [port] + `(= ~gch ~(if (vector? port) (first port) port))) + ports)) + (if (and (seq? expr) (vector? (first expr))) + `(let [~(first expr) ~gret] ~@(rest expr)) + expr)]) + clauses) + (= ~gch :default) val#)))) + +(defmacro alt! + "Makes a single choice between one of several channel operations, + as if by alts!, returning the value of the result expr corresponding + to the operation completed. Must be called inside a (go ...) block. + + Each clause takes the form of: + + channel-op[s] result-expr + + where channel-ops is one of: + + take-port - a single port to take + [take-port | [put-port put-val] ...] - a vector of ports as per alts! + :default | :priority - an option for alts! + + and result-expr is either a list beginning with a vector, whereupon that + vector will be treated as a binding for the [val port] return of the + operation, else any other expression. + + (alt! + [c t] ([val ch] (foo ch val)) + x ([v] v) + [[out val]] :wrote + :default 42) + + Each option may appear at most once. The choice and parking + characteristics are those of alts!." + + [& clauses] + (do-alt 'alts! clauses)) + + +(defmacro go-loop + "Like (go (loop ...))" + [bindings & body] + `(go (loop ~bindings ~@body))) diff --git a/src/main/clojure/cljs/core/async.cljs b/src/main/clojure/cljs/core/async.cljs index 9cf8510..efd38df 100644 --- a/src/main/clojure/cljs/core/async.cljs +++ b/src/main/clojure/cljs/core/async.cljs @@ -1,3 +1,11 @@ +;; Copyright (c) Rich Hickey and contributors. All rights reserved. +;; The use and distribution terms for this software are covered by the +;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +;; which can be found in the file epl-v10.html at the root of this distribution. +;; By using this software in any fashion, you are agreeing to be bound by +;; the terms of this license. +;; You must not remove this notice, or any other, from this software. + (ns cljs.core.async (:refer-clojure :exclude [reduce transduce into merge map take partition partition-by]) (:require [cljs.core.async.impl.protocols :as impl] @@ -5,9 +13,10 @@ [cljs.core.async.impl.buffers :as buffers] [cljs.core.async.impl.timers :as timers] [cljs.core.async.impl.dispatch :as dispatch] - [cljs.core.async.impl.ioc-helpers :as helpers]) + [cljs.core.async.impl.ioc-helpers :as helpers] + [goog.array :as garray]) (:require-macros [cljs.core.async.impl.ioc-macros :as ioc] - [cljs.core.async.macros :refer [go go-loop]])) + [cljs.core.async :refer [go go-loop]])) (defn- fn-handler ([f] (fn-handler f true)) @@ -113,10 +122,10 @@ (throw (js/Error. ">! used not in (go ...) block"))) (defn put! - "Asynchronously puts a val into port, calling fn0 (if supplied) when + "Asynchronously puts a val into port, calling fn1 (if supplied) when complete. nil values are not allowed. Will throw if closed. If on-caller? (default true) is true, and the put is immediately - accepted, will call fn0 on calling thread. Returns nil." + accepted, will call fn1 on calling thread. Returns nil." ([port val] (if-let [ret (impl/put! port val fhnop)] @ret @@ -140,15 +149,9 @@ [n] (let [a (make-array n)] (dotimes [x n] - (aset a x 0)) - (loop [i 1] - (if (= i n) - a - (do - (let [j (rand-int i)] - (aset a i (aget a j)) - (aset a j i) - (recur (inc i)))))))) + (aset a x x)) + (garray/shuffle a) + a)) (defn- alt-flag [] (let [flag (atom true)] @@ -172,6 +175,7 @@ (defn do-alts "returns derefable [val port] if immediate, nil if enqueued" [fret ports opts] + (assert (pos? (count ports)) "alts must have at least one channel operation") (let [flag (alt-flag) n (count ports) idxs (random-array n) @@ -382,14 +386,14 @@ (let [ret (! ch (first vs))) @@ -398,14 +402,25 @@ (close! ch)))))) -(defn to-chan +(defn to-chan! "Creates and returns a channel which contains the contents of coll, closing when exhausted." [coll] (let [ch (chan (bounded-count 100 coll))] - (onto-chan ch coll) + (onto-chan! ch coll) ch)) +(defn onto-chan + "Deprecated - use onto-chan!" + {:deprecated "1.2"} + ([ch coll] (onto-chan! ch coll true)) + ([ch coll close?] (onto-chan! ch coll close?))) + +(defn to-chan + "Deprecated - use to-chan!" + {:deprecated "1.2"} + [coll] + (to-chan! coll)) (defprotocol Mux (muxch* [_])) @@ -450,7 +465,6 @@ (reset! dctr (count chs)) (doseq [c chs] (when-not (put! c val done) - (done nil) (untap* m c))) ;;wait for all (when (seq chs) @@ -517,7 +531,7 @@ solo-modes #{:mute :pause} attrs (conj solo-modes :solo) solo-mode (atom :mute) - change (chan) + change (chan (sliding-buffer 1)) changed #(put! change true) pick (fn [attr chs] (reduce-kv diff --git a/src/main/clojure/clojure/core/async/impl/channels.clj b/src/main/clojure/clojure/core/async/impl/channels.clj index 063ffef..917cdef 100644 --- a/src/main/clojure/clojure/core/async/impl/channels.clj +++ b/src/main/clojure/clojure/core/async/impl/channels.clj @@ -52,7 +52,7 @@ [this] (let [iter (.iterator puts)] (when (.hasNext iter) - (loop [^Lock putter (.next iter)] + (loop [[^Lock putter] (.next iter)] (.lock putter) (let [put-cb (and (impl/active? putter) (impl/commit putter))] (.unlock putter) @@ -175,7 +175,7 @@ (let [val (impl/remove! buf) iter (.iterator puts) [done? cbs] - (when (.hasNext iter) + (when (and (not (impl/full? buf)) (.hasNext iter)) (loop [cbs [] [^Lock putter val] (.next iter)] (.lock putter) @@ -300,4 +300,3 @@ (add! buf val) (catch Throwable t (handle buf exh t))))))))) - diff --git a/src/main/clojure/clojure/core/async/impl/concurrent.clj b/src/main/clojure/clojure/core/async/impl/concurrent.clj index a197f03..732fb0b 100644 --- a/src/main/clojure/clojure/core/async/impl/concurrent.clj +++ b/src/main/clojure/clojure/core/async/impl/concurrent.clj @@ -15,15 +15,23 @@ (defn counted-thread-factory "Create a ThreadFactory that maintains a counter for naming Threads. name-format specifies thread names - use %d to include counter - daemon is a flag for whether threads are daemons or not" - [name-format daemon] - (let [counter (atom 0)] - (reify - ThreadFactory - (newThread [this runnable] - (doto (Thread. runnable) - (.setName (format name-format (swap! counter inc))) - (.setDaemon daemon)))))) + daemon is a flag for whether threads are daemons or not + opts is an options map: + init-fn - function to run when thread is created" + ([name-format daemon] + (counted-thread-factory name-format daemon nil)) + ([name-format daemon {:keys [init-fn] :as opts}] + (let [counter (atom 0)] + (reify + ThreadFactory + (newThread [this runnable] + (let [body (if init-fn + (fn [] (init-fn) (.run ^Runnable runnable)) + runnable) + t (Thread. ^Runnable body)] + (doto t + (.setName (format name-format (swap! counter inc))) + (.setDaemon daemon)))))))) (defonce ^{:doc "Number of processors reported by the JVM"} diff --git a/src/main/clojure/clojure/core/async/impl/dispatch.clj b/src/main/clojure/clojure/core/async/impl/dispatch.clj index f31569a..c01cb05 100644 --- a/src/main/clojure/clojure/core/async/impl/dispatch.clj +++ b/src/main/clojure/clojure/core/async/impl/dispatch.clj @@ -13,7 +13,21 @@ (set! *warn-on-reflection* true) -(defonce executor (delay (tp/thread-pool-executor))) +(defonce ^:private in-dispatch (ThreadLocal.)) + +(defonce executor + (delay (tp/thread-pool-executor #(.set ^ThreadLocal in-dispatch true)))) + +(defn in-dispatch-thread? + "Returns true if the current thread is a go block dispatch pool thread" + [] + (boolean (.get ^ThreadLocal in-dispatch))) + +(defn check-blocking-in-dispatch + "If the current thread is a dispatch pool thread, throw an exception" + [] + (when (.get ^ThreadLocal in-dispatch) + (throw (IllegalStateException. "Invalid blocking call in dispatch thread")))) (defn run "Runs Runnable r in a thread pool thread" diff --git a/src/main/clojure/clojure/core/async/impl/exec/threadpool.clj b/src/main/clojure/clojure/core/async/impl/exec/threadpool.clj index e4fa4f8..95bcd04 100644 --- a/src/main/clojure/clojure/core/async/impl/exec/threadpool.clj +++ b/src/main/clojure/clojure/core/async/impl/exec/threadpool.clj @@ -17,15 +17,16 @@ "Value is set via clojure.core.async.pool-size system property; defaults to 8; uses a delay so property can be set from code after core.async namespace is loaded but before any use of the async thread pool." - (delay (or (when-let [prop (System/getProperty "clojure.core.async.pool-size")] - (Long/parseLong prop)) - 8))) + (delay (or (Long/getLong "clojure.core.async.pool-size") 8))) (defn thread-pool-executor - [] - (let [executor-svc (Executors/newFixedThreadPool - @pool-size - (conc/counted-thread-factory "async-dispatch-%d" true))] - (reify impl/Executor - (impl/exec [this r] - (.execute executor-svc ^Runnable r))))) + ([] + (thread-pool-executor nil)) + ([init-fn] + (let [executor-svc (Executors/newFixedThreadPool + @pool-size + (conc/counted-thread-factory "async-dispatch-%d" true + {:init-fn init-fn}))] + (reify impl/Executor + (impl/exec [this r] + (.execute executor-svc ^Runnable r)))))) diff --git a/src/main/clojure/clojure/core/async/impl/ioc_macros.clj b/src/main/clojure/clojure/core/async/impl/ioc_macros.clj index d4d7e5e..22f2b76 100644 --- a/src/main/clojure/clojure/core/async/impl/ioc_macros.clj +++ b/src/main/clojure/clojure/core/async/impl/ioc_macros.clj @@ -36,8 +36,7 @@ (def ^:const VALUE-IDX 2) (def ^:const BINDINGS-IDX 3) (def ^:const EXCEPTION-FRAMES 4) -(def ^:const CURRENT-EXCEPTION 5) -(def ^:const USER-START-IDX 6) +(def ^:const USER-START-IDX 5) (defn aset-object [^AtomicReferenceArray arr idx ^Object o] (.set arr idx o)) @@ -227,8 +226,9 @@ (defrecord RawCode [ast locals] IInstruction (reads-from [this] - (keep (or locals #{}) - (map :name (-> ast :env :locals vals)))) + (for [local (map :name (-> ast :env :locals vals)) + :when (contains? locals local)] + (get locals local))) (writes-to [this] [(:id this)]) (block-references [this] []) IEmittableInstruction @@ -237,8 +237,7 @@ `[~@(->> (-> ast :env :locals vals) (map #(select-keys % [:op :name :form])) (filter (fn [local] - (when locals - (get locals (:name local))))) + (contains? locals (:name local)))) set (mapcat (fn [local] @@ -413,25 +412,21 @@ (terminate-block [this state-sym _] (let [ex (gensym 'ex)] `(let [~ex (aget-object ~state-sym ~VALUE-IDX)] - (aset-all! ~state-sym ~CURRENT-EXCEPTION ~ex) (cond ~@(for [[handler-idx type] catches - i [`(instance? ~type ~ex) ` (aset-all! ~state-sym - ~STATE-IDX ~handler-idx - ~CURRENT-EXCEPTION nil)]] + i [`(instance? ~type ~ex) `(aset-all! ~state-sym ~STATE-IDX ~handler-idx)]] i) :else (throw ~ex)) :recur)))) -(defrecord EndFinally [] - IInstruction - (reads-from [this] []) +(defrecord EndFinally [exception-local] + IInstruction + (reads-from [this] [exception-local]) (writes-to [this] []) (block-references [this] []) IEmittableInstruction (emit-instruction [this state-sym] - `[~'_ (when-let [e# (aget-object ~state-sym ~CURRENT-EXCEPTION)] - (throw e#))])) + `[~'_ (throw ~exception-local)])) ;; Dispatch clojure forms based on :op (def -item-to-ssa nil) ;; for help in the repl @@ -644,67 +639,77 @@ (defmethod -item-to-ssa :try [{:keys [catches body finally] :as ast}] - (gen-plan - [body-block (add-block) - exit-block (add-block) - ;; Two routes to the finally block, via normal execution and - ;; exception execution - finally-blk (if finally - (gen-plan - [cur-blk (get-block) - finally-blk (add-block) - _ (set-block finally-blk) - result-id (add-instruction (->Const ::value)) - _ (item-to-ssa finally) - ;; rethrow exception on exception path - _ (add-instruction (->EndFinally)) - _ (add-instruction (->Jmp result-id exit-block)) - _ (set-block cur-blk)] - finally-blk) - (gen-plan [] exit-block)) - catch-blocks (all - (for [{ex-bind :local {ex :val} :class catch-body :body} catches] - (gen-plan - [cur-blk (get-block) - catch-blk (add-block) - _ (set-block catch-blk) - ex-id (add-instruction (->Const ::value)) - _ (push-alter-binding :locals assoc (:name ex-bind) - (vary-meta ex-id merge (when (:tag ex-bind) - {:tag (.getName ^Class (:tag ex-bind))}))) - result-id (item-to-ssa catch-body) - ;; if there is a finally, jump to it after - ;; handling the exception, if not jump to exit - _ (add-instruction (->Jmp result-id finally-blk)) - _ (pop-binding :locals) - _ (set-block cur-blk)] - [catch-blk ex]))) - ;; catch block handler routes exceptions to the correct handler, - ;; rethrows if there is no match - catch-handler-block (add-block) - cur-blk (get-block) - _ (set-block catch-handler-block) - _ (add-instruction (->CatchHandler catch-blocks)) - _ (set-block cur-blk) - _ (add-instruction (->Jmp nil body-block)) - _ (set-block body-block) - ;; the finally gets pushed on to the exception handler stack, so - ;; it will be executed if there is an exception - _ (if finally - (add-instruction (->PushTry finally-blk)) - (no-op)) - _ (add-instruction (->PushTry catch-handler-block)) - body (item-to-ssa body) - _ (add-instruction (->PopTry)) - _ (if finally - (add-instruction (->PopTry)) - (no-op)) - ;; if the body finishes executing normally, jump to the finally - ;; block, if it exists - _ (add-instruction (->Jmp body finally-blk)) - _ (set-block exit-block) - ret (add-instruction (->Const ::value))] - ret)) + (let [make-finally (fn [exit-block rethrow?] + (if finally + (gen-plan + [cur-blk (get-block) + finally-blk (add-block) + _ (set-block finally-blk) + ;; catch block has to pop itself off of + ;; EXCEPTION-FRAMES. every try/catch pushes at + ;; least 1 frame on to EXCEPTION-FRAMES, + ;; try/catch/finally pushes 2. The exception + ;; handling machinery around the state machine + ;; pops one off when handling an exception. + _ (add-instruction (->PopTry)) + result-id (add-instruction (->Const ::value)) + _ (item-to-ssa finally) + ;; rethrow exception on exception path + _ (if rethrow? + (add-instruction (->EndFinally result-id)) + (no-op)) + _ (add-instruction (->Jmp result-id exit-block)) + _ (set-block cur-blk)] + finally-blk) + (gen-plan [] exit-block)))] + (gen-plan + [body-block (add-block) + exit-block (add-block) + ;; Two routes to the finally block, via normal execution and + ;; exception execution + finally-blk (make-finally exit-block false) + exception-finally-blk (make-finally exit-block true) + catch-blocks (all + (for [{ex-bind :local {ex :val} :class catch-body :body} catches] + (gen-plan + [cur-blk (get-block) + catch-blk (add-block) + _ (set-block catch-blk) + ex-id (add-instruction (->Const ::value)) + _ (push-alter-binding :locals assoc (:name ex-bind) + (vary-meta ex-id merge (when (:tag ex-bind) + {:tag (.getName ^Class (:tag ex-bind))}))) + result-id (item-to-ssa catch-body) + ;; if there is a finally, jump to it after + ;; handling the exception, if not jump to exit + _ (add-instruction (->Jmp result-id finally-blk)) + _ (pop-binding :locals) + _ (set-block cur-blk)] + [catch-blk ex]))) + ;; catch block handler routes exceptions to the correct handler, + ;; rethrows if there is no match + catch-handler-block (add-block) + cur-blk (get-block) + _ (set-block catch-handler-block) + _ (add-instruction (->PopTry)) ; pop catch-handler-block + _ (add-instruction (->CatchHandler catch-blocks)) + _ (set-block cur-blk) + _ (add-instruction (->Jmp nil body-block)) + _ (set-block body-block) + ;; the finally gets pushed on to the exception handler stack, so + ;; it will be executed if there is an exception + _ (if finally + (add-instruction (->PushTry exception-finally-blk)) + (no-op)) + _ (add-instruction (->PushTry catch-handler-block)) + body (item-to-ssa body) + _ (add-instruction (->PopTry)) ; pop catch-handler-block + ;; if the body finishes executing normally, jump to the finally + ;; block, if it exists + _ (add-instruction (->Jmp body finally-blk)) + _ (set-block exit-block) + ret (add-instruction (->Const ::value))] + ret))) (defmethod -item-to-ssa :throw [{:keys [exception] :as ast}] @@ -940,11 +945,11 @@ (catch Throwable ex# (aset-all! ~state-sym ~VALUE-IDX ex#) (if (seq (aget-object ~state-sym ~EXCEPTION-FRAMES)) - (aset-all! ~state-sym ~STATE-IDX (first (aget-object ~state-sym ~EXCEPTION-FRAMES)) - ~EXCEPTION-FRAMES (rest (aget-object ~state-sym ~EXCEPTION-FRAMES))) + (aset-all! ~state-sym ~STATE-IDX (first (aget-object ~state-sym ~EXCEPTION-FRAMES))) (throw ex#)) :recur) (finally + (aset-object ~state-sym ~BINDINGS-IDX (clojure.lang.Var/getThreadBindingFrame)) (clojure.lang.Var/resetThreadBindingFrame old-frame#)))] (if (identical? ret-value# :recur) (recur ~state-sym) diff --git a/src/main/clojure/clojure/core/async/impl/mutex.clj b/src/main/clojure/clojure/core/async/impl/mutex.clj index 524d05e..7ea29f1 100644 --- a/src/main/clojure/clojure/core/async/impl/mutex.clj +++ b/src/main/clojure/clojure/core/async/impl/mutex.clj @@ -9,8 +9,7 @@ (ns ^{:skip-wiki true} clojure.core.async.impl.mutex (:require [clojure.core.async.impl.protocols :as impl]) - (:import [clojure.core.async Mutex] - [java.util.concurrent.locks Lock ReentrantLock])) + (:import [java.util.concurrent.locks Lock ReentrantLock])) (defn mutex [] (let [m (ReentrantLock.)] diff --git a/src/main/clojure/clojure/core/async/impl/timers.clj b/src/main/clojure/clojure/core/async/impl/timers.clj index eaaf07c..43b5a9d 100644 --- a/src/main/clojure/clojure/core/async/impl/timers.clj +++ b/src/main/clojure/clojure/core/async/impl/timers.clj @@ -40,19 +40,6 @@ (close! [this] (impl/close! channel))) -(defn timeout - "returns a channel that will close after msecs" - [^long msecs] - (let [timeout (+ (System/currentTimeMillis) msecs) - me (.ceilingEntry timeouts-map timeout)] - (or (when (and me (< (.getKey me) (+ timeout TIMEOUT_RESOLUTION_MS))) - (.channel ^TimeoutQueueEntry (.getValue me))) - (let [timeout-channel (channels/chan nil) - timeout-entry (TimeoutQueueEntry. timeout-channel timeout)] - (.put timeouts-map timeout timeout-entry) - (.put timeouts-queue timeout-entry) - timeout-channel)))) - (defn- timeout-worker [] (let [q timeouts-queue] @@ -63,6 +50,21 @@ (recur)))) (defonce timeout-daemon - (doto (Thread. ^Runnable timeout-worker "clojure.core.async.timers/timeout-daemon") - (.setDaemon true) - (.start))) + (delay + (doto (Thread. ^Runnable timeout-worker "clojure.core.async.timers/timeout-daemon") + (.setDaemon true) + (.start)))) + +(defn timeout + "returns a channel that will close after msecs" + [^long msecs] + @timeout-daemon + (let [timeout (+ (System/currentTimeMillis) msecs) + me (.ceilingEntry timeouts-map timeout)] + (or (when (and me (< (.getKey me) (+ timeout TIMEOUT_RESOLUTION_MS))) + (.channel ^TimeoutQueueEntry (.getValue me))) + (let [timeout-channel (channels/chan nil) + timeout-entry (TimeoutQueueEntry. timeout-channel timeout)] + (.put timeouts-map timeout timeout-entry) + (.put timeouts-queue timeout-entry) + timeout-channel)))) diff --git a/src/main/clojure/clojure/core/async/lab.clj b/src/main/clojure/clojure/core/async/lab.clj index 616f9df..1af4260 100644 --- a/src/main/clojure/clojure/core/async/lab.clj +++ b/src/main/clojure/clojure/core/async/lab.clj @@ -6,7 +6,7 @@ ;; the terms of this license. ;; You must not remove this notice, or any other, from this software. -(ns clojure.core.async.lab +(ns ^{:skip-wiki true} clojure.core.async.lab "core.async HIGHLY EXPERIMENTAL feature exploration Caveats: @@ -105,4 +105,4 @@ strongly advised that each of the underlying ports support buffered writes." [& ports] - (->BroadcastingWritePort (set ports))) \ No newline at end of file + (->BroadcastingWritePort (set ports))) diff --git a/src/main/clojure/clojure/core/async.clj b/src/main/clojure/clojure/core/async.clj index 93b79e6..c8124ca 100644 --- a/src/main/clojure/clojure/core/async.clj +++ b/src/main/clojure/clojure/core/async.clj @@ -11,7 +11,14 @@ go blocks are dispatched over an internal thread pool, which defaults to 8 threads. The size of this pool can be modified using -the Java system property `clojure.core.async.pool-size`." +the Java system property `clojure.core.async.pool-size`. + +Set Java system property `clojure.core.async.go-checking` to true +to validate go blocks do not invoke core.async blocking operations. +Property is read once, at namespace load time. Recommended for use +primarily during development. Invalid blocking calls will throw in +go block threads - use Thread.setDefaultUncaughtExceptionHandler() +to catch and handle." (:refer-clojure :exclude [reduce transduce into merge map take partition partition-by bounded-count]) (:require [clojure.core.async.impl.protocols :as impl] @@ -23,9 +30,8 @@ [clojure.core.async.impl.mutex :as mutex] [clojure.core.async.impl.concurrent :as conc] ) - (:import [clojure.core.async ThreadLocalRandom] - [java.util.concurrent.locks Lock] - [java.util.concurrent Executors Executor] + (:import [java.util.concurrent.locks Lock] + [java.util.concurrent Executors Executor ThreadLocalRandom] [java.util ArrayList])) (alias 'core 'clojure.core) @@ -50,6 +56,7 @@ (defn buffer "Returns a fixed buffer of size n. When full, puts will block/park." [n] + (assert (pos? n) "fixed buffers must have size > 0") (buffers/fixed-buffer n)) (defn dropping-buffer @@ -84,7 +91,6 @@ ([buf-or-n] (chan buf-or-n nil)) ([buf-or-n xform] (chan buf-or-n xform nil)) ([buf-or-n xform ex-handler] - (when (and buf-or-n (number? buf-or-n)) (assert (pos? buf-or-n) "fixed buffers must have size > 0")) (when xform (assert buf-or-n "buffer must be supplied when transducer is")) (channels/chan (if (number? buf-or-n) (buffer buf-or-n) buf-or-n) xform ex-handler))) @@ -93,7 +99,8 @@ exception-handler. A promise channel can take exactly one value that consumers will receive. Once full, puts complete but val is dropped (no transfer). Consumers will block until either a value is placed in the channel or the - channel is closed. See chan for the semantics of xform and ex-handler." + channel is closed, then return the value (or nil) forever. See chan for the + semantics of xform and ex-handler." ([] (promise-chan nil)) ([xform] (promise-chan xform nil)) ([xform ex-handler] @@ -104,9 +111,23 @@ [^long msecs] (timers/timeout msecs)) -(defn !! +(defblockingop >!! "puts a val into port. nil values are not allowed. Will block if no - buffer space is available. Returns true unless port is already closed." + buffer space is available. Returns true unless port is already closed. + Not intended for use in direct or transitive calls from (go ...) blocks. + Use the clojure.core.async.go-checking flag to detect invalid use (see + namespace docs)." [port val] (let [p (promise) ret (impl/put! port val (fn-handler (fn [open?] (deliver p open?))))] @@ -159,8 +188,13 @@ "Asynchronously puts a val into port, calling fn1 (if supplied) when complete, passing false iff port is already closed. nil values are not allowed. If on-caller? (default true) is true, and the put is - immediately accepted, will call fn1 on calling thread. Returns - true unless port is already closed." + immediately accepted, will call fn1 on calling thread. + + fn1 may be run in a fixed-size dispatch thread pool and should not + perform blocking IO, including core.async blocking ops (those that + end in !!). + + Returns true unless port is already closed." ([port val] (if-let [ret (impl/put! port val fhnop)] @ret @@ -237,6 +271,7 @@ (defn do-alts "returns derefable [val port] if immediate, nil if enqueued" [fret ports opts] + (assert (pos? (count ports)) "alts must have at least one channel operation") (let [flag (alt-flag) n (count ports) ^ints idxs (random-array n) @@ -263,13 +298,15 @@ (when got (channels/box [(:default opts) :default]))))))) -(defn alts!! +(defblockingop alts!! "Like alts!, except takes will be made as if by !!, will block until completed, and not intended - for use in (go ...) blocks." - [ports & {:as opts}] + be made as if by >!!, will block until completed. + Not intended for use in direct or transitive calls from (go ...) blocks. + Use the clojure.core.async.go-checking flag to detect invalid use (see + namespace docs)." + [ports & opts] (let [p (promise) - ret (do-alts (partial deliver p) ports opts)] + ret (do-alts (partial deliver p) ports (apply hash-map opts))] (if ret @ret (deref p)))) @@ -409,6 +446,11 @@ the only JS thread when in ClojureScript). Upon completion of the operation, the body will be resumed. + go blocks should not (either directly or indirectly) perform operations + that may block indefinitely. Doing so risks depleting the fixed pool of + go block threads, causing all go block processing to stop. This includes + core.async blocking ops (those ending in !!) and other blocking IO. + Returns a channel which will receive the result of the body when completed" [& body] @@ -502,14 +544,10 @@ true)))] (dotimes [_ n] (case type - :blocking (thread - (let [job (! ch (first vs))) @@ -646,14 +686,53 @@ (when close? (close! ch)))))) -(defn to-chan +(defn to-chan! "Creates and returns a channel which contains the contents of coll, - closing when exhausted." + closing when exhausted. + + If accessing coll might block, use to-chan!! instead" [coll] (let [c (bounded-count 100 coll)] (if (pos? c) (let [ch (chan c)] - (onto-chan ch coll) + (onto-chan! ch coll) + ch) + (let [ch (chan)] + (close! ch) + ch)))) + +(defn onto-chan + "Deprecated - use onto-chan! or onto-chan!!" + {:deprecated "1.2"} + ([ch coll] (onto-chan! ch coll true)) + ([ch coll close?] (onto-chan! ch coll close?))) + +(defn to-chan + "Deprecated - use to-chan! or to-chan!!" + {:deprecated "1.2"} + [coll] + (to-chan! coll)) + +(defn onto-chan!! + "Like onto-chan! for use when accessing coll might block, + e.g. a lazy seq of blocking operations" + ([ch coll] (onto-chan!! ch coll true)) + ([ch coll close?] + (thread + (loop [vs (seq coll)] + (if (and vs (>!! ch (first vs))) + (recur (next vs)) + (when close? + (close! ch))))))) + +(defn to-chan!! + "Like to-chan! for use when accessing coll might block, + e.g. a lazy seq of blocking operations" + [coll] + (let [c (bounded-count 100 coll)] + (if (pos? c) + (let [ch (chan c)] + (onto-chan!! ch coll) ch) (let [ch (chan)] (close! ch) @@ -702,7 +781,6 @@ (reset! dctr (count chs)) (doseq [c chs] (when-not (put! c val done) - (done nil) (untap* m c))) ;;wait for all (when (seq chs) @@ -758,7 +836,7 @@ solo-modes #{:mute :pause} attrs (conj solo-modes :solo) solo-mode (atom :mute) - change (chan) + change (chan (sliding-buffer 1)) changed #(put! change true) pick (fn [attr chs] (reduce-kv @@ -999,7 +1077,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; deprecated - do not use ;;;;;;;;;;;;;;;;;;;;;;;;; (defn map< "Deprecated - this function will be removed. Use transducer instead" - {:deprecated "0.1.319.0-6b1aca-alpha"} + {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} [f ch] (reify impl/Channel @@ -1031,7 +1109,7 @@ (defn map> "Deprecated - this function will be removed. Use transducer instead" - {:deprecated "0.1.319.0-6b1aca-alpha"} + {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} [f ch] (reify impl/Channel @@ -1047,7 +1125,7 @@ (defn filter> "Deprecated - this function will be removed. Use transducer instead" - {:deprecated "0.1.319.0-6b1aca-alpha"} + {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} [p ch] (reify impl/Channel @@ -1065,13 +1143,13 @@ (defn remove> "Deprecated - this function will be removed. Use transducer instead" - {:deprecated "0.1.319.0-6b1aca-alpha"} + {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} [p ch] (filter> (complement p) ch)) (defn filter< "Deprecated - this function will be removed. Use transducer instead" - {:deprecated "0.1.319.0-6b1aca-alpha"} + {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} ([p ch] (filter< p ch nil)) ([p ch buf-or-n] (let [out (chan buf-or-n)] @@ -1086,7 +1164,7 @@ (defn remove< "Deprecated - this function will be removed. Use transducer instead" - {:deprecated "0.1.319.0-6b1aca-alpha"} + {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} ([p ch] (remove< p ch nil)) ([p ch buf-or-n] (filter< (complement p) ch buf-or-n))) @@ -1102,7 +1180,7 @@ (defn mapcat< "Deprecated - this function will be removed. Use transducer instead" - {:deprecated "0.1.319.0-6b1aca-alpha"} + {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} ([f in] (mapcat< f in nil)) ([f in buf-or-n] (let [out (chan buf-or-n)] @@ -1111,7 +1189,7 @@ (defn mapcat> "Deprecated - this function will be removed. Use transducer instead" - {:deprecated "0.1.319.0-6b1aca-alpha"} + {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} ([f out] (mapcat> f out nil)) ([f out buf-or-n] (let [in (chan buf-or-n)] @@ -1120,7 +1198,7 @@ (defn unique "Deprecated - this function will be removed. Use transducer instead" - {:deprecated "0.1.319.0-6b1aca-alpha"} + {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} ([ch] (unique ch nil)) ([ch buf-or-n] @@ -1138,7 +1216,7 @@ (defn partition "Deprecated - this function will be removed. Use transducer instead" - {:deprecated "0.1.319.0-6b1aca-alpha"} + {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} ([n ch] (partition n ch nil)) ([n ch buf-or-n] @@ -1163,7 +1241,7 @@ (defn partition-by "Deprecated - this function will be removed. Use transducer instead" - {:deprecated "0.1.319.0-6b1aca-alpha"} + {:deprecated "0.1.319.0-6b1aca-alpha", :skip-wiki true} ([f ch] (partition-by f ch nil)) ([f ch buf-or-n] diff --git a/src/main/java/clojure/core/async/Mutex.java b/src/main/java/clojure/core/async/Mutex.java deleted file mode 100644 index 10d4f8e..0000000 --- a/src/main/java/clojure/core/async/Mutex.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - Copyright (c) Rich Hickey and contributors. All rights reserved. - The use and distribution terms for this software are covered by the - Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) - which can be found in the file epl-v10.html at the root of this distribution. - By using this software in any fashion, you are agreeing to be bound by - the terms of this license. - You must not remove this notice, or any other, from this software. -*/ - -package clojure.core.async; - -import java.util.concurrent.locks.AbstractQueuedSynchronizer; - -// non-recursive, non-reentrant mutex implementation based on example -// from Doug Lea's "The java.util.concurrent Synchronizer Framework" -// http://gee.cs.oswego.edu/dl/papers/aqs.pdf -public class Mutex { - private static class Sync extends AbstractQueuedSynchronizer { - public boolean tryAcquire(int ignored) { - return compareAndSetState(0, 1); - } - - public boolean tryRelease(int ignored) { - setState(0); - return true; - } - } - - private final Sync sync = new Sync(); - - public Mutex() {} - - public void lock() { - sync.acquire(1); - } - - public void unlock() { - sync.release(1); - } -} diff --git a/src/main/java/clojure/core/async/ThreadLocalRandom.java b/src/main/java/clojure/core/async/ThreadLocalRandom.java deleted file mode 100644 index ed772bb..0000000 --- a/src/main/java/clojure/core/async/ThreadLocalRandom.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright (c) Rich Hickey and contributors. All rights reserved. - The use and distribution terms for this software are covered by the - Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) - which can be found in the file epl-v10.html at the root of this distribution. - By using this software in any fashion, you are agreeing to be bound by - the terms of this license. - You must not remove this notice, or any other, from this software. -*/ - -package clojure.core.async; - -import java.util.Random; - -public class ThreadLocalRandom extends Random { - - private static final long serialVersionUID = -2599376724352996934L; - - private static ThreadLocal currentThreadLocalRandom = new ThreadLocal() { - protected ThreadLocalRandom initialValue() { - return new ThreadLocalRandom(); - } - }; - - - /** - * Returns the current ThreadLocalRandom for this thread. Clients must call current, - * rather than constructing instances themselves. The ThreadLocalRandom instance will - * be returned from a ThreadLocal variable. - * - * @return A ThreadLocalRandom for the current thread - * - * @see ThreadLocal - * @see Random - */ - public static ThreadLocalRandom current() { - return currentThreadLocalRandom.get(); - } - - private ThreadLocalRandom() { - super(); - } - - private ThreadLocalRandom(long seed) { - super(seed); - } - -} diff --git a/src/test/cljs/cljs/core/async/buffer_tests.cljs b/src/test/cljs/cljs/core/async/buffer_tests.cljs index f1dd19c..31cfe73 100644 --- a/src/test/cljs/cljs/core/async/buffer_tests.cljs +++ b/src/test/cljs/cljs/core/async/buffer_tests.cljs @@ -1,3 +1,11 @@ +;; Copyright (c) Rich Hickey and contributors. All rights reserved. +;; The use and distribution terms for this software are covered by the +;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +;; which can be found in the file epl-v10.html at the root of this distribution. +;; By using this software in any fashion, you are agreeing to be bound by +;; the terms of this license. +;; You must not remove this notice, or any other, from this software. + (ns cljs.core.async.buffer-tests (:require-macros [cljs.core.async.macros :as m :refer [go]]) (:require [cljs.core.async @@ -30,12 +38,20 @@ (is (full? fb)) #_(assert (throws? (add! fb :3))) + ; already overflown + (add! fb :3) + (is (= 3 (count fb))) + (is (full? fb)) + (is (= :1 (remove! fb))) + (is (= 2 (count fb))) + (is (full? fb)) + + (is (= :2 (remove! fb))) + (is (= 1 (count fb))) (is (not (full? fb))) - (is (= 1 (count fb))) - (is (= :2 (remove! fb))) - + (is (= :3 (remove! fb))) (is (= 0 (count fb))) #_(is (helpers/throws? (remove! fb))))) diff --git a/src/test/cljs/cljs/core/async/interop_tests.cljs b/src/test/cljs/cljs/core/async/interop_tests.cljs new file mode 100644 index 0000000..2403cc1 --- /dev/null +++ b/src/test/cljs/cljs/core/async/interop_tests.cljs @@ -0,0 +1,86 @@ +;; Copyright (c) Rich Hickey and contributors. All rights reserved. +;; The use and distribution terms for this software are covered by the +;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +;; which can be found in the file epl-v10.html at the root of this distribution. +;; By using this software in any fashion, you are agreeing to be bound by +;; the terms of this license. +;; You must not remove this notice, or any other, from this software. + +(ns cljs.core.async.interop-tests + (:require-macros [cljs.core.async.macros :refer [go]]) + (:require [cljs.core.async :refer [c] :refer-macros [c-semantics + (async done + (go + (let [c (p->c (js/Promise.resolve 42))] + (is (= (! chan close! to-chan pipeline-async pipeline put!]] + :refer [! chan close! to-chan! pipeline-async pipeline put!]] [cljs.test :refer-macros [deftest is testing async]])) (defn pipeline-tester [pipeline-fn n inputs xf] - (let [cin (to-chan inputs) + (let [cin (to-chan! inputs) cout (chan 1)] (pipeline-fn n cout xf cin) (go-loop [acc []] @@ -50,16 +58,16 @@ (async done (go (let [cout (chan 1)] - (pipeline 5 cout (map identity) (to-chan [1]) true) + (pipeline 5 cout (map identity) (to-chan! [1]) true) (is (= 1 (! cout :more) (is (= :more (! cout :more) (is (= :more ( @@ -151,7 +159,7 @@ (is (= [2 3 4 5] (let [out (chan) in (async/map> inc out)] - (async/onto-chan in [1 2 3 4]) + (async/onto-chan! in [1 2 3 4]) ( @@ -175,7 +183,7 @@ (is (= [2 4 6] (let [out (chan) in (async/filter> even? out)] - (async/onto-chan in [1 2 3 4 5 6]) + (async/onto-chan! in [1 2 3 4 5 6]) ( even? out)] - (async/onto-chan in [1 2 3 4 5 6]) + (async/onto-chan! in [1 2 3 4 5 6]) ( @@ -202,7 +210,7 @@ (is (= [0 0 1 0 1 2] (let [out (chan) in (async/mapcat> range out)] - (async/onto-chan in [1 2 3]) + (async/onto-chan! in [1 2 3]) (! take-out (!! c x) - (close! c) - c)) + (to-chan! [x])) (deftest async-test (testing "values are returned correctly" @@ -436,29 +434,38 @@ (chan) ([v] :failed) :default 42)))))) - (testing "alt obeys its random-array initialization" - (is (= #{:two} - (with-redefs [clojure.core.async/random-array - (constantly (int-array [1 2 0]))] - (" (is (= [2 3 4 5] (let [out (chan) in (a/map> inc out)] - (a/onto-chan in [1 2 3 4]) + (a/onto-chan! in [1 2 3 4]) (" (is (= [2 4 6] (let [out (chan) in (filter> even? out)] - (a/onto-chan in [1 2 3 4 5 6]) + (a/onto-chan! in [1 2 3 4 5 6]) (" (is (= [1 3 5] (let [out (chan) in (remove> even? out)] - (a/onto-chan in [1 2 3 4 5 6]) + (a/onto-chan! in [1 2 3 4 5 6]) (" (is (= [0 0 1 0 1 2] (let [out (chan) in (mapcat> range out)] - (a/onto-chan in [1 2 3]) + (a/onto-chan! in [1 2 3]) (!! c [1 2 3]))) + (is (= 1 (!! c [1 2 3]))) + (is (= 1 (!! c [4 5 6])] + (swap! counter inc) + r))] + (is (= 0 @counter)) + (is (= 2 (! !! go go-loop thread chan close! to-chan + [clojure.core.async :as a :refer [! !! go go-loop thread chan close! to-chan! pipeline pipeline-blocking pipeline-async]])) ;; in Clojure 1.7, use (map f) instead of this @@ -15,7 +15,7 @@ (f1 result (apply f input inputs)))))) (defn pipeline-tester [pipeline-fn n inputs xf] - (let [cin (to-chan inputs) + (let [cin (to-chan! inputs) cout (chan 1)] (pipeline-fn n cout xf cin) (!! cout :more) (is (= :more (!! cout :more) (is (= :more (!! chex e) :err))] - (pf 5 cout ex-mapping (to-chan [1 2 3 4]) true ex-handler) + (pf 5 cout ex-mapping (to-chan! [1 2 3 4]) true ex-handler) (is (= 1 (