├── .gitignore ├── LICENSE ├── README.md ├── Sempare.Async.Group.groupproj ├── Sempare.Async.Pkg.dpk ├── Sempare.Async.Pkg.dproj ├── Sempare.Async.Pkg.res ├── Sempare.Async.Tester.dpr ├── Sempare.Async.Tester.dproj ├── Sempare.Async.Tester.res ├── Sempare.Async.res ├── docs ├── channel.md ├── promise.md └── waitgroup.md ├── images └── sempare-logo-45px.png └── src ├── Sempare.Async.Channel.Test.pas ├── Sempare.Async.Channel.pas ├── Sempare.Async.Promise.Test.pas ├── Sempare.Async.Promise.pas ├── Sempare.Async.WaitGroup.Test.pas ├── Sempare.Async.WaitGroup.pas └── Sempare.Async.pas /.gitignore: -------------------------------------------------------------------------------- 1 | # Uncomment these types if you want even more clean repository. But be careful. 2 | # It can make harm to an existing project source. Read explanations below. 3 | # 4 | # Resource files are binaries containing manifest, project icon and version info. 5 | # They can not be viewed as text or compared by diff-tools. Consider replacing them with .rc files. 6 | #*.res 7 | # 8 | # Type library file (binary). In old Delphi versions it should be stored. 9 | # Since Delphi 2009 it is produced from .ridl file and can safely be ignored. 10 | #*.tlb 11 | # 12 | # Diagram Portfolio file. Used by the diagram editor up to Delphi 7. 13 | # Uncomment this if you are not using diagrams or use newer Delphi version. 14 | #*.ddp 15 | # 16 | # Visual LiveBindings file. Added in Delphi XE2. 17 | # Uncomment this if you are not using LiveBindings Designer. 18 | #*.vlb 19 | # 20 | # Deployment Manager configuration file for your project. Added in Delphi XE2. 21 | # Uncomment this if it is not mobile development and you do not use remote debug feature. 22 | #*.deployproj 23 | # 24 | # C++ object files produced when C/C++ Output file generation is configured. 25 | # Uncomment this if you are not using external objects (zlib library for example). 26 | #*.obj 27 | # 28 | 29 | # Delphi compiler-generated binaries (safe to delete) 30 | *.exe 31 | *.dll 32 | *.bpl 33 | *.bpi 34 | *.dcp 35 | *.so 36 | *.apk 37 | *.drc 38 | *.map 39 | *.dres 40 | *.rsm 41 | *.tds 42 | *.dcu 43 | *.lib 44 | *.a 45 | *.o 46 | *.ocx 47 | 48 | # Delphi autogenerated files (duplicated info) 49 | *.cfg 50 | *.hpp 51 | *Resource.rc 52 | 53 | # Delphi local files (user-specific info) 54 | *.local 55 | *.identcache 56 | *.projdata 57 | *.tvsconfig 58 | *.dsk 59 | 60 | # Delphi history and backups 61 | __history/ 62 | __recovery/ 63 | *.~* 64 | 65 | # Castalia statistics file (since XE7 Castalia is distributed with Delphi) 66 | *.stat 67 | 68 | # Boss dependency manager vendor folder https://github.com/HashLoad/boss 69 | modules/ 70 | Win32 71 | *.bak 72 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![](https://tokei.rs/b1/github/sempare/sempare-async?category=lines)](https://github.com/sempare/sempare-async) [![](https://tokei.rs/b1/github/sempare/sempare-async?category=code)](https://github.com/sempare/sempare-async) [![](https://tokei.rs/b1/github/sempare/sempare-async?category=files)](https://github.com/sempare/sempare-async) 2 | 3 | # ![](./images/sempare-logo-45px.png) Sempare Async 4 | 5 | Copyright (c) 2020 [Sempare Limited](http://www.sempare.ltd), [Conrad Vermeulen](mailto:conrad.vermeulen@gmail.com) 6 | 7 | Contact: 8 | 9 | License: [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt) 10 | 11 | Open Source: https://github.com/sempare/sempare-async 12 | 13 | # Description 14 | 15 | Some experimental async classes for Delphi: 16 | * [Promise](./docs/promise.md) 17 | * [WaitGroup](./docs/waitgroup.md) 18 | * [Channel](./docs/channel.md) 19 | 20 | # How to reference: 21 | 22 | ``` 23 | uses 24 | Sempare.Async; 25 | ``` 26 | 27 | 28 | -------------------------------------------------------------------------------- /Sempare.Async.Group.groupproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {EAE33432-507E-40B6-81D1-352784564895} 4 | 5 | 6 | 7 | 8 | 9 | 10 | Sempare.Async.Pkg.dproj 11 | 12 | 13 | 14 | Default.Personality.12 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Sempare.Async.Pkg.dpk: -------------------------------------------------------------------------------- 1 | package Sempare.Async.Pkg; 2 | 3 | {$R *.res} 4 | {$IFDEF IMPLICITBUILDING This IFDEF should not be used by users} 5 | {$ALIGN 8} 6 | {$ASSERTIONS ON} 7 | {$BOOLEVAL OFF} 8 | {$DEBUGINFO OFF} 9 | {$EXTENDEDSYNTAX ON} 10 | {$IMPORTEDDATA ON} 11 | {$IOCHECKS ON} 12 | {$LOCALSYMBOLS ON} 13 | {$LONGSTRINGS ON} 14 | {$OPENSTRINGS ON} 15 | {$OPTIMIZATION OFF} 16 | {$OVERFLOWCHECKS OFF} 17 | {$RANGECHECKS OFF} 18 | {$REFERENCEINFO ON} 19 | {$SAFEDIVIDE OFF} 20 | {$STACKFRAMES ON} 21 | {$TYPEDADDRESS OFF} 22 | {$VARSTRINGCHECKS ON} 23 | {$WRITEABLECONST OFF} 24 | {$MINENUMSIZE 1} 25 | {$IMAGEBASE $400000} 26 | {$DEFINE DEBUG} 27 | {$ENDIF IMPLICITBUILDING} 28 | {$IMPLICITBUILD ON} 29 | 30 | requires 31 | rtl; 32 | 33 | contains 34 | Sempare.Async.Channel in 'src\Sempare.Async.Channel.pas', 35 | Sempare.Async in 'src\Sempare.Async.pas', 36 | Sempare.Async.Promise in 'src\Sempare.Async.Promise.pas', 37 | Sempare.Async.WaitGroup in 'src\Sempare.Async.WaitGroup.pas'; 38 | 39 | end. 40 | -------------------------------------------------------------------------------- /Sempare.Async.Pkg.dproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {30DB6FC3-5523-4E59-B65E-8706931839D7} 4 | Sempare.Async.Pkg.dpk 5 | 19.0 6 | None 7 | True 8 | Release 9 | Win32 10 | 1 11 | Package 12 | 13 | 14 | true 15 | 16 | 17 | true 18 | Base 19 | true 20 | 21 | 22 | true 23 | Base 24 | true 25 | 26 | 27 | true 28 | Base 29 | true 30 | 31 | 32 | true 33 | Base 34 | true 35 | 36 | 37 | true 38 | Base 39 | true 40 | 41 | 42 | true 43 | Base 44 | true 45 | 46 | 47 | true 48 | Base 49 | true 50 | 51 | 52 | true 53 | Base 54 | true 55 | 56 | 57 | true 58 | Cfg_1 59 | true 60 | true 61 | 62 | 63 | true 64 | Base 65 | true 66 | 67 | 68 | .\$(Platform)\$(Config) 69 | .\$(Platform)\$(Config) 70 | false 71 | false 72 | false 73 | false 74 | false 75 | true 76 | true 77 | System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace) 78 | All 79 | Sempare_Async_Pkg 80 | 81 | 82 | None 83 | android-support-v4.dex.jar;cloud-messaging.dex.jar;com-google-android-gms.play-services-ads-base.17.2.0.dex.jar;com-google-android-gms.play-services-ads-identifier.16.0.0.dex.jar;com-google-android-gms.play-services-ads-lite.17.2.0.dex.jar;com-google-android-gms.play-services-ads.17.2.0.dex.jar;com-google-android-gms.play-services-analytics-impl.16.0.8.dex.jar;com-google-android-gms.play-services-analytics.16.0.8.dex.jar;com-google-android-gms.play-services-base.16.0.1.dex.jar;com-google-android-gms.play-services-basement.16.2.0.dex.jar;com-google-android-gms.play-services-gass.17.2.0.dex.jar;com-google-android-gms.play-services-identity.16.0.0.dex.jar;com-google-android-gms.play-services-maps.16.1.0.dex.jar;com-google-android-gms.play-services-measurement-base.16.4.0.dex.jar;com-google-android-gms.play-services-measurement-sdk-api.16.4.0.dex.jar;com-google-android-gms.play-services-stats.16.0.1.dex.jar;com-google-android-gms.play-services-tagmanager-v4-impl.16.0.8.dex.jar;com-google-android-gms.play-services-tasks.16.0.1.dex.jar;com-google-android-gms.play-services-wallet.16.0.1.dex.jar;com-google-firebase.firebase-analytics.16.4.0.dex.jar;com-google-firebase.firebase-common.16.1.0.dex.jar;com-google-firebase.firebase-iid-interop.16.0.1.dex.jar;com-google-firebase.firebase-iid.17.1.1.dex.jar;com-google-firebase.firebase-measurement-connector.17.0.1.dex.jar;com-google-firebase.firebase-messaging.17.5.0.dex.jar;fmx.dex.jar;google-play-billing.dex.jar;google-play-licensing.dex.jar 84 | rtl;$(DCC_UsePackage) 85 | 86 | 87 | None 88 | android-support-v4.dex.jar;cloud-messaging.dex.jar;com-google-android-gms.play-services-ads-base.17.2.0.dex.jar;com-google-android-gms.play-services-ads-identifier.16.0.0.dex.jar;com-google-android-gms.play-services-ads-lite.17.2.0.dex.jar;com-google-android-gms.play-services-ads.17.2.0.dex.jar;com-google-android-gms.play-services-analytics-impl.16.0.8.dex.jar;com-google-android-gms.play-services-analytics.16.0.8.dex.jar;com-google-android-gms.play-services-base.16.0.1.dex.jar;com-google-android-gms.play-services-basement.16.2.0.dex.jar;com-google-android-gms.play-services-gass.17.2.0.dex.jar;com-google-android-gms.play-services-identity.16.0.0.dex.jar;com-google-android-gms.play-services-maps.16.1.0.dex.jar;com-google-android-gms.play-services-measurement-base.16.4.0.dex.jar;com-google-android-gms.play-services-measurement-sdk-api.16.4.0.dex.jar;com-google-android-gms.play-services-stats.16.0.1.dex.jar;com-google-android-gms.play-services-tagmanager-v4-impl.16.0.8.dex.jar;com-google-android-gms.play-services-tasks.16.0.1.dex.jar;com-google-android-gms.play-services-wallet.16.0.1.dex.jar;com-google-firebase.firebase-analytics.16.4.0.dex.jar;com-google-firebase.firebase-common.16.1.0.dex.jar;com-google-firebase.firebase-iid-interop.16.0.1.dex.jar;com-google-firebase.firebase-iid.17.1.1.dex.jar;com-google-firebase.firebase-measurement-connector.17.0.1.dex.jar;com-google-firebase.firebase-messaging.17.5.0.dex.jar;fmx.dex.jar;google-play-billing.dex.jar;google-play-licensing.dex.jar 89 | rtl;$(DCC_UsePackage) 90 | 91 | 92 | None 93 | rtl;$(DCC_UsePackage) 94 | 95 | 96 | None 97 | rtl;$(DCC_UsePackage) 98 | 99 | 100 | rtl;$(DCC_UsePackage) 101 | 102 | 103 | Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) 104 | Debug 105 | true 106 | CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= 107 | 1033 108 | rtl;$(DCC_UsePackage) 109 | 110 | 111 | rtl;$(DCC_UsePackage) 112 | 113 | 114 | DEBUG;$(DCC_Define) 115 | true 116 | false 117 | true 118 | true 119 | true 120 | 121 | 122 | false 123 | 124 | 125 | false 126 | RELEASE;$(DCC_Define) 127 | 0 128 | 0 129 | 130 | 131 | 132 | MainSource 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | Cfg_2 141 | Base 142 | 143 | 144 | Base 145 | 146 | 147 | Cfg_1 148 | Base 149 | 150 | 151 | 152 | Delphi.Personality.12 153 | Package 154 | 155 | 156 | 157 | Sempare.Async.Pkg.dpk 158 | 159 | 160 | 161 | False 162 | False 163 | False 164 | False 165 | False 166 | True 167 | False 168 | 169 | 170 | 171 | 172 | true 173 | 174 | 175 | 176 | 177 | true 178 | 179 | 180 | 181 | 182 | true 183 | 184 | 185 | 186 | 187 | Sempare_Async_Pkg.bpl 188 | true 189 | 190 | 191 | 192 | 193 | 1 194 | 195 | 196 | 0 197 | 198 | 199 | 200 | 201 | classes 202 | 1 203 | 204 | 205 | classes 206 | 1 207 | 208 | 209 | 210 | 211 | res\xml 212 | 1 213 | 214 | 215 | res\xml 216 | 1 217 | 218 | 219 | 220 | 221 | library\lib\armeabi-v7a 222 | 1 223 | 224 | 225 | 226 | 227 | library\lib\armeabi 228 | 1 229 | 230 | 231 | library\lib\armeabi 232 | 1 233 | 234 | 235 | 236 | 237 | library\lib\armeabi-v7a 238 | 1 239 | 240 | 241 | 242 | 243 | library\lib\mips 244 | 1 245 | 246 | 247 | library\lib\mips 248 | 1 249 | 250 | 251 | 252 | 253 | library\lib\armeabi-v7a 254 | 1 255 | 256 | 257 | library\lib\arm64-v8a 258 | 1 259 | 260 | 261 | 262 | 263 | library\lib\armeabi-v7a 264 | 1 265 | 266 | 267 | 268 | 269 | res\drawable 270 | 1 271 | 272 | 273 | res\drawable 274 | 1 275 | 276 | 277 | 278 | 279 | res\values 280 | 1 281 | 282 | 283 | res\values 284 | 1 285 | 286 | 287 | 288 | 289 | res\values-v21 290 | 1 291 | 292 | 293 | res\values-v21 294 | 1 295 | 296 | 297 | 298 | 299 | res\values 300 | 1 301 | 302 | 303 | res\values 304 | 1 305 | 306 | 307 | 308 | 309 | res\drawable 310 | 1 311 | 312 | 313 | res\drawable 314 | 1 315 | 316 | 317 | 318 | 319 | res\drawable-xxhdpi 320 | 1 321 | 322 | 323 | res\drawable-xxhdpi 324 | 1 325 | 326 | 327 | 328 | 329 | res\drawable-ldpi 330 | 1 331 | 332 | 333 | res\drawable-ldpi 334 | 1 335 | 336 | 337 | 338 | 339 | res\drawable-mdpi 340 | 1 341 | 342 | 343 | res\drawable-mdpi 344 | 1 345 | 346 | 347 | 348 | 349 | res\drawable-hdpi 350 | 1 351 | 352 | 353 | res\drawable-hdpi 354 | 1 355 | 356 | 357 | 358 | 359 | res\drawable-xhdpi 360 | 1 361 | 362 | 363 | res\drawable-xhdpi 364 | 1 365 | 366 | 367 | 368 | 369 | res\drawable-mdpi 370 | 1 371 | 372 | 373 | res\drawable-mdpi 374 | 1 375 | 376 | 377 | 378 | 379 | res\drawable-hdpi 380 | 1 381 | 382 | 383 | res\drawable-hdpi 384 | 1 385 | 386 | 387 | 388 | 389 | res\drawable-xhdpi 390 | 1 391 | 392 | 393 | res\drawable-xhdpi 394 | 1 395 | 396 | 397 | 398 | 399 | res\drawable-xxhdpi 400 | 1 401 | 402 | 403 | res\drawable-xxhdpi 404 | 1 405 | 406 | 407 | 408 | 409 | res\drawable-xxxhdpi 410 | 1 411 | 412 | 413 | res\drawable-xxxhdpi 414 | 1 415 | 416 | 417 | 418 | 419 | res\drawable-small 420 | 1 421 | 422 | 423 | res\drawable-small 424 | 1 425 | 426 | 427 | 428 | 429 | res\drawable-normal 430 | 1 431 | 432 | 433 | res\drawable-normal 434 | 1 435 | 436 | 437 | 438 | 439 | res\drawable-large 440 | 1 441 | 442 | 443 | res\drawable-large 444 | 1 445 | 446 | 447 | 448 | 449 | res\drawable-xlarge 450 | 1 451 | 452 | 453 | res\drawable-xlarge 454 | 1 455 | 456 | 457 | 458 | 459 | res\values 460 | 1 461 | 462 | 463 | res\values 464 | 1 465 | 466 | 467 | 468 | 469 | 1 470 | 471 | 472 | 1 473 | 474 | 475 | 0 476 | 477 | 478 | 479 | 480 | 1 481 | .framework 482 | 483 | 484 | 1 485 | .framework 486 | 487 | 488 | 0 489 | 490 | 491 | 492 | 493 | 1 494 | .dylib 495 | 496 | 497 | 1 498 | .dylib 499 | 500 | 501 | 0 502 | .dll;.bpl 503 | 504 | 505 | 506 | 507 | 1 508 | .dylib 509 | 510 | 511 | 1 512 | .dylib 513 | 514 | 515 | 1 516 | .dylib 517 | 518 | 519 | 1 520 | .dylib 521 | 522 | 523 | 1 524 | .dylib 525 | 526 | 527 | 0 528 | .bpl 529 | 530 | 531 | 532 | 533 | 0 534 | 535 | 536 | 0 537 | 538 | 539 | 0 540 | 541 | 542 | 0 543 | 544 | 545 | 0 546 | 547 | 548 | 0 549 | 550 | 551 | 0 552 | 553 | 554 | 0 555 | 556 | 557 | 558 | 559 | 1 560 | 561 | 562 | 1 563 | 564 | 565 | 1 566 | 567 | 568 | 569 | 570 | 1 571 | 572 | 573 | 1 574 | 575 | 576 | 1 577 | 578 | 579 | 580 | 581 | 1 582 | 583 | 584 | 1 585 | 586 | 587 | 1 588 | 589 | 590 | 591 | 592 | 1 593 | 594 | 595 | 1 596 | 597 | 598 | 1 599 | 600 | 601 | 602 | 603 | 1 604 | 605 | 606 | 1 607 | 608 | 609 | 1 610 | 611 | 612 | 613 | 614 | 1 615 | 616 | 617 | 1 618 | 619 | 620 | 1 621 | 622 | 623 | 624 | 625 | 1 626 | 627 | 628 | 1 629 | 630 | 631 | 1 632 | 633 | 634 | 635 | 636 | 1 637 | 638 | 639 | 1 640 | 641 | 642 | 1 643 | 644 | 645 | 646 | 647 | 1 648 | 649 | 650 | 1 651 | 652 | 653 | 1 654 | 655 | 656 | 657 | 658 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 659 | 1 660 | 661 | 662 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 663 | 1 664 | 665 | 666 | 667 | 668 | 1 669 | 670 | 671 | 1 672 | 673 | 674 | 1 675 | 676 | 677 | 678 | 679 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 680 | 1 681 | 682 | 683 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 684 | 1 685 | 686 | 687 | 688 | 689 | 1 690 | 691 | 692 | 1 693 | 694 | 695 | 1 696 | 697 | 698 | 699 | 700 | 1 701 | 702 | 703 | 1 704 | 705 | 706 | 1 707 | 708 | 709 | 710 | 711 | 1 712 | 713 | 714 | 1 715 | 716 | 717 | 1 718 | 719 | 720 | 721 | 722 | 1 723 | 724 | 725 | 1 726 | 727 | 728 | 1 729 | 730 | 731 | 732 | 733 | 1 734 | 735 | 736 | 1 737 | 738 | 739 | 1 740 | 741 | 742 | 743 | 744 | 1 745 | 746 | 747 | 1 748 | 749 | 750 | 1 751 | 752 | 753 | 754 | 755 | 1 756 | 757 | 758 | 1 759 | 760 | 761 | 1 762 | 763 | 764 | 765 | 766 | 1 767 | 768 | 769 | 1 770 | 771 | 772 | 1 773 | 774 | 775 | 776 | 777 | 1 778 | 779 | 780 | 1 781 | 782 | 783 | 1 784 | 785 | 786 | 787 | 788 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 789 | 1 790 | 791 | 792 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 793 | 1 794 | 795 | 796 | 797 | 798 | 1 799 | 800 | 801 | 1 802 | 803 | 804 | 1 805 | 806 | 807 | 808 | 809 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 810 | 1 811 | 812 | 813 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 814 | 1 815 | 816 | 817 | 818 | 819 | 1 820 | 821 | 822 | 1 823 | 824 | 825 | 1 826 | 827 | 828 | 829 | 830 | 1 831 | 832 | 833 | 1 834 | 835 | 836 | 1 837 | 838 | 839 | 840 | 841 | 1 842 | 843 | 844 | 1 845 | 846 | 847 | 1 848 | 849 | 850 | 851 | 852 | 1 853 | 854 | 855 | 1 856 | 857 | 858 | 1 859 | 860 | 861 | 862 | 863 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 864 | 1 865 | 866 | 867 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 868 | 1 869 | 870 | 871 | 872 | 873 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 874 | 1 875 | 876 | 877 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 878 | 1 879 | 880 | 881 | 882 | 883 | 1 884 | 885 | 886 | 1 887 | 888 | 889 | 890 | 891 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 892 | 1 893 | 894 | 895 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 896 | 1 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 1 906 | 907 | 908 | 1 909 | 910 | 911 | 1 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | Contents\Resources 920 | 1 921 | 922 | 923 | Contents\Resources 924 | 1 925 | 926 | 927 | 928 | 929 | library\lib\armeabi-v7a 930 | 1 931 | 932 | 933 | library\lib\arm64-v8a 934 | 1 935 | 936 | 937 | 1 938 | 939 | 940 | 1 941 | 942 | 943 | 1 944 | 945 | 946 | 1 947 | 948 | 949 | 1 950 | 951 | 952 | 1 953 | 954 | 955 | 0 956 | 957 | 958 | 959 | 960 | library\lib\armeabi-v7a 961 | 1 962 | 963 | 964 | 965 | 966 | 1 967 | 968 | 969 | 1 970 | 971 | 972 | 973 | 974 | Assets 975 | 1 976 | 977 | 978 | Assets 979 | 1 980 | 981 | 982 | 983 | 984 | Assets 985 | 1 986 | 987 | 988 | Assets 989 | 1 990 | 991 | 992 | 993 | 994 | 995 | 996 | 997 | 998 | 999 | 1000 | 1001 | 1002 | 1003 | 1004 | 12 1005 | 1006 | 1007 | 1008 | 1009 | 1010 | -------------------------------------------------------------------------------- /Sempare.Async.Pkg.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sempare/sempare-delphi-async/8b9ec7a3bd7453e2ecced2ad51d6a09e9ab204cb/Sempare.Async.Pkg.res -------------------------------------------------------------------------------- /Sempare.Async.Tester.dpr: -------------------------------------------------------------------------------- 1 | program Sempare.Async.Tester; 2 | 3 | {$IFNDEF TESTINSIGHT} 4 | {$APPTYPE CONSOLE} 5 | {$ENDIF} 6 | {$STRONGLINKTYPES ON} 7 | uses 8 | System.SysUtils, 9 | {$IFDEF TESTINSIGHT} 10 | TestInsight.DUnitX, 11 | {$ELSE} 12 | DUnitX.Loggers.Console, 13 | DUnitX.Loggers.Xml.NUnit, 14 | {$ENDIF } 15 | DUnitX.TestFramework, 16 | Sempare.Async.Channel.Test in 'src\Sempare.Async.Channel.Test.pas', 17 | Sempare.Async.Promise.Test in 'src\Sempare.Async.Promise.Test.pas', 18 | Sempare.Async.WaitGroup.Test in 'src\Sempare.Async.WaitGroup.Test.pas'; 19 | 20 | {$IFNDEF TESTINSIGHT} 21 | var 22 | runner: ITestRunner; 23 | results: IRunResults; 24 | logger: ITestLogger; 25 | nunitLogger : ITestLogger; 26 | {$ENDIF} 27 | begin 28 | try 29 | //Check command line options, will exit if invalid 30 | TDUnitX.CheckCommandLine; 31 | //Create the test runner 32 | runner := TDUnitX.CreateRunner; 33 | //Tell the runner to use RTTI to find Fixtures 34 | runner.UseRTTI := True; 35 | //tell the runner how we will log things 36 | //Log to the console window 37 | logger := TDUnitXConsoleLogger.Create(true); 38 | runner.AddLogger(logger); 39 | //Generate an NUnit compatible XML File 40 | nunitLogger := TDUnitXXMLNUnitFileLogger.Create(TDUnitX.Options.XMLOutputFile); 41 | runner.AddLogger(nunitLogger); 42 | runner.FailsOnNoAsserts := False; //When true, Assertions must be made during tests; 43 | 44 | //Run tests 45 | results := runner.Execute; 46 | if not results.AllPassed then 47 | System.ExitCode := EXIT_ERRORS; 48 | 49 | {$IFNDEF CI} 50 | //We don't want this happening when running under CI. 51 | if TDUnitX.Options.ExitBehavior = TDUnitXExitBehavior.Pause then 52 | begin 53 | System.Write('Done.. press key to quit.'); 54 | System.Readln; 55 | end; 56 | {$ENDIF} 57 | except 58 | on E: Exception do 59 | System.Writeln(E.ClassName, ': ', E.Message); 60 | end; 61 | end. 62 | -------------------------------------------------------------------------------- /Sempare.Async.Tester.dproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {1EC6F1B2-61F6-434A-B039-E2BEFAC92B69} 4 | 19.0 5 | None 6 | True 7 | Release 8 | Win32 9 | 1 10 | Console 11 | Sempare.Async.Tester.dpr 12 | 13 | 14 | true 15 | 16 | 17 | true 18 | Base 19 | true 20 | 21 | 22 | true 23 | Base 24 | true 25 | 26 | 27 | true 28 | Base 29 | true 30 | 31 | 32 | true 33 | Base 34 | true 35 | 36 | 37 | true 38 | Base 39 | true 40 | 41 | 42 | true 43 | Base 44 | true 45 | 46 | 47 | true 48 | Base 49 | true 50 | 51 | 52 | true 53 | Base 54 | true 55 | 56 | 57 | true 58 | Cfg_1 59 | true 60 | true 61 | 62 | 63 | true 64 | Base 65 | true 66 | 67 | 68 | true 69 | Cfg_2 70 | true 71 | true 72 | 73 | 74 | .\$(Platform)\$(Config) 75 | .\$(Platform)\$(Config) 76 | false 77 | false 78 | false 79 | false 80 | false 81 | System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace) 82 | true 83 | $(BDS)\bin\delphi_PROJECTICON.ico 84 | $(BDS)\bin\delphi_PROJECTICNS.icns 85 | $(DUnitX);$(DCC_UnitSearchPath) 86 | Sempare_Async_Tester 87 | 88 | 89 | DBXSqliteDriver;RESTComponents;DBXInterBaseDriver;emsclientfiredac;tethering;DataSnapFireDAC;bindcompfmx;fmx;FireDACIBDriver;FireDACDBXDriver;dbexpress;IndyCore;dsnap;emsclient;DataSnapCommon;FireDACCommon;RESTBackendComponents;soapserver;bindengine;CloudService;FireDACCommonDriver;DataSnapClient;inet;IndyIPCommon;bindcompdbx;IndyIPServer;IndySystem;fmxFireDAC;FireDAC;FireDACSqliteDriver;soaprtl;DbxCommonDriver;xmlrtl;soapmidas;DataSnapNativeClient;FireDACDSDriver;rtl;DbxClientDriver;CustomIPTransport;bindcomp;IndyIPClient;FrameStandPackage_10_4;dbxcds;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;$(DCC_UsePackage) 90 | android-support-v4.dex.jar;cloud-messaging.dex.jar;com-google-android-gms.play-services-ads-base.17.2.0.dex.jar;com-google-android-gms.play-services-ads-identifier.16.0.0.dex.jar;com-google-android-gms.play-services-ads-lite.17.2.0.dex.jar;com-google-android-gms.play-services-ads.17.2.0.dex.jar;com-google-android-gms.play-services-analytics-impl.16.0.8.dex.jar;com-google-android-gms.play-services-analytics.16.0.8.dex.jar;com-google-android-gms.play-services-base.16.0.1.dex.jar;com-google-android-gms.play-services-basement.16.2.0.dex.jar;com-google-android-gms.play-services-gass.17.2.0.dex.jar;com-google-android-gms.play-services-identity.16.0.0.dex.jar;com-google-android-gms.play-services-maps.16.1.0.dex.jar;com-google-android-gms.play-services-measurement-base.16.4.0.dex.jar;com-google-android-gms.play-services-measurement-sdk-api.16.4.0.dex.jar;com-google-android-gms.play-services-stats.16.0.1.dex.jar;com-google-android-gms.play-services-tagmanager-v4-impl.16.0.8.dex.jar;com-google-android-gms.play-services-tasks.16.0.1.dex.jar;com-google-android-gms.play-services-wallet.16.0.1.dex.jar;com-google-firebase.firebase-analytics.16.4.0.dex.jar;com-google-firebase.firebase-common.16.1.0.dex.jar;com-google-firebase.firebase-iid-interop.16.0.1.dex.jar;com-google-firebase.firebase-iid.17.1.1.dex.jar;com-google-firebase.firebase-measurement-connector.17.0.1.dex.jar;com-google-firebase.firebase-messaging.17.5.0.dex.jar;fmx.dex.jar;google-play-billing.dex.jar;google-play-licensing.dex.jar 91 | 92 | 93 | DBXSqliteDriver;RESTComponents;DBXInterBaseDriver;emsclientfiredac;tethering;DataSnapFireDAC;bindcompfmx;fmx;FireDACIBDriver;FireDACDBXDriver;dbexpress;IndyCore;dsnap;emsclient;DataSnapCommon;FireDACCommon;RESTBackendComponents;soapserver;bindengine;CloudService;FireDACCommonDriver;DataSnapClient;inet;IndyIPCommon;bindcompdbx;IndyIPServer;IndySystem;fmxFireDAC;FireDAC;FireDACSqliteDriver;soaprtl;DbxCommonDriver;xmlrtl;soapmidas;DataSnapNativeClient;FireDACDSDriver;rtl;DbxClientDriver;CustomIPTransport;bindcomp;IndyIPClient;FrameStandPackage_10_4;dbxcds;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;$(DCC_UsePackage) 94 | android-support-v4.dex.jar;cloud-messaging.dex.jar;com-google-android-gms.play-services-ads-base.17.2.0.dex.jar;com-google-android-gms.play-services-ads-identifier.16.0.0.dex.jar;com-google-android-gms.play-services-ads-lite.17.2.0.dex.jar;com-google-android-gms.play-services-ads.17.2.0.dex.jar;com-google-android-gms.play-services-analytics-impl.16.0.8.dex.jar;com-google-android-gms.play-services-analytics.16.0.8.dex.jar;com-google-android-gms.play-services-base.16.0.1.dex.jar;com-google-android-gms.play-services-basement.16.2.0.dex.jar;com-google-android-gms.play-services-gass.17.2.0.dex.jar;com-google-android-gms.play-services-identity.16.0.0.dex.jar;com-google-android-gms.play-services-maps.16.1.0.dex.jar;com-google-android-gms.play-services-measurement-base.16.4.0.dex.jar;com-google-android-gms.play-services-measurement-sdk-api.16.4.0.dex.jar;com-google-android-gms.play-services-stats.16.0.1.dex.jar;com-google-android-gms.play-services-tagmanager-v4-impl.16.0.8.dex.jar;com-google-android-gms.play-services-tasks.16.0.1.dex.jar;com-google-android-gms.play-services-wallet.16.0.1.dex.jar;com-google-firebase.firebase-analytics.16.4.0.dex.jar;com-google-firebase.firebase-common.16.1.0.dex.jar;com-google-firebase.firebase-iid-interop.16.0.1.dex.jar;com-google-firebase.firebase-iid.17.1.1.dex.jar;com-google-firebase.firebase-measurement-connector.17.0.1.dex.jar;com-google-firebase.firebase-messaging.17.5.0.dex.jar;fmx.dex.jar;google-play-billing.dex.jar;google-play-licensing.dex.jar 95 | 96 | 97 | DBXSqliteDriver;RESTComponents;fmxase;DBXInterBaseDriver;emsclientfiredac;tethering;DataSnapFireDAC;bindcompfmx;fmx;FireDACIBDriver;FireDACDBXDriver;dbexpress;IndyCore;dsnap;emsclient;DataSnapCommon;FireDACCommon;RESTBackendComponents;soapserver;bindengine;CloudService;FireDACCommonDriver;DataSnapClient;inet;IndyIPCommon;bindcompdbx;IndyIPServer;IndySystem;fmxFireDAC;FireDAC;FireDACSqliteDriver;soaprtl;DbxCommonDriver;xmlrtl;soapmidas;DataSnapNativeClient;FireDACDSDriver;rtl;DbxClientDriver;CustomIPTransport;bindcomp;IndyIPClient;dbxcds;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;$(DCC_UsePackage) 98 | 99 | 100 | DBXSqliteDriver;RESTComponents;fmxase;DBXInterBaseDriver;emsclientfiredac;tethering;DataSnapFireDAC;bindcompfmx;fmx;FireDACIBDriver;FireDACDBXDriver;dbexpress;IndyCore;dsnap;emsclient;DataSnapCommon;FireDACCommon;RESTBackendComponents;soapserver;bindengine;CloudService;FireDACCommonDriver;DataSnapClient;inet;IndyIPCommon;bindcompdbx;IndyIPServer;IndySystem;fmxFireDAC;FireDAC;FireDACSqliteDriver;soaprtl;DbxCommonDriver;xmlrtl;soapmidas;DataSnapNativeClient;FireDACDSDriver;rtl;DbxClientDriver;CustomIPTransport;bindcomp;IndyIPClient;FrameStandPackage_10_4;dbxcds;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;$(DCC_UsePackage) 101 | 102 | 103 | DBXSqliteDriver;RESTComponents;fmxase;DBXInterBaseDriver;emsclientfiredac;tethering;DataSnapFireDAC;FireDACMSSQLDriver;bindcompfmx;DBXOracleDriver;inetdb;fmx;FireDACIBDriver;fmxdae;FireDACDBXDriver;dbexpress;IndyCore;dsnap;emsclient;DataSnapCommon;FireDACCommon;RESTBackendComponents;soapserver;bindengine;DBXMySQLDriver;CloudService;FireDACOracleDriver;FireDACMySQLDriver;DBXFirebirdDriver;IcsCommonD104Run;FireDACCommonODBC;FireDACCommonDriver;DataSnapClient;inet;IndyIPCommon;bindcompdbx;IndyIPServer;IndySystem;fmxFireDAC;FireDAC;FireDACSqliteDriver;FireDACPgDriver;FireDACASADriver;FireDACTDataDriver;soaprtl;DbxCommonDriver;DataSnapServer;xmlrtl;soapmidas;DataSnapNativeClient;fmxobj;FireDACDSDriver;rtl;DbxClientDriver;DBXSybaseASADriver;CustomIPTransport;bindcomp;DBXInformixDriver;IndyIPClient;FrameStandPackage_10_4;dbxcds;FireDACODBCDriver;DataSnapIndy10ServerTransport;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;inetdbxpress;FireDACMongoDBDriver;OnGuardFMXDR;DataSnapServerMidas;$(DCC_UsePackage) 104 | 105 | 106 | DBXSqliteDriver;RESTComponents;fmxase;DBXDb2Driver;DBXInterBaseDriver;vclactnband;vclFireDAC;bindcompvclsmp;emsclientfiredac;tethering;svnui;DataSnapFireDAC;JvGlobus;FireDACADSDriver;NexusDB450ll270;JvPluginSystem;DBXMSSQLDriver;JvMM;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;PngComponentsD;vcltouch;JvBands;vcldb;bindcompfmx;svn;JvJans;DBXOracleDriver;JvNet;inetdb;JvAppFrm;VirtualTreesDR;RaizeComponentsVcl;JvDotNetCtrls;emsedge;RaizeComponentsVclDb;fmx;FireDACIBDriver;fmxdae;EasyListviewD;BrookTardigrade;vcledge;VirtualShellToolsD;NexusDB450sq270;NexusDB450pv270;NexusDB450sr270;JvWizards;FireDACDBXDriver;dbexpress;IndyCore;NexusDB450se270;vclx;JvPageComps;dsnap;emsclient;DataSnapCommon;FireDACCommon;JvDB;RESTBackendComponents;DataSnapConnectors;VCLRESTComponents;soapserver;JclDeveloperTools;vclie;FMXfrxDB27;bindengine;DBXMySQLDriver;CloudService;FireDACOracleDriver;FireDACMySQLDriver;DBXFirebirdDriver;IcsCommonD104Run;JvCmp;JvHMI;FireDACCommonODBC;FireDACCommonDriver;DataSnapClient;inet;IndyIPCommon;bindcompdbx;FMXfrx27;IcsVclD104Run;vcl;IndyIPServer;DBXSybaseASEDriver;JvCustom;JvXPCtrls;IndySystem;FireDACDb2Driver;dsnapcon;NexusDB450db270;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;IcsFmxD104Run;Jcl;FireDAC;JvCore;emshosting;JvCrypt;FireDACSqliteDriver;FireDACPgDriver;FireDACASADriver;DBXOdbcDriver;FireDACTDataDriver;soaprtl;DbxCommonDriver;JvDlgs;JvRuntimeDesign;JvManagedThreads;NexusDB450lg270;DataSnapServer;xmlrtl;soapmidas;DataSnapNativeClient;fmxobj;vclwinx;FireDACDSDriver;rtl;emsserverresource;DbxClientDriver;JvTimeFramework;DBXSybaseASADriver;CustomIPTransport;vcldsnap;DOSCommandDR;JvSystem;JvStdCtrls;bindcomp;appanalytics;DBXInformixDriver;IndyIPClient;bindcompvcl;FrameStandPackage_10_4;NexusDB450sd270;JvDocking;dbxcds;VclSmp;JvPascalInterpreter;adortl;FireDACODBCDriver;JclVcl;DataSnapIndy10ServerTransport;MPCommonLibD;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;inetdbxpress;FireDACMongoDBDriver;JvControls;JvPrintPreview;OnGuardFMXDR;JclContainers;DataSnapServerMidas;$(DCC_UsePackage) 107 | Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) 108 | Debug 109 | CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= 110 | 1033 111 | 112 | 113 | DBXSqliteDriver;RESTComponents;fmxase;DBXDb2Driver;DBXInterBaseDriver;vclactnband;vclFireDAC;bindcompvclsmp;emsclientfiredac;tethering;DataSnapFireDAC;FireDACADSDriver;NexusDB450ll270;DBXMSSQLDriver;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;PngComponentsD;vcltouch;vcldb;bindcompfmx;DBXOracleDriver;inetdb;VirtualTreesDR;RaizeComponentsVcl;emsedge;RaizeComponentsVclDb;fmx;FireDACIBDriver;fmxdae;EasyListviewD;vcledge;VirtualShellToolsD;NexusDB450sq270;NexusDB450pv270;NexusDB450sr270;FireDACDBXDriver;dbexpress;IndyCore;NexusDB450se270;vclx;dsnap;emsclient;DataSnapCommon;FireDACCommon;RESTBackendComponents;DataSnapConnectors;VCLRESTComponents;soapserver;vclie;bindengine;DBXMySQLDriver;CloudService;FireDACOracleDriver;FireDACMySQLDriver;DBXFirebirdDriver;IcsCommonD104Run;FireDACCommonODBC;FireDACCommonDriver;DataSnapClient;inet;IndyIPCommon;bindcompdbx;IcsVclD104Run;vcl;IndyIPServer;DBXSybaseASEDriver;IndySystem;FireDACDb2Driver;dsnapcon;NexusDB450db270;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;IcsFmxD104Run;FireDAC;emshosting;FireDACSqliteDriver;FireDACPgDriver;FireDACASADriver;DBXOdbcDriver;FireDACTDataDriver;soaprtl;DbxCommonDriver;NexusDB450lg270;DataSnapServer;xmlrtl;soapmidas;DataSnapNativeClient;fmxobj;vclwinx;FireDACDSDriver;rtl;emsserverresource;DbxClientDriver;DBXSybaseASADriver;CustomIPTransport;vcldsnap;DOSCommandDR;bindcomp;appanalytics;DBXInformixDriver;IndyIPClient;bindcompvcl;FrameStandPackage_10_4;NexusDB450sd270;dbxcds;VclSmp;adortl;FireDACODBCDriver;DataSnapIndy10ServerTransport;MPCommonLibD;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;inetdbxpress;FireDACMongoDBDriver;OnGuardFMXDR;DataSnapServerMidas;$(DCC_UsePackage) 114 | 115 | 116 | DEBUG;$(DCC_Define) 117 | true 118 | false 119 | true 120 | true 121 | true 122 | 123 | 124 | false 125 | src;$(DCC_UnitSearchPath) 126 | 1033 127 | (None) 128 | false 129 | 130 | 131 | false 132 | RELEASE;$(DCC_Define) 133 | 0 134 | 0 135 | 136 | 137 | src;$(DCC_UnitSearchPath) 138 | 1033 139 | (None) 140 | 141 | 142 | 143 | MainSource 144 | 145 | 146 | 147 | 148 | 149 | Cfg_2 150 | Base 151 | 152 | 153 | Base 154 | 155 | 156 | Cfg_1 157 | Base 158 | 159 | 160 | 161 | Delphi.Personality.12 162 | Application 163 | 164 | 165 | 166 | Sempare.Async.Tester.dpr 167 | 168 | 169 | File C:\WINDOWS\system32\FMX_MediaLabBasicDsn260.bpl not found 170 | File C:\WINDOWS\system32\FMX_VideoLabBasicDsn260.bpl not found 171 | File C:\WINDOWS\system32\FMX_SignalLabScopeDsn260.bpl not found 172 | File C:\WINDOWS\system32\FMX_PlotLabDsn260.bpl not found 173 | File C:\WINDOWS\system32\FMX_UserLabBasicDsn260.bpl not found 174 | File C:\WINDOWS\system32\FMX_InstrumentLabDigitalDsn260.bpl not found 175 | File C:\WINDOWS\system32\FMX_InstrumentLabDsn260.bpl not found 176 | 177 | 178 | 179 | False 180 | False 181 | False 182 | False 183 | False 184 | True 185 | False 186 | 187 | 188 | 189 | 190 | true 191 | 192 | 193 | 194 | 195 | true 196 | 197 | 198 | 199 | 200 | true 201 | 202 | 203 | 204 | 205 | Sempare_Async_Tester.exe 206 | true 207 | 208 | 209 | 210 | 211 | 1 212 | 213 | 214 | Contents\MacOS 215 | 1 216 | 217 | 218 | 0 219 | 220 | 221 | 222 | 223 | classes 224 | 1 225 | 226 | 227 | classes 228 | 1 229 | 230 | 231 | 232 | 233 | res\xml 234 | 1 235 | 236 | 237 | res\xml 238 | 1 239 | 240 | 241 | 242 | 243 | library\lib\armeabi-v7a 244 | 1 245 | 246 | 247 | 248 | 249 | library\lib\armeabi 250 | 1 251 | 252 | 253 | library\lib\armeabi 254 | 1 255 | 256 | 257 | 258 | 259 | library\lib\armeabi-v7a 260 | 1 261 | 262 | 263 | 264 | 265 | library\lib\mips 266 | 1 267 | 268 | 269 | library\lib\mips 270 | 1 271 | 272 | 273 | 274 | 275 | library\lib\armeabi-v7a 276 | 1 277 | 278 | 279 | library\lib\arm64-v8a 280 | 1 281 | 282 | 283 | 284 | 285 | library\lib\armeabi-v7a 286 | 1 287 | 288 | 289 | 290 | 291 | res\drawable 292 | 1 293 | 294 | 295 | res\drawable 296 | 1 297 | 298 | 299 | 300 | 301 | res\values 302 | 1 303 | 304 | 305 | res\values 306 | 1 307 | 308 | 309 | 310 | 311 | res\values-v21 312 | 1 313 | 314 | 315 | res\values-v21 316 | 1 317 | 318 | 319 | 320 | 321 | res\values 322 | 1 323 | 324 | 325 | res\values 326 | 1 327 | 328 | 329 | 330 | 331 | res\drawable 332 | 1 333 | 334 | 335 | res\drawable 336 | 1 337 | 338 | 339 | 340 | 341 | res\drawable-xxhdpi 342 | 1 343 | 344 | 345 | res\drawable-xxhdpi 346 | 1 347 | 348 | 349 | 350 | 351 | res\drawable-ldpi 352 | 1 353 | 354 | 355 | res\drawable-ldpi 356 | 1 357 | 358 | 359 | 360 | 361 | res\drawable-mdpi 362 | 1 363 | 364 | 365 | res\drawable-mdpi 366 | 1 367 | 368 | 369 | 370 | 371 | res\drawable-hdpi 372 | 1 373 | 374 | 375 | res\drawable-hdpi 376 | 1 377 | 378 | 379 | 380 | 381 | res\drawable-xhdpi 382 | 1 383 | 384 | 385 | res\drawable-xhdpi 386 | 1 387 | 388 | 389 | 390 | 391 | res\drawable-mdpi 392 | 1 393 | 394 | 395 | res\drawable-mdpi 396 | 1 397 | 398 | 399 | 400 | 401 | res\drawable-hdpi 402 | 1 403 | 404 | 405 | res\drawable-hdpi 406 | 1 407 | 408 | 409 | 410 | 411 | res\drawable-xhdpi 412 | 1 413 | 414 | 415 | res\drawable-xhdpi 416 | 1 417 | 418 | 419 | 420 | 421 | res\drawable-xxhdpi 422 | 1 423 | 424 | 425 | res\drawable-xxhdpi 426 | 1 427 | 428 | 429 | 430 | 431 | res\drawable-xxxhdpi 432 | 1 433 | 434 | 435 | res\drawable-xxxhdpi 436 | 1 437 | 438 | 439 | 440 | 441 | res\drawable-small 442 | 1 443 | 444 | 445 | res\drawable-small 446 | 1 447 | 448 | 449 | 450 | 451 | res\drawable-normal 452 | 1 453 | 454 | 455 | res\drawable-normal 456 | 1 457 | 458 | 459 | 460 | 461 | res\drawable-large 462 | 1 463 | 464 | 465 | res\drawable-large 466 | 1 467 | 468 | 469 | 470 | 471 | res\drawable-xlarge 472 | 1 473 | 474 | 475 | res\drawable-xlarge 476 | 1 477 | 478 | 479 | 480 | 481 | res\values 482 | 1 483 | 484 | 485 | res\values 486 | 1 487 | 488 | 489 | 490 | 491 | 1 492 | 493 | 494 | Contents\MacOS 495 | 1 496 | 497 | 498 | 0 499 | 500 | 501 | 502 | 503 | Contents\MacOS 504 | 1 505 | .framework 506 | 507 | 508 | Contents\MacOS 509 | 1 510 | .framework 511 | 512 | 513 | 0 514 | 515 | 516 | 517 | 518 | 1 519 | .dylib 520 | 521 | 522 | 1 523 | .dylib 524 | 525 | 526 | 1 527 | .dylib 528 | 529 | 530 | Contents\MacOS 531 | 1 532 | .dylib 533 | 534 | 535 | Contents\MacOS 536 | 1 537 | .dylib 538 | 539 | 540 | 0 541 | .dll;.bpl 542 | 543 | 544 | 545 | 546 | 1 547 | .dylib 548 | 549 | 550 | 1 551 | .dylib 552 | 553 | 554 | 1 555 | .dylib 556 | 557 | 558 | Contents\MacOS 559 | 1 560 | .dylib 561 | 562 | 563 | Contents\MacOS 564 | 1 565 | .dylib 566 | 567 | 568 | 0 569 | .bpl 570 | 571 | 572 | 573 | 574 | 0 575 | 576 | 577 | 0 578 | 579 | 580 | 0 581 | 582 | 583 | 0 584 | 585 | 586 | 0 587 | 588 | 589 | Contents\Resources\StartUp\ 590 | 0 591 | 592 | 593 | Contents\Resources\StartUp\ 594 | 0 595 | 596 | 597 | 0 598 | 599 | 600 | 601 | 602 | 1 603 | 604 | 605 | 1 606 | 607 | 608 | 1 609 | 610 | 611 | 612 | 613 | 1 614 | 615 | 616 | 1 617 | 618 | 619 | 1 620 | 621 | 622 | 623 | 624 | 1 625 | 626 | 627 | 1 628 | 629 | 630 | 1 631 | 632 | 633 | 634 | 635 | 1 636 | 637 | 638 | 1 639 | 640 | 641 | 1 642 | 643 | 644 | 645 | 646 | 1 647 | 648 | 649 | 1 650 | 651 | 652 | 1 653 | 654 | 655 | 656 | 657 | 1 658 | 659 | 660 | 1 661 | 662 | 663 | 1 664 | 665 | 666 | 667 | 668 | 1 669 | 670 | 671 | 1 672 | 673 | 674 | 1 675 | 676 | 677 | 678 | 679 | 1 680 | 681 | 682 | 1 683 | 684 | 685 | 1 686 | 687 | 688 | 689 | 690 | 1 691 | 692 | 693 | 1 694 | 695 | 696 | 1 697 | 698 | 699 | 700 | 701 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 702 | 1 703 | 704 | 705 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 706 | 1 707 | 708 | 709 | 710 | 711 | 1 712 | 713 | 714 | 1 715 | 716 | 717 | 1 718 | 719 | 720 | 721 | 722 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 723 | 1 724 | 725 | 726 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 727 | 1 728 | 729 | 730 | 731 | 732 | 1 733 | 734 | 735 | 1 736 | 737 | 738 | 1 739 | 740 | 741 | 742 | 743 | 1 744 | 745 | 746 | 1 747 | 748 | 749 | 1 750 | 751 | 752 | 753 | 754 | 1 755 | 756 | 757 | 1 758 | 759 | 760 | 1 761 | 762 | 763 | 764 | 765 | 1 766 | 767 | 768 | 1 769 | 770 | 771 | 1 772 | 773 | 774 | 775 | 776 | 1 777 | 778 | 779 | 1 780 | 781 | 782 | 1 783 | 784 | 785 | 786 | 787 | 1 788 | 789 | 790 | 1 791 | 792 | 793 | 1 794 | 795 | 796 | 797 | 798 | 1 799 | 800 | 801 | 1 802 | 803 | 804 | 1 805 | 806 | 807 | 808 | 809 | 1 810 | 811 | 812 | 1 813 | 814 | 815 | 1 816 | 817 | 818 | 819 | 820 | 1 821 | 822 | 823 | 1 824 | 825 | 826 | 1 827 | 828 | 829 | 830 | 831 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 832 | 1 833 | 834 | 835 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 836 | 1 837 | 838 | 839 | 840 | 841 | 1 842 | 843 | 844 | 1 845 | 846 | 847 | 1 848 | 849 | 850 | 851 | 852 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 853 | 1 854 | 855 | 856 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 857 | 1 858 | 859 | 860 | 861 | 862 | 1 863 | 864 | 865 | 1 866 | 867 | 868 | 1 869 | 870 | 871 | 872 | 873 | 1 874 | 875 | 876 | 1 877 | 878 | 879 | 1 880 | 881 | 882 | 883 | 884 | 1 885 | 886 | 887 | 1 888 | 889 | 890 | 1 891 | 892 | 893 | 894 | 895 | 1 896 | 897 | 898 | 1 899 | 900 | 901 | 1 902 | 903 | 904 | 905 | 906 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 907 | 1 908 | 909 | 910 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 911 | 1 912 | 913 | 914 | 915 | 916 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 917 | 1 918 | 919 | 920 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 921 | 1 922 | 923 | 924 | 925 | 926 | 1 927 | 928 | 929 | 1 930 | 931 | 932 | 933 | 934 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 935 | 1 936 | 937 | 938 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 939 | 1 940 | 941 | 942 | 943 | 944 | 1 945 | 946 | 947 | 1 948 | 949 | 950 | 951 | 952 | ..\ 953 | 1 954 | 955 | 956 | ..\ 957 | 1 958 | 959 | 960 | 961 | 962 | 1 963 | 964 | 965 | 1 966 | 967 | 968 | 1 969 | 970 | 971 | 972 | 973 | ..\$(PROJECTNAME).launchscreen 974 | 64 975 | 976 | 977 | ..\$(PROJECTNAME).launchscreen 978 | 64 979 | 980 | 981 | 982 | 983 | 1 984 | 985 | 986 | 1 987 | 988 | 989 | 1 990 | 991 | 992 | 993 | 994 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 995 | 1 996 | 997 | 998 | 999 | 1000 | ..\ 1001 | 1 1002 | 1003 | 1004 | ..\ 1005 | 1 1006 | 1007 | 1008 | 1009 | 1010 | Contents 1011 | 1 1012 | 1013 | 1014 | Contents 1015 | 1 1016 | 1017 | 1018 | 1019 | 1020 | Contents\Resources 1021 | 1 1022 | 1023 | 1024 | Contents\Resources 1025 | 1 1026 | 1027 | 1028 | 1029 | 1030 | library\lib\armeabi-v7a 1031 | 1 1032 | 1033 | 1034 | library\lib\arm64-v8a 1035 | 1 1036 | 1037 | 1038 | 1 1039 | 1040 | 1041 | 1 1042 | 1043 | 1044 | 1 1045 | 1046 | 1047 | 1 1048 | 1049 | 1050 | Contents\MacOS 1051 | 1 1052 | 1053 | 1054 | Contents\MacOS 1055 | 1 1056 | 1057 | 1058 | 0 1059 | 1060 | 1061 | 1062 | 1063 | library\lib\armeabi-v7a 1064 | 1 1065 | 1066 | 1067 | 1068 | 1069 | 1 1070 | 1071 | 1072 | 1 1073 | 1074 | 1075 | 1076 | 1077 | Assets 1078 | 1 1079 | 1080 | 1081 | Assets 1082 | 1 1083 | 1084 | 1085 | 1086 | 1087 | Assets 1088 | 1 1089 | 1090 | 1091 | Assets 1092 | 1 1093 | 1094 | 1095 | 1096 | 1097 | 1098 | 1099 | 1100 | 1101 | 1102 | 1103 | 1104 | 1105 | 1106 | 1107 | 12 1108 | 1109 | 1110 | 1111 | 1112 | 1113 | -------------------------------------------------------------------------------- /Sempare.Async.Tester.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sempare/sempare-delphi-async/8b9ec7a3bd7453e2ecced2ad51d6a09e9ab204cb/Sempare.Async.Tester.res -------------------------------------------------------------------------------- /Sempare.Async.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sempare/sempare-delphi-async/8b9ec7a3bd7453e2ecced2ad51d6a09e9ab204cb/Sempare.Async.res -------------------------------------------------------------------------------- /docs/channel.md: -------------------------------------------------------------------------------- 1 | # Channel 2 | 3 | Similar to Go channels used for message passing. 4 | 5 | ## Single Message Buffer 6 | 7 | ### Receive 8 | 9 | Send blocks when the buffer is full. 10 | Receive blocks if another no message is available. 11 | 12 | ``` 13 | var ch := Channel.Create(1); 14 | ch.Send(1); 15 | Promise.Apply(procedure 16 | begin 17 | Sleep(1000); // to bypass blocking 18 | ch.Send(1, 1000); // send with 1000ms timeout 19 | end).Start(); 20 | var i := ch.Receive() 21 | ``` 22 | 23 | ### Receive with timeout 24 | 25 | ``` 26 | var i : integer; 27 | var ch := Channel.Create(1); 28 | ch.Send(1); 29 | var received := ch.Receive(i, 1000) // 1000 ms 30 | ``` -------------------------------------------------------------------------------- /docs/promise.md: -------------------------------------------------------------------------------- 1 | # Promise 2 | 3 | Similar to JavaScript Promise 4 | 5 | ## basic 6 | ``` 7 | Promise.Apply(procedure 8 | begin 9 | writeln('hello world'); 10 | end).Start.Wait(); 11 | ``` 12 | 13 | ## return value 14 | ``` 15 | Promise.Apply(functon : string 16 | begin 17 | result := 'hello world' 18 | end) 19 | .Next.Apply(procedure(const AValue : string) 20 | begin 21 | writeln(AValue); 22 | end).Start.Wait(); 23 | ``` 24 | 25 | ## accept and return value 26 | ``` 27 | Promise.Apply(functon : string 28 | begin 29 | result := 'hello' 30 | end) 31 | .Next.Apply(functon(const AValue : string) : string 32 | begin 33 | result := AValue + ' world' 34 | end) 35 | .Next.Apply(procedure(const AValue : string) 36 | begin 37 | writeln(AValue); 38 | end).Start.Wait(); 39 | ``` 40 | 41 | 42 | ## throw exception 43 | Use Catch() to handle exceptions. Multiple Apply blocks can be used before a catch block. 44 | ``` 45 | Promise.Apply(procedure 46 | begin 47 | raise Exception.Create('problem'); 48 | end) 49 | .Next.Catch(procedure(const AException : Exception) 50 | begin 51 | writeln(AException.Message); 52 | end).Start.Wait(); 53 | ``` 54 | 55 | ## working with UI 56 | 57 | Use SyncUI option to safely update UI components by synchronising updates with the main thread. 58 | 59 | ``` 60 | var 61 | p1: IPromise; 62 | j: integer; 63 | begin 64 | p1 := Promise.Apply( 65 | procedure 66 | begin 67 | Label1.Text := 'start'; 68 | end, SyncUI); 69 | for j := 0 to 10 do 70 | p1 := p1.Next.Apply( 71 | procedure 72 | begin 73 | sleep(1000); 74 | Label1.Text := inttostr(FCounter); 75 | inc(FCounter); 76 | end, SyncUI); 77 | p1.start(); 78 | end; 79 | 80 | ``` 81 | -------------------------------------------------------------------------------- /docs/waitgroup.md: -------------------------------------------------------------------------------- 1 | # WaitGroup 2 | 3 | WaitGroup has 3 methods: 4 | - add - increments a count by delta 5 | - done - decrements a count by 1 6 | - wait - waits for count to be 0 7 | 8 | Similar to Go WaitGroup 9 | 10 | ``` 11 | var wg := WaitGroup.Create(2); 12 | wg.Add(2); 13 | var Promise.Apply(procedure 14 | begin 15 | wg.Done(); 16 | end) 17 | .Next.Apply(procedure 18 | begin 19 | wg.Done(); 20 | end) 21 | .Next.Apply(procedure 22 | begin 23 | wg.Done(); 24 | end) 25 | .Next.Apply(procedure 26 | begin 27 | wg.Done(); 28 | end) 29 | .Start; 30 | 31 | wg.Wait(); 32 | ``` -------------------------------------------------------------------------------- /images/sempare-logo-45px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sempare/sempare-delphi-async/8b9ec7a3bd7453e2ecced2ad51d6a09e9ab204cb/images/sempare-logo-45px.png -------------------------------------------------------------------------------- /src/Sempare.Async.Channel.Test.pas: -------------------------------------------------------------------------------- 1 | unit Sempare.Async.Channel.Test; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, 7 | DUnitX.TestFramework; 8 | 9 | type 10 | [TestFixture] 11 | TChannelTests = class 12 | public 13 | [Test] 14 | procedure TestBasic; 15 | 16 | [Test] 17 | procedure TestBasicBlocking; 18 | 19 | [Test] 20 | procedure TestBasicNonBlocking; 21 | 22 | [Test] 23 | procedure TestBuffered; 24 | 25 | end; 26 | 27 | implementation 28 | 29 | uses 30 | Sempare.Async, 31 | Sempare.Async.Promise, 32 | Sempare.Async.Channel; 33 | 34 | { TChannelTests } 35 | 36 | procedure TChannelTests.TestBasic; 37 | var 38 | c: IChannel; 39 | begin 40 | c := Channel.create(); 41 | c.Send(123); 42 | assert.AreEqual(123, c.Receive(123)); 43 | end; 44 | 45 | procedure TChannelTests.TestBasicBlocking; 46 | var 47 | c: IChannel; 48 | p: TPromiseComplete; 49 | begin 50 | c := Channel.create(); 51 | p := Promise.Apply( 52 | procedure 53 | begin 54 | assert.AreEqual(123, c.Receive(123)); 55 | end).Start; 56 | c.Send(123); 57 | c.Send(345); 58 | p.Wait(); 59 | assert.AreEqual(345, c.Receive(345)); 60 | end; 61 | 62 | procedure TChannelTests.TestBasicNonBlocking; 63 | var 64 | c: IChannel; 65 | i: integer; 66 | begin 67 | c := Channel.create(); 68 | assert.IsFalse(c.Receive(i)); 69 | c.Send(123); 70 | assert.istrue(c.Receive(i)); 71 | assert.AreEqual(123, i); 72 | end; 73 | 74 | procedure TChannelTests.TestBuffered; 75 | var 76 | c: IChannel; 77 | begin 78 | c := Channel.create(); 79 | c.Send(123); 80 | assert.AreEqual(123, c.Receive(123)); 81 | end; 82 | 83 | initialization 84 | 85 | TDUnitX.RegisterTestFixture(TChannelTests); 86 | 87 | end. 88 | -------------------------------------------------------------------------------- /src/Sempare.Async.Channel.pas: -------------------------------------------------------------------------------- 1 | unit Sempare.Async.Channel; 2 | 3 | interface 4 | 5 | uses 6 | System.Generics.Collections, 7 | System.SyncObjs, 8 | System.SysUtils, 9 | Sempare.Async; 10 | 11 | type 12 | TChannel = class abstract(TInterfacedObject, IChannel) 13 | protected 14 | FLock: TCriticalSection; 15 | FSendEvent: TEvent; 16 | FReceiveEvent: TEvent; 17 | public 18 | constructor Create; 19 | destructor Destroy; override; 20 | procedure Send(const AMessage: T; const ATimeoutMS: uint32 = INFINITE); virtual; abstract; 21 | function Receive(var AMessage: T): boolean; overload; virtual; abstract; 22 | function Receive(const ATimeoutMS: uint32 = INFINITE): T; overload; virtual; abstract; 23 | function HasMessage: boolean; virtual; abstract; 24 | end; 25 | 26 | ENoMessage = class(Exception); 27 | 28 | TSimpleChannel = class(TChannel) 29 | private 30 | FHasMessage: boolean; 31 | FMessage: T; 32 | public 33 | constructor Create; 34 | destructor Destroy; override; 35 | procedure Send(const AMessage: T; const ATimeoutMS: uint32 = INFINITE); override; 36 | function Receive(var AMessage: T): boolean; overload; override; 37 | function Receive(const ATimeoutMS: uint32 = INFINITE): T; overload; override; 38 | function HasMessage: boolean; override; 39 | end; 40 | 41 | TBufferedChannel = class(TChannel) 42 | private 43 | FMessage: TQueue; 44 | public 45 | constructor Create(const ACapacity: int32 = 100); 46 | destructor Destroy; override; 47 | procedure Send(const AMessage: T; const ATimeoutMS: uint32 = INFINITE); override; 48 | function Receive(var AMessage: T): boolean; overload; override; 49 | function Receive(const ATimeoutMS: uint32 = INFINITE): T; overload; override; 50 | function HasMessage: boolean; override; 51 | end; 52 | 53 | implementation 54 | 55 | uses 56 | System.TypInfo; 57 | { TSimpleChannel } 58 | 59 | constructor TSimpleChannel.Create; 60 | begin 61 | inherited; 62 | FHasMessage := false; 63 | end; 64 | 65 | destructor TSimpleChannel.Destroy; 66 | var 67 | p: tobject; 68 | begin 69 | if HasMessage then 70 | begin 71 | if PTypeInfo(TypeInfo(T)).Kind = tkClass then 72 | begin 73 | move(FMessage, p, sizeof(pointer)); 74 | p.Free; 75 | end; 76 | end; 77 | inherited; 78 | end; 79 | 80 | function TSimpleChannel.HasMessage: boolean; 81 | begin 82 | result := FHasMessage; 83 | end; 84 | 85 | function TSimpleChannel.Receive(const ATimeoutMS: uint32): T; 86 | begin 87 | FLock.Acquire; 88 | try 89 | if not FHasMessage then 90 | begin 91 | FLock.Release; 92 | try 93 | FReceiveEvent.WaitFor(); 94 | finally 95 | FLock.Acquire; 96 | end; 97 | end; 98 | result := FMessage; 99 | FSendEvent.SetEvent; 100 | finally 101 | FLock.Release; 102 | end; 103 | end; 104 | 105 | function TSimpleChannel.Receive(var AMessage: T): boolean; 106 | begin 107 | FLock.Acquire; 108 | try 109 | if not FHasMessage then 110 | exit(false); 111 | AMessage := FMessage; 112 | FSendEvent.SetEvent; 113 | exit(true); 114 | finally 115 | FLock.Release; 116 | end; 117 | end; 118 | 119 | procedure TSimpleChannel.Send(const AMessage: T; const ATimeoutMS: uint32); 120 | begin 121 | FLock.Acquire; 122 | try 123 | if FHasMessage then 124 | begin 125 | FLock.Release; 126 | try 127 | FSendEvent.WaitFor(ATimeoutMS); 128 | finally 129 | FLock.Acquire; 130 | end; 131 | end; 132 | FSendEvent.ResetEvent; 133 | FMessage := AMessage; 134 | FHasMessage := true; 135 | FReceiveEvent.SetEvent; 136 | finally 137 | FLock.Release; 138 | end; 139 | end; 140 | 141 | { TBufferedChannel } 142 | 143 | constructor TBufferedChannel.Create(const ACapacity: int32); 144 | begin 145 | FMessage := TQueue.Create(); 146 | FMessage.Capacity := ACapacity; 147 | inherited Create; 148 | end; 149 | 150 | destructor TBufferedChannel.Destroy; 151 | var 152 | m: T; 153 | p: tobject; 154 | begin 155 | if PTypeInfo(TypeInfo(T)).Kind = tkClass then 156 | begin 157 | for m in FMessage do 158 | begin 159 | move(m, p, sizeof(pointer)); 160 | p.Free; 161 | end; 162 | end; 163 | FMessage.Free; 164 | inherited; 165 | end; 166 | 167 | function TBufferedChannel.HasMessage: boolean; 168 | begin 169 | result := FMessage.Count > 0; 170 | end; 171 | 172 | function TBufferedChannel.Receive(const ATimeoutMS: uint32): T; 173 | begin 174 | FLock.Acquire; 175 | try 176 | if FMessage.Count = 0 then 177 | begin 178 | FLock.Release; 179 | try 180 | FReceiveEvent.WaitFor(ATimeoutMS); 181 | finally 182 | FLock.Acquire; 183 | end; 184 | end; 185 | result := FMessage.Extract; 186 | FSendEvent.SetEvent; 187 | finally 188 | FLock.Release; 189 | end; 190 | end; 191 | 192 | function TBufferedChannel.Receive(var AMessage: T): boolean; 193 | begin 194 | FLock.Acquire; 195 | try 196 | if FMessage.Count = 0 then 197 | exit(false); 198 | AMessage := FMessage.Extract; 199 | FSendEvent.SetEvent; 200 | exit(true); 201 | finally 202 | FLock.Release; 203 | end; 204 | end; 205 | 206 | procedure TBufferedChannel.Send(const AMessage: T; const ATimeoutMS: uint32); 207 | begin 208 | FLock.Acquire; 209 | try 210 | if FMessage.Count = FMessage.Capacity then 211 | begin 212 | FLock.Release; 213 | try 214 | FSendEvent.WaitFor(ATimeoutMS); 215 | finally 216 | FLock.Acquire; 217 | end; 218 | end; 219 | FSendEvent.ResetEvent; 220 | FMessage.Enqueue(AMessage); 221 | FReceiveEvent.SetEvent; 222 | finally 223 | FLock.Release; 224 | end; 225 | end; 226 | 227 | { TChannel } 228 | 229 | constructor TChannel.Create; 230 | begin 231 | FLock := TCriticalSection.Create; 232 | FSendEvent := TEvent.Create; 233 | FReceiveEvent := TEvent.Create; 234 | 235 | end; 236 | 237 | destructor TChannel.Destroy; 238 | begin 239 | FSendEvent.Free; 240 | FReceiveEvent.Free; 241 | FLock.Free; 242 | 243 | inherited; 244 | end; 245 | 246 | end. 247 | -------------------------------------------------------------------------------- /src/Sempare.Async.Promise.Test.pas: -------------------------------------------------------------------------------- 1 | unit Sempare.Async.Promise.Test; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, 7 | DUnitX.TestFramework; 8 | 9 | type 10 | [TestFixture] 11 | TPromiseTests = class 12 | public 13 | [Test, MaxTime(1000)] 14 | procedure TestBasic; 15 | 16 | [Test, MaxTime(1000)] 17 | procedure TestReturnValue; 18 | 19 | [Test, MaxTime(1000)] 20 | procedure TestException; 21 | end; 22 | 23 | implementation 24 | 25 | uses 26 | 27 | Sempare.Async; 28 | 29 | { TMyTestObject } 30 | 31 | procedure TPromiseTests.TestException; 32 | var 33 | i: integer; 34 | ok: boolean; 35 | begin 36 | ok := false; 37 | Promise // 38 | .Apply( 39 | procedure 40 | begin 41 | raise Exception.Create('boo'); 42 | end) // 43 | .Next.Apply( 44 | procedure 45 | begin 46 | inc(i); 47 | end) // 48 | .Next.Apply( 49 | procedure 50 | begin 51 | inc(i); 52 | end).Catch( 53 | procedure(const AException: Exception) 54 | begin 55 | inc(i); 56 | ok := true; 57 | end) // 58 | .Start // 59 | .Wait; 60 | assert.IsTrue(ok); 61 | assert.AreEqual(1, i); 62 | end; 63 | 64 | procedure TPromiseTests.TestReturnValue; 65 | var 66 | i: integer; 67 | p: ipromise; 68 | begin 69 | p := Promise // 70 | .Apply( 71 | function: string 72 | begin 73 | inc(i); 74 | result := 'hello world'; 75 | end) // 76 | .Next.Apply( 77 | procedure(const AValue: string) 78 | begin 79 | inc(i); 80 | end) // 81 | .Next.Apply( 82 | function(const AValue: string): string 83 | begin 84 | inc(i); 85 | result := '## ' + AValue; 86 | end) // 87 | .Next.Apply( 88 | procedure(const AValue: string) 89 | begin 90 | inc(i); 91 | end).Next.Apply( 92 | function(const AValue: string): integer 93 | begin 94 | inc(i); 95 | result := length(AValue) 96 | end).Next.Apply( 97 | procedure() 98 | begin 99 | inc(i); 100 | end).Next.Apply( 101 | procedure(const AValue: integer) 102 | begin 103 | inc(i); 104 | assert.AreEqual(14, AValue); 105 | end); 106 | 107 | p.Start // 108 | .Wait; 109 | 110 | assert.AreEqual(7, i); 111 | end; 112 | 113 | procedure TPromiseTests.TestBasic; 114 | var 115 | i: integer; 116 | begin 117 | Promise.Apply( 118 | procedure 119 | begin 120 | inc(i); 121 | end).Next.Apply( 122 | procedure 123 | begin 124 | inc(i); 125 | end).Start.Wait; 126 | assert.AreEqual(2, i); 127 | end; 128 | 129 | initialization 130 | 131 | TDUnitX.RegisterTestFixture(TPromiseTests); 132 | 133 | end. 134 | -------------------------------------------------------------------------------- /src/Sempare.Async.Promise.pas: -------------------------------------------------------------------------------- 1 | unit Sempare.Async.Promise; 2 | 3 | interface 4 | 5 | uses 6 | System.Classes, 7 | System.Generics.Collections, 8 | System.Rtti, 9 | System.SysUtils, 10 | System.SyncObjs, 11 | System.Threading, 12 | Sempare.Async, 13 | System.TimeSpan; 14 | 15 | type 16 | TPromiseResult = record 17 | FValue: TValue; 18 | strict private 19 | function GetHasValue: boolean; 20 | public 21 | property HasValue: boolean read GetHasValue; 22 | function AsType: T; 23 | end; 24 | 25 | TPromiseItem = class; 26 | 27 | TPromise = class(TInterfacedObject, IPromise) 28 | private 29 | FValue: TValue; 30 | FCurrentOffset: integer; 31 | FCurrentTask: ITask; 32 | FItems: TObjectList; 33 | FWaitFor: TEvent; 34 | function FirstItem: TPromiseItem; 35 | function LastItem: TPromiseItem; 36 | function GetItem(const AOffset: integer): TPromiseItem; 37 | function GetItemWithExceptionHandler(const AOffset: integer): TPromiseItem; 38 | function IsLast(const AOffset: integer): boolean; 39 | procedure Cancel; 40 | public 41 | function Add: TPromiseItem; 42 | constructor Create(); 43 | destructor Destroy; override; 44 | 45 | function Catch(const AMethod: TPromiseExceptionHandler): IPromise; 46 | function Next(): TPromiseThen; 47 | function Start: TPromiseComplete; 48 | procedure Wait(const ATimeout: TTimespan); overload; 49 | procedure Wait(const ATimeout: cardinal); overload; 50 | property Value: TValue read FValue write FValue; 51 | end; 52 | 53 | _TEventHandlerBase_ = class; 54 | 55 | TPromiseItem = class 56 | private 57 | FOffset: integer; 58 | FPromise: TPromise; 59 | FExceptionHandler: TPromiseExceptionHandler; 60 | FHandler: _TEventHandlerBase_; 61 | 62 | procedure Start(); 63 | procedure Init(const EventHandler: _TEventHandlerBase_); overload; 64 | 65 | public 66 | constructor Create(const APromise: TPromise); 67 | destructor Destroy; override; 68 | 69 | // ideally init would not be required as generics are not allowed on constructors. 70 | procedure Init(const AMethod: TPromiseMethod; const AOption: TPromiseOption; const APrev: IPromise = nil); overload; 71 | procedure Init(const AMethod: TPromiseMethodProc; const AOption: TPromiseOption; const APrev: IPromise = nil); overload; 72 | procedure Init(const AMethod: TPromiseMethodArg; const AOption: TPromiseOption; const APrev: IPromise = nil); overload; 73 | procedure Init(const AMethod: TPromiseMethodProcArg; const AOption: TPromiseOption; const APrev: IPromise = nil); overload; 74 | 75 | procedure Catch(const AMethod: TPromiseExceptionHandler); 76 | function Next(): TPromiseThen; 77 | end; 78 | 79 | _TEventHandlerBase_ = class abstract 80 | public 81 | procedure HandleEvent(sender: TObject); virtual; abstract; 82 | end; 83 | 84 | _TEventHandlerBase_ = class abstract(_TEventHandlerBase_) 85 | private 86 | procedure ActuallyHandleEvent(sender: TObject); 87 | protected 88 | FPromise: TPromiseItem; 89 | FMethod: TMethod; 90 | FOption: TPromiseOption; 91 | protected 92 | procedure DoHandleEvent(sender: TPromiseItem); virtual; abstract; 93 | public 94 | constructor Create(const APromise: TPromiseItem; const AMethod: TMethod; const AOption: TPromiseOption); 95 | procedure HandleEvent(sender: TObject); override; 96 | end; 97 | 98 | _TEventHandler_ = class(_TEventHandlerBase_ < TPromiseMethod < T >> ) 99 | protected 100 | procedure DoHandleEvent(sender: TPromiseItem); override; 101 | end; 102 | 103 | _TEventHandler_ = class(_TEventHandlerBase_ < TPromiseMethodArg < TIn, T >> ) 104 | protected 105 | procedure DoHandleEvent(sender: TPromiseItem); override; 106 | end; 107 | 108 | _TEventHandler_ = class(_TEventHandlerBase_) 109 | protected 110 | procedure DoHandleEvent(sender: TPromiseItem); override; 111 | end; 112 | 113 | _TEventHandlerArg_ = class(_TEventHandlerBase_ < TPromiseMethodProcArg < TIn >> ) 114 | protected 115 | procedure DoHandleEvent(sender: TPromiseItem); override; 116 | end; 117 | 118 | implementation 119 | 120 | { TPromiseResult } 121 | 122 | function TPromiseResult.AsType: T; 123 | begin 124 | result := FValue.AsType; 125 | end; 126 | 127 | function TPromiseResult.GetHasValue: boolean; 128 | begin 129 | result := not FValue.IsEmpty; 130 | end; 131 | 132 | { TPromise } 133 | 134 | procedure TPromiseItem.Catch(const AMethod: TPromiseExceptionHandler); 135 | begin 136 | FExceptionHandler := AMethod; 137 | end; 138 | 139 | constructor TPromiseItem.Create(const APromise: TPromise); 140 | begin 141 | FPromise := APromise; 142 | end; 143 | 144 | destructor TPromiseItem.Destroy; 145 | begin 146 | FPromise := nil; 147 | if FHandler <> nil then 148 | begin 149 | FHandler.free; 150 | FHandler := nil; 151 | end; 152 | inherited; 153 | end; 154 | 155 | procedure TPromiseItem.Init(const AMethod: TPromiseMethod; const AOption: TPromiseOption; const APrev: IPromise); 156 | begin 157 | Init(_TEventHandler_.Create(self, AMethod, AOption)); 158 | end; 159 | 160 | procedure TPromiseItem.Init(const EventHandler: _TEventHandlerBase_); 161 | begin 162 | FOffset := FPromise.FCurrentOffset; 163 | inc(FPromise.FCurrentOffset); 164 | FHandler := EventHandler; 165 | end; 166 | 167 | procedure TPromiseItem.Init(const AMethod: TPromiseMethodArg; const AOption: TPromiseOption; const APrev: IPromise); 168 | begin 169 | Init(_TEventHandler_.Create(self, AMethod, AOption)); 170 | end; 171 | 172 | procedure TPromiseItem.Init(const AMethod: TPromiseMethodProcArg; const AOption: TPromiseOption; const APrev: IPromise); 173 | begin 174 | Init(_TEventHandlerArg_.Create(self, AMethod, AOption)); 175 | end; 176 | 177 | procedure TPromiseItem.Start(); 178 | begin 179 | FPromise.FCurrentTask := TTask.Create(self, FHandler.HandleEvent); 180 | FPromise.FCurrentTask.Start; 181 | end; 182 | 183 | procedure TPromiseItem.Init(const AMethod: TPromiseMethodProc; const AOption: TPromiseOption; const APrev: IPromise); 184 | begin 185 | Init(_TEventHandler_.Create(self, AMethod, AOption)); 186 | end; 187 | 188 | function TPromiseItem.Next(): TPromiseThen; 189 | begin 190 | result := TPromiseThen.Create(self.FPromise); 191 | end; 192 | 193 | { TEventHandler } 194 | 195 | procedure _TEventHandler_.DoHandleEvent(sender: TPromiseItem); 196 | begin 197 | sender.FPromise.FValue := TValue.From(FMethod); 198 | end; 199 | 200 | { TPromise } 201 | 202 | function TPromise.Add: TPromiseItem; 203 | begin 204 | result := TPromiseItem.Create(self); 205 | FItems.Add(result); 206 | end; 207 | 208 | procedure TPromise.Cancel; 209 | var 210 | status: ttaskstatus; 211 | begin 212 | status := ttaskstatus.Created; 213 | if (FCurrentTask <> nil) then 214 | begin 215 | status := FCurrentTask.status; 216 | if not(status in [ttaskstatus.Completed, ttaskstatus.Canceled]) then 217 | FCurrentTask.Cancel; 218 | end; 219 | FWaitFor.SetEvent; 220 | if status = ttaskstatus.Created then 221 | raise EOperationCancelled.Create('terminating promise chain'); 222 | end; 223 | 224 | function TPromise.Catch(const AMethod: TPromiseExceptionHandler): IPromise; 225 | var 226 | item: TPromiseItem; 227 | begin 228 | item := LastItem; 229 | if item <> nil then 230 | item.Catch(AMethod); 231 | result := self; 232 | end; 233 | 234 | constructor TPromise.Create; 235 | begin 236 | FItems := TObjectList.Create(); 237 | FWaitFor := TEvent.Create; 238 | end; 239 | 240 | destructor TPromise.Destroy; 241 | begin 242 | FItems.free; 243 | FWaitFor.free; 244 | inherited; 245 | end; 246 | 247 | function TPromise.FirstItem: TPromiseItem; 248 | begin 249 | result := GetItem(0); 250 | end; 251 | 252 | function TPromise.GetItem(const AOffset: integer): TPromiseItem; 253 | begin 254 | if AOffset + 1 > FItems.Count then 255 | exit(nil); 256 | result := FItems[AOffset]; 257 | end; 258 | 259 | function TPromise.GetItemWithExceptionHandler(const AOffset: integer): TPromiseItem; 260 | var 261 | i: integer; 262 | begin 263 | for i := AOffset + 1 to FItems.Count - 1 do 264 | begin 265 | result := FItems[i]; 266 | if assigned(result.FExceptionHandler) then 267 | exit; 268 | end; 269 | result := nil; 270 | end; 271 | 272 | function TPromise.IsLast(const AOffset: integer): boolean; 273 | begin 274 | result := FItems.Count - 1 = AOffset; 275 | end; 276 | 277 | function TPromise.LastItem: TPromiseItem; 278 | begin 279 | if FItems.Count = 0 then 280 | exit(nil); 281 | result := FItems[FItems.Count - 1]; 282 | end; 283 | 284 | function TPromise.Next: TPromiseThen; 285 | begin 286 | result := TPromiseThen.Create(self); 287 | end; 288 | 289 | function TPromise.Start: TPromiseComplete; 290 | begin 291 | self.FirstItem.Start; 292 | result := TPromiseComplete.Create(self); 293 | end; 294 | 295 | procedure TPromise.Wait(const ATimeout: TTimespan); 296 | begin 297 | FWaitFor.WaitFor(ATimeout); 298 | end; 299 | 300 | procedure TPromise.Wait(const ATimeout: cardinal); 301 | begin 302 | FWaitFor.WaitFor(ATimeout); 303 | end; 304 | 305 | { _TEventHandler_ } 306 | 307 | procedure _TEventHandler_.DoHandleEvent(sender: TPromiseItem); 308 | begin 309 | sender.FPromise.FValue := TValue.From(FMethod(sender.FPromise.FValue.AsType())); 310 | end; 311 | 312 | { _TEventHandler_ } 313 | 314 | procedure _TEventHandler_.DoHandleEvent(sender: TPromiseItem); 315 | begin 316 | FMethod(); 317 | end; 318 | 319 | { _TEventHandlerArg_ } 320 | 321 | procedure _TEventHandlerArg_.DoHandleEvent(sender: TPromiseItem); 322 | begin 323 | FMethod(sender.FPromise.FValue.AsType()); 324 | end; 325 | 326 | { _TEventHandlerBase_ } 327 | 328 | procedure _TEventHandlerBase_.ActuallyHandleEvent(sender: TObject); 329 | var 330 | current, Next: TPromiseItem; 331 | begin 332 | current := TPromiseItem(sender); 333 | try 334 | DoHandleEvent(current); 335 | Next := current.FPromise.GetItem(current.FOffset + 1); 336 | if Next <> nil then 337 | Next.Start 338 | else 339 | current.FPromise.FWaitFor.SetEvent; 340 | except 341 | on e: Exception do 342 | begin 343 | Next := current.FPromise.GetItemWithExceptionHandler(current.FOffset); 344 | if Next = nil then 345 | raise EOperationCancelled.Create(e.Message); 346 | current.FPromise.Cancel; 347 | Next.FExceptionHandler(e); 348 | end; 349 | end; 350 | end; 351 | 352 | constructor _TEventHandlerBase_.Create(const APromise: TPromiseItem; const AMethod: TMethod; const AOption: TPromiseOption); 353 | begin 354 | FPromise := APromise; 355 | FMethod := AMethod; 356 | FOption := AOption; 357 | end; 358 | 359 | procedure _TEventHandlerBase_.HandleEvent(sender: TObject); 360 | 361 | begin 362 | if FOption = SyncUI then 363 | TThread.Synchronize(nil, 364 | procedure 365 | begin 366 | ActuallyHandleEvent(sender); 367 | end) 368 | else 369 | ActuallyHandleEvent(sender); 370 | end; 371 | 372 | end. 373 | -------------------------------------------------------------------------------- /src/Sempare.Async.WaitGroup.Test.pas: -------------------------------------------------------------------------------- 1 | unit Sempare.Async.WaitGroup.Test; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, 7 | DUnitX.TestFramework; 8 | 9 | type 10 | [TestFixture] 11 | TWaitGroupTests = class 12 | public 13 | [Test] 14 | procedure TestWaitGroup; 15 | end; 16 | 17 | implementation 18 | 19 | uses 20 | Sempare.Async.WaitGroup, 21 | Sempare.Async; 22 | 23 | { TWaitGroupTests } 24 | 25 | procedure TWaitGroupTests.TestWaitGroup; 26 | var 27 | wg: IWaitGroup; 28 | i: integer; 29 | p1, p2: ipromise; 30 | begin 31 | wg := WaitGroup.Create; 32 | wg.Add(2); 33 | p1 := promise.Apply( 34 | procedure 35 | begin 36 | Sleep(15); 37 | inc(i); 38 | wg.Done; 39 | end); 40 | p2 := promise.Apply( 41 | procedure 42 | begin 43 | inc(i); 44 | Sleep(15); 45 | wg.Done; 46 | end); 47 | p1.Start; 48 | p2.Start; 49 | wg.Wait(); 50 | Assert.AreEqual(2, i); 51 | end; 52 | 53 | initialization 54 | 55 | TDUnitX.RegisterTestFixture(TWaitGroupTests); 56 | 57 | end. 58 | -------------------------------------------------------------------------------- /src/Sempare.Async.WaitGroup.pas: -------------------------------------------------------------------------------- 1 | unit Sempare.Async.WaitGroup; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, 7 | System.SyncObjs, 8 | Sempare.Async; 9 | 10 | type 11 | TWaitGroupError = class(Exception); 12 | 13 | TWaitGroup = class(TInterfacedObject, IWaitGroup) 14 | private 15 | FEvent: TCountdownEvent; 16 | // we subtract 1 on the first add as the CountdownEvent starts with 1 (so it doesn't signal on initialisation) 17 | FSub1: boolean; 18 | public 19 | constructor Create; 20 | destructor Destroy; override; 21 | procedure Add(const ADelta: integer); 22 | procedure Done(); 23 | procedure Wait(Timeout: cardinal = INFINITE); 24 | end; 25 | 26 | implementation 27 | 28 | { TWaitGroup } 29 | 30 | procedure TWaitGroup.Add(const ADelta: integer); 31 | var 32 | delta: integer; 33 | begin 34 | delta := ADelta; 35 | if not FSub1 then 36 | begin 37 | FSub1 := true; 38 | dec(delta); 39 | end; 40 | FEvent.AddCount(delta); 41 | end; 42 | 43 | constructor TWaitGroup.Create; 44 | begin 45 | FEvent := TCountdownEvent.Create(); 46 | FSub1 := false; 47 | end; 48 | 49 | destructor TWaitGroup.Destroy; 50 | begin 51 | FEvent.Free; 52 | inherited; 53 | end; 54 | 55 | procedure TWaitGroup.Done; 56 | begin 57 | FEvent.Signal(); 58 | end; 59 | 60 | procedure TWaitGroup.Wait(Timeout: cardinal); 61 | begin 62 | FEvent.WaitFor(Timeout); 63 | end; 64 | 65 | end. 66 | -------------------------------------------------------------------------------- /src/Sempare.Async.pas: -------------------------------------------------------------------------------- 1 | unit Sempare.Async; 2 | 3 | interface 4 | 5 | uses 6 | System.SysUtils, 7 | System.TimeSpan, 8 | System.Rtti; 9 | 10 | type 11 | // import ttimespan so users don't have to manually import it 12 | TTimespan = System.TimeSpan.TTimespan; 13 | 14 | IChannel = interface 15 | ['{B256D710-A1C7-48B5-AFF6-BBD7FBB3B8CA}'] 16 | 17 | procedure Send(const AMessage: T; const ATimeoutMS: uint32 = INFINITE); 18 | function Receive(var AMessage: T): boolean; overload; 19 | function Receive(const ATimeoutMS: uint32 = INFINITE): T; overload; 20 | function HasMessage: boolean; 21 | end; 22 | 23 | Channel = class 24 | public 25 | class function Create(const ABufferSize: int32 = 1): IChannel; static; 26 | end; 27 | 28 | IWaitGroup = interface 29 | ['{C4EAD2FA-6392-4064-B004-9749590E88FF}'] 30 | procedure Add(const ADelta: integer); 31 | procedure Done(); 32 | procedure Wait(Timeout: cardinal = INFINITE); 33 | end; 34 | 35 | TPromiseMethod = reference to function: T; 36 | TPromiseMethodProc = reference to procedure; 37 | TPromiseMethodArg = reference to function(const AArg: TIn): T; 38 | TPromiseMethodProcArg = reference to procedure(const AArg: TIn); 39 | TPromiseExceptionHandler = reference to procedure(const AException: Exception); 40 | 41 | IPromise = interface; 42 | 43 | TPromiseOption = (poNormal, poSyncUI, SyncUI = poSyncUI); 44 | 45 | TPromiseThen = record 46 | strict private 47 | FPromise: IPromise; 48 | public 49 | constructor Create(const APromise: IPromise); 50 | function Apply(const AMethod: TPromiseMethod; const AOption: TPromiseOption = poNormal): IPromise; overload; 51 | function Apply(const AMethod: TPromiseMethodProc; const AOption: TPromiseOption = poNormal): IPromise; overload; 52 | function Apply(const AMethod: TPromiseMethodArg; const AOption: TPromiseOption = poNormal): IPromise; overload; 53 | function Apply(const AMethod: TPromiseMethodProcArg; const AOption: TPromiseOption = poNormal): IPromise; overload; 54 | end; 55 | 56 | TPromiseComplete = record 57 | strict private 58 | FPromise: IPromise; 59 | 60 | public 61 | constructor Create(const APromise: IPromise); 62 | procedure Wait(const ADurationMS: cardinal = INFINITE); overload; 63 | procedure Wait(const ATimespan: TTimespan); overload; 64 | end; 65 | 66 | IPromise = interface 67 | ['{3ACE02F6-CCDB-4249-92A4-6A69E9F2E2ED}'] 68 | 69 | function Start(): TPromiseComplete; 70 | function Catch(const AMethod: TPromiseExceptionHandler): IPromise; 71 | function Next(): TPromiseThen; 72 | 73 | procedure Wait(const ATimeout: TTimespan); overload; 74 | procedure Wait(const ATimeout: cardinal); overload; 75 | 76 | end; 77 | 78 | Promise = record 79 | public 80 | class function Apply(const AMethod: TPromiseMethod; const AOption: TPromiseOption = poNormal): IPromise; overload; static; 81 | class function Apply(const AMethod: TPromiseMethodProc; const AOption: TPromiseOption = poNormal): IPromise; overload; static; 82 | class function Apply(const AMethod: TPromiseMethodArg; const AOption: TPromiseOption = poNormal): IPromise; overload; static; 83 | class function Apply(const AMethod: TPromiseMethodProcArg; const AOption: TPromiseOption = poNormal): IPromise; overload; static; 84 | end; 85 | 86 | WaitGroup = record 87 | public 88 | class function Create(const ACount: integer = 0): IWaitGroup; static; 89 | end; 90 | 91 | implementation 92 | 93 | uses 94 | Sempare.Async.Channel, 95 | Sempare.Async.Promise, 96 | Sempare.Async.WaitGroup; 97 | 98 | class function WaitGroup.Create(const ACount: integer): IWaitGroup; 99 | begin 100 | result := TWaitGroup.Create; 101 | if ACount > 0 then 102 | result.Add(ACount); 103 | end; 104 | 105 | { Channel } 106 | 107 | class function Channel.Create(const ABufferSize: int32): IChannel; 108 | begin 109 | if ABufferSize = 1 then 110 | result := TSimpleChannel.Create 111 | else 112 | result := TBufferedChannel.Create(ABufferSize); 113 | end; 114 | 115 | { Promise } 116 | 117 | class function Promise.Apply(const AMethod: TPromiseMethodProc; const AOption: TPromiseOption): IPromise; 118 | var 119 | p: TPromise; 120 | i: TPromiseItem; 121 | begin 122 | p := TPromise.Create; 123 | i := p.Add; 124 | i.Init(AMethod, AOption); 125 | result := p; 126 | end; 127 | 128 | class function Promise.Apply(const AMethod: TPromiseMethod; const AOption: TPromiseOption): IPromise; 129 | var 130 | p: TPromise; 131 | i: TPromiseItem; 132 | begin 133 | p := TPromise.Create; 134 | i := p.Add; 135 | i.Init(AMethod, AOption); 136 | result := p; 137 | end; 138 | 139 | class function Promise.Apply(const AMethod: TPromiseMethodProcArg; const AOption: TPromiseOption): IPromise; 140 | var 141 | p: TPromise; 142 | i: TPromiseItem; 143 | begin 144 | p := TPromise.Create; 145 | i := p.Add; 146 | i.Init(AMethod, AOption); 147 | result := p; 148 | end; 149 | 150 | class function Promise.Apply(const AMethod: TPromiseMethodArg; const AOption: TPromiseOption): IPromise; 151 | var 152 | p: TPromise; 153 | i: TPromiseItem; 154 | begin 155 | p := TPromise.Create; 156 | i := p.Add; 157 | i.Init(AMethod, AOption); 158 | result := p; 159 | end; 160 | 161 | { TPromiseComplete } 162 | 163 | constructor TPromiseComplete.Create(const APromise: IPromise); 164 | begin 165 | FPromise := APromise; 166 | end; 167 | 168 | procedure TPromiseComplete.Wait(const ATimespan: TTimespan); 169 | begin 170 | TPromise(FPromise).Wait(ATimespan); 171 | end; 172 | 173 | procedure TPromiseComplete.Wait(const ADurationMS: cardinal); 174 | begin 175 | TPromise(FPromise).Wait(ADurationMS); 176 | end; 177 | 178 | { TPromiseThen } 179 | 180 | constructor TPromiseThen.Create(const APromise: IPromise); 181 | begin 182 | FPromise := APromise; 183 | end; 184 | 185 | function TPromiseThen.Apply(const AMethod: TPromiseMethodProc; const AOption: TPromiseOption): IPromise; 186 | var 187 | Promise: TPromiseItem; 188 | begin 189 | Promise := TPromise(FPromise).Add; 190 | Promise.Init(AMethod, AOption); 191 | result := FPromise; 192 | end; 193 | 194 | function TPromiseThen.Apply(const AMethod: TPromiseMethodProcArg; const AOption: TPromiseOption): IPromise; 195 | var 196 | Promise: TPromiseItem; 197 | begin 198 | Promise := TPromise(FPromise).Add; 199 | Promise.Init(AMethod, AOption, FPromise); 200 | result := FPromise; 201 | end; 202 | 203 | function TPromiseThen.Apply(const AMethod: TPromiseMethod; const AOption: TPromiseOption): IPromise; 204 | var 205 | Promise: TPromiseItem; 206 | begin 207 | Promise := TPromise(FPromise).Add; 208 | Promise.Init(AMethod, AOption, FPromise); 209 | result := FPromise; 210 | end; 211 | 212 | function TPromiseThen.Apply(const AMethod: TPromiseMethodArg; const AOption: TPromiseOption): IPromise; 213 | var 214 | Promise: TPromiseItem; 215 | begin 216 | Promise := TPromise(FPromise).Add; 217 | Promise.Init(AMethod, AOption, FPromise); 218 | result := FPromise; 219 | end; 220 | 221 | end. 222 | --------------------------------------------------------------------------------