├── .gitignore
├── .swiftpm
└── xcode
│ └── package.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ └── IDEWorkspaceChecks.plist
├── .travis.yml
├── Future.swift.podspec
├── Future.xcodeproj
├── FutureTests_Info.plist
├── Future_Info.plist
├── project.pbxproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ └── WorkspaceSettings.xcsettings
└── xcshareddata
│ └── xcschemes
│ └── Future-Package.xcscheme
├── LICENSE
├── Package.resolved
├── Package.swift
├── README.md
├── Sources
└── Future
│ ├── Async.swift
│ ├── Features
│ ├── always.swift
│ ├── and.swift
│ ├── any.swift
│ ├── asAny.swift
│ ├── asVoid.swift
│ ├── catch.swift
│ ├── delay.swift
│ ├── done.swift
│ ├── finally.swift
│ ├── flat.swift
│ ├── flatMap.swift
│ ├── hush.swift
│ ├── map.swift
│ ├── mute.swift
│ ├── pipe.swift
│ ├── race.swift
│ ├── recover.swift
│ ├── reduce.swift
│ ├── retry.swift
│ ├── return.swift
│ ├── some.swift
│ ├── tap.swift
│ ├── then.swift
│ ├── timeout.swift
│ ├── validate.swift
│ ├── wait.swift
│ ├── whenAll.T.gyb
│ ├── whenAll.T.swift
│ ├── whenAll.swift
│ ├── whenAllVoid.T.gyb
│ ├── whenAllVoid.T.swift
│ ├── whenAllVoid.swift
│ ├── whenAny.T.gyb
│ ├── whenAny.T.swift
│ ├── whenAny.swift
│ └── yield.swift
│ ├── Future.swift
│ ├── Helpers
│ ├── Atom.swift
│ ├── Extensions.swift
│ └── Lock.swift
│ ├── Promise.swift
│ ├── Publisher.swift
│ ├── Scheduler.swift
│ └── Thenable.swift
├── Tests
├── FutureTests
│ ├── AsyncTests.swift
│ ├── FeaturesTests.swift
│ ├── FutureTests.swift
│ ├── Helpers.swift
│ └── XCTestManifests.swift
└── LinuxMain.swift
├── benchmark
├── Package.resolved
├── Package.swift
├── README.md
├── Sources
│ └── benchmark
│ │ ├── main.swift
│ │ └── src
│ │ ├── BrightFutures.swift
│ │ ├── Dispatch.swift
│ │ ├── Future.swift
│ │ ├── Helpers.swift
│ │ ├── Hydra.swift
│ │ ├── PromiseKit.swift
│ │ ├── Promises.swift
│ │ ├── Reactive.swift
│ │ └── RxSwift.swift
├── Tests
│ ├── LinuxMain.swift
│ └── benchmarkTests
│ │ ├── XCTestManifests.swift
│ │ └── benchmarkTests.swift
└── benchmark.xcodeproj
│ ├── BrightFutures_Info.plist
│ ├── FBLPromises_Info.plist
│ ├── FutureQ_Info.plist
│ ├── Future_Info.plist
│ ├── Hydra_Info.plist
│ ├── PromiseKit_Info.plist
│ ├── Promises_Info.plist
│ ├── ReactiveSwift_Info.plist
│ ├── Result_Info.plist
│ ├── RxSwift_Info.plist
│ ├── benchmarkTests_Info.plist
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ ├── IDEWorkspaceChecks.plist
│ │ └── WorkspaceSettings.xcsettings
│ └── xcshareddata
│ └── xcschemes
│ ├── benchmark-Package.xcscheme
│ └── benchmark.xcscheme
├── logo.png
├── resources
├── benchmark-concurrent.png
└── benchmark-serial.png
└── utils
└── gyb.py
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4 |
5 | ## User settings
6 | xcuserdata/
7 |
8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
9 | *.xcscmblueprint
10 | *.xccheckout
11 |
12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
13 | build/
14 | DerivedData/
15 | *.moved-aside
16 | *.pbxuser
17 | !default.pbxuser
18 | *.mode1v3
19 | !default.mode1v3
20 | *.mode2v3
21 | !default.mode2v3
22 | *.perspectivev3
23 | !default.perspectivev3
24 |
25 | ## Obj-C/Swift specific
26 | *.hmap
27 |
28 | ## App packaging
29 | *.ipa
30 | *.dSYM.zip
31 | *.dSYM
32 |
33 | ## Playgrounds
34 | timeline.xctimeline
35 | playground.xcworkspace
36 |
37 | # Swift Package Manager
38 | #
39 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
40 | # Packages/
41 | # Package.pins
42 | # Package.resolved
43 | # *.xcodeproj
44 | #
45 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
46 | # hence it is not needed unless you have added a package configuration file to your project
47 | .swiftpm
48 |
49 | .build/
50 |
51 | # CocoaPods
52 | #
53 | # We recommend against adding the Pods directory to your .gitignore. However
54 | # you should judge for yourself, the pros and cons are mentioned at:
55 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
56 | #
57 | # Pods/
58 | #
59 | # Add this line if you want to avoid checking in source code from the Xcode workspace
60 | # *.xcworkspace
61 |
62 | # Carthage
63 | #
64 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
65 | # Carthage/Checkouts
66 |
67 | Carthage/Build/
68 |
69 | # Accio dependency management
70 | Dependencies/
71 | .accio/
72 |
73 | # fastlane
74 | #
75 | # It is recommended to not store the screenshots in the git repo.
76 | # Instead, use fastlane to re-generate the screenshots whenever they are needed.
77 | # For more information about the recommended setup visit:
78 | # https://docs.fastlane.tools/best-practices/source-control/#source-control
79 |
80 | fastlane/report.xml
81 | fastlane/Preview.html
82 | fastlane/screenshots/**/*.png
83 | fastlane/test_output
84 |
85 | # Code Injection
86 | #
87 | # After new code Injection tools there's a generated folder /iOSInjectionProject
88 | # https://github.com/johnno1962/injectionforxcode
89 |
90 | iOSInjectionProject/
--------------------------------------------------------------------------------
/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | branches:
2 | only:
3 | - master
4 |
5 | language: objective-c
6 | osx_image: xcode10.2
7 |
8 | env:
9 | global:
10 | - PROJECT="Future.swift.xcodeproj"
11 | - SCHEME="Future.swift-Package"
12 |
13 | matrix:
14 | include:
15 | - os: osx
16 | env:
17 | - SDK="iphonesimulator12.2"
18 | - DESTINATION="platform=iOS Simulator,name=iPhone 8,OS=12.2"
19 | - os: osx
20 | env:
21 | - SDK="macosx10.14"
22 | - DESTINATION="arch=x86_64"
23 | - os: osx
24 | env:
25 | - SDK="appletvsimulator12.0"
26 | - DESTINATION="OS=12.0,name=Apple TV 4K"
27 | - os: linux
28 | sudo: required
29 | dist: trusty
30 |
31 | before_install:
32 | - if [[ $TRAVIS_OS_NAME == 'osx' ]]; then
33 | gem install xcpretty;
34 | fi
35 | - if [[ $TRAVIS_OS_NAME == 'linux' ]]; then
36 | eval "$(curl -sL https://swiftenv.fuller.li/install.sh)";
37 | fi
38 |
39 | script:
40 | - if [[ $TRAVIS_OS_NAME == 'osx' ]]; then
41 | xcodebuild clean build test -project "$PROJECT" -scheme "$SCHEME" -sdk "$SDK" -destination "$DESTINATION" -enableCodeCoverage YES | xcpretty;
42 | fi
43 | - if [[ $TRAVIS_OS_NAME == 'linux' ]]; then
44 | swift test;
45 | fi
46 |
47 | after_success:
48 | if [[ $TRAVIS_OS_NAME == 'osx' ]]; then
49 | bash <(curl -s https://codecov.io/bash) -J 'Future.swift';
50 | fi
--------------------------------------------------------------------------------
/Future.swift.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 | s.name = "Future.swift"
3 | s.module_name = "Future"
4 | s.version = "0.0.1"
5 | s.license = { :type => "MIT" }
6 | s.homepage = "https://github.com/luoxiu/Future"
7 | s.author = { "Quentin Jin" => "luoxiustm@gmail.com" }
8 | s.summary = "Future is an implementation of futures and promises for Swift."
9 |
10 | s.source = { :git => "https://github.com/luoxiu/Future.git", :tag => "#{s.version}" }
11 | s.source_files = "Sources/Future/**/*.swift"
12 |
13 | s.swift_version = "5.0"
14 |
15 | s.ios.deployment_target = "10.0"
16 | s.osx.deployment_target = "10.12"
17 | s.tvos.deployment_target = "10.0"
18 | s.watchos.deployment_target = "3.0"
19 | end
20 |
--------------------------------------------------------------------------------
/Future.xcodeproj/FutureTests_Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CFBundleDevelopmentRegion
5 | en
6 | CFBundleExecutable
7 | $(EXECUTABLE_NAME)
8 | CFBundleIdentifier
9 | $(PRODUCT_BUNDLE_IDENTIFIER)
10 | CFBundleInfoDictionaryVersion
11 | 6.0
12 | CFBundleName
13 | $(PRODUCT_NAME)
14 | CFBundlePackageType
15 | BNDL
16 | CFBundleShortVersionString
17 | 1.0
18 | CFBundleSignature
19 | ????
20 | CFBundleVersion
21 | $(CURRENT_PROJECT_VERSION)
22 | NSPrincipalClass
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Future.xcodeproj/Future_Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CFBundleDevelopmentRegion
5 | en
6 | CFBundleExecutable
7 | $(EXECUTABLE_NAME)
8 | CFBundleIdentifier
9 | $(PRODUCT_BUNDLE_IDENTIFIER)
10 | CFBundleInfoDictionaryVersion
11 | 6.0
12 | CFBundleName
13 | $(PRODUCT_NAME)
14 | CFBundlePackageType
15 | FMWK
16 | CFBundleShortVersionString
17 | 1.0
18 | CFBundleSignature
19 | ????
20 | CFBundleVersion
21 | $(CURRENT_PROJECT_VERSION)
22 | NSPrincipalClass
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Future.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = "1";
4 | objectVersion = "46";
5 | objects = {
6 | "Future::Future" = {
7 | isa = "PBXNativeTarget";
8 | buildConfigurationList = "OBJ_71";
9 | buildPhases = (
10 | "OBJ_74",
11 | "OBJ_117"
12 | );
13 | dependencies = (
14 | );
15 | name = "Future";
16 | productName = "Future";
17 | productReference = "Future::Future::Product";
18 | productType = "com.apple.product-type.framework";
19 | };
20 | "Future::Future::Product" = {
21 | isa = "PBXFileReference";
22 | path = "Future.framework";
23 | sourceTree = "BUILT_PRODUCTS_DIR";
24 | };
25 | "Future::FuturePackageTests::ProductTarget" = {
26 | isa = "PBXAggregateTarget";
27 | buildConfigurationList = "OBJ_125";
28 | buildPhases = (
29 | );
30 | dependencies = (
31 | "OBJ_128"
32 | );
33 | name = "FuturePackageTests";
34 | productName = "FuturePackageTests";
35 | };
36 | "Future::FutureTests" = {
37 | isa = "PBXNativeTarget";
38 | buildConfigurationList = "OBJ_130";
39 | buildPhases = (
40 | "OBJ_133",
41 | "OBJ_139"
42 | );
43 | dependencies = (
44 | "OBJ_141"
45 | );
46 | name = "FutureTests";
47 | productName = "FutureTests";
48 | productReference = "Future::FutureTests::Product";
49 | productType = "com.apple.product-type.bundle.unit-test";
50 | };
51 | "Future::FutureTests::Product" = {
52 | isa = "PBXFileReference";
53 | path = "FutureTests.xctest";
54 | sourceTree = "BUILT_PRODUCTS_DIR";
55 | };
56 | "Future::SwiftPMPackageDescription" = {
57 | isa = "PBXNativeTarget";
58 | buildConfigurationList = "OBJ_119";
59 | buildPhases = (
60 | "OBJ_122"
61 | );
62 | dependencies = (
63 | );
64 | name = "FuturePackageDescription";
65 | productName = "FuturePackageDescription";
66 | productType = "com.apple.product-type.framework";
67 | };
68 | "OBJ_1" = {
69 | isa = "PBXProject";
70 | attributes = {
71 | LastSwiftMigration = "9999";
72 | LastUpgradeCheck = "9999";
73 | };
74 | buildConfigurationList = "OBJ_2";
75 | compatibilityVersion = "Xcode 3.2";
76 | developmentRegion = "English";
77 | hasScannedForEncodings = "0";
78 | knownRegions = (
79 | "en"
80 | );
81 | mainGroup = "OBJ_5";
82 | productRefGroup = "OBJ_60";
83 | projectDirPath = ".";
84 | targets = (
85 | "Future::Future",
86 | "Future::SwiftPMPackageDescription",
87 | "Future::FuturePackageTests::ProductTarget",
88 | "Future::FutureTests"
89 | );
90 | };
91 | "OBJ_10" = {
92 | isa = "PBXGroup";
93 | children = (
94 | "OBJ_11",
95 | "OBJ_12",
96 | "OBJ_13",
97 | "OBJ_14",
98 | "OBJ_15",
99 | "OBJ_16",
100 | "OBJ_17",
101 | "OBJ_18",
102 | "OBJ_19",
103 | "OBJ_20",
104 | "OBJ_21",
105 | "OBJ_22",
106 | "OBJ_23",
107 | "OBJ_24",
108 | "OBJ_25",
109 | "OBJ_26",
110 | "OBJ_27",
111 | "OBJ_28",
112 | "OBJ_29",
113 | "OBJ_30",
114 | "OBJ_31",
115 | "OBJ_32",
116 | "OBJ_33",
117 | "OBJ_34",
118 | "OBJ_35",
119 | "OBJ_36",
120 | "OBJ_37",
121 | "OBJ_38",
122 | "OBJ_39",
123 | "OBJ_40",
124 | "OBJ_41",
125 | "OBJ_42",
126 | "OBJ_43"
127 | );
128 | name = "Features";
129 | path = "Features";
130 | sourceTree = "";
131 | };
132 | "OBJ_100" = {
133 | isa = "PBXBuildFile";
134 | fileRef = "OBJ_35";
135 | };
136 | "OBJ_101" = {
137 | isa = "PBXBuildFile";
138 | fileRef = "OBJ_36";
139 | };
140 | "OBJ_102" = {
141 | isa = "PBXBuildFile";
142 | fileRef = "OBJ_37";
143 | };
144 | "OBJ_103" = {
145 | isa = "PBXBuildFile";
146 | fileRef = "OBJ_38";
147 | };
148 | "OBJ_104" = {
149 | isa = "PBXBuildFile";
150 | fileRef = "OBJ_39";
151 | };
152 | "OBJ_105" = {
153 | isa = "PBXBuildFile";
154 | fileRef = "OBJ_40";
155 | };
156 | "OBJ_106" = {
157 | isa = "PBXBuildFile";
158 | fileRef = "OBJ_41";
159 | };
160 | "OBJ_107" = {
161 | isa = "PBXBuildFile";
162 | fileRef = "OBJ_42";
163 | };
164 | "OBJ_108" = {
165 | isa = "PBXBuildFile";
166 | fileRef = "OBJ_43";
167 | };
168 | "OBJ_109" = {
169 | isa = "PBXBuildFile";
170 | fileRef = "OBJ_44";
171 | };
172 | "OBJ_11" = {
173 | isa = "PBXFileReference";
174 | path = "always.swift";
175 | sourceTree = "";
176 | };
177 | "OBJ_110" = {
178 | isa = "PBXBuildFile";
179 | fileRef = "OBJ_46";
180 | };
181 | "OBJ_111" = {
182 | isa = "PBXBuildFile";
183 | fileRef = "OBJ_47";
184 | };
185 | "OBJ_112" = {
186 | isa = "PBXBuildFile";
187 | fileRef = "OBJ_48";
188 | };
189 | "OBJ_113" = {
190 | isa = "PBXBuildFile";
191 | fileRef = "OBJ_49";
192 | };
193 | "OBJ_114" = {
194 | isa = "PBXBuildFile";
195 | fileRef = "OBJ_50";
196 | };
197 | "OBJ_115" = {
198 | isa = "PBXBuildFile";
199 | fileRef = "OBJ_51";
200 | };
201 | "OBJ_116" = {
202 | isa = "PBXBuildFile";
203 | fileRef = "OBJ_52";
204 | };
205 | "OBJ_117" = {
206 | isa = "PBXFrameworksBuildPhase";
207 | files = (
208 | );
209 | };
210 | "OBJ_119" = {
211 | isa = "XCConfigurationList";
212 | buildConfigurations = (
213 | "OBJ_120",
214 | "OBJ_121"
215 | );
216 | defaultConfigurationIsVisible = "0";
217 | defaultConfigurationName = "Release";
218 | };
219 | "OBJ_12" = {
220 | isa = "PBXFileReference";
221 | path = "and.swift";
222 | sourceTree = "";
223 | };
224 | "OBJ_120" = {
225 | isa = "XCBuildConfiguration";
226 | buildSettings = {
227 | LD = "/usr/bin/true";
228 | OTHER_SWIFT_FLAGS = (
229 | "-swift-version",
230 | "5",
231 | "-I",
232 | "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2",
233 | "-target",
234 | "x86_64-apple-macosx10.10",
235 | "-sdk",
236 | "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk"
237 | );
238 | SWIFT_VERSION = "5.0";
239 | };
240 | name = "Debug";
241 | };
242 | "OBJ_121" = {
243 | isa = "XCBuildConfiguration";
244 | buildSettings = {
245 | LD = "/usr/bin/true";
246 | OTHER_SWIFT_FLAGS = (
247 | "-swift-version",
248 | "5",
249 | "-I",
250 | "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2",
251 | "-target",
252 | "x86_64-apple-macosx10.10",
253 | "-sdk",
254 | "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk"
255 | );
256 | SWIFT_VERSION = "5.0";
257 | };
258 | name = "Release";
259 | };
260 | "OBJ_122" = {
261 | isa = "PBXSourcesBuildPhase";
262 | files = (
263 | "OBJ_123"
264 | );
265 | };
266 | "OBJ_123" = {
267 | isa = "PBXBuildFile";
268 | fileRef = "OBJ_6";
269 | };
270 | "OBJ_125" = {
271 | isa = "XCConfigurationList";
272 | buildConfigurations = (
273 | "OBJ_126",
274 | "OBJ_127"
275 | );
276 | defaultConfigurationIsVisible = "0";
277 | defaultConfigurationName = "Release";
278 | };
279 | "OBJ_126" = {
280 | isa = "XCBuildConfiguration";
281 | buildSettings = {
282 | };
283 | name = "Debug";
284 | };
285 | "OBJ_127" = {
286 | isa = "XCBuildConfiguration";
287 | buildSettings = {
288 | };
289 | name = "Release";
290 | };
291 | "OBJ_128" = {
292 | isa = "PBXTargetDependency";
293 | target = "Future::FutureTests";
294 | };
295 | "OBJ_13" = {
296 | isa = "PBXFileReference";
297 | path = "any.swift";
298 | sourceTree = "";
299 | };
300 | "OBJ_130" = {
301 | isa = "XCConfigurationList";
302 | buildConfigurations = (
303 | "OBJ_131",
304 | "OBJ_132"
305 | );
306 | defaultConfigurationIsVisible = "0";
307 | defaultConfigurationName = "Release";
308 | };
309 | "OBJ_131" = {
310 | isa = "XCBuildConfiguration";
311 | buildSettings = {
312 | CLANG_ENABLE_MODULES = "YES";
313 | EMBEDDED_CONTENT_CONTAINS_SWIFT = "YES";
314 | FRAMEWORK_SEARCH_PATHS = (
315 | "$(inherited)",
316 | "$(PLATFORM_DIR)/Developer/Library/Frameworks"
317 | );
318 | HEADER_SEARCH_PATHS = (
319 | "$(inherited)"
320 | );
321 | INFOPLIST_FILE = "Future.xcodeproj/FutureTests_Info.plist";
322 | IPHONEOS_DEPLOYMENT_TARGET = "10.0";
323 | LD_RUNPATH_SEARCH_PATHS = (
324 | "$(inherited)",
325 | "@loader_path/../Frameworks",
326 | "@loader_path/Frameworks"
327 | );
328 | MACOSX_DEPLOYMENT_TARGET = "10.12";
329 | OTHER_CFLAGS = (
330 | "$(inherited)"
331 | );
332 | OTHER_LDFLAGS = (
333 | "$(inherited)"
334 | );
335 | OTHER_SWIFT_FLAGS = (
336 | "$(inherited)"
337 | );
338 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = (
339 | "$(inherited)"
340 | );
341 | SWIFT_VERSION = "5.0";
342 | TARGET_NAME = "FutureTests";
343 | TVOS_DEPLOYMENT_TARGET = "10.0";
344 | WATCHOS_DEPLOYMENT_TARGET = "3.0";
345 | };
346 | name = "Debug";
347 | };
348 | "OBJ_132" = {
349 | isa = "XCBuildConfiguration";
350 | buildSettings = {
351 | CLANG_ENABLE_MODULES = "YES";
352 | EMBEDDED_CONTENT_CONTAINS_SWIFT = "YES";
353 | FRAMEWORK_SEARCH_PATHS = (
354 | "$(inherited)",
355 | "$(PLATFORM_DIR)/Developer/Library/Frameworks"
356 | );
357 | HEADER_SEARCH_PATHS = (
358 | "$(inherited)"
359 | );
360 | INFOPLIST_FILE = "Future.xcodeproj/FutureTests_Info.plist";
361 | IPHONEOS_DEPLOYMENT_TARGET = "10.0";
362 | LD_RUNPATH_SEARCH_PATHS = (
363 | "$(inherited)",
364 | "@loader_path/../Frameworks",
365 | "@loader_path/Frameworks"
366 | );
367 | MACOSX_DEPLOYMENT_TARGET = "10.12";
368 | OTHER_CFLAGS = (
369 | "$(inherited)"
370 | );
371 | OTHER_LDFLAGS = (
372 | "$(inherited)"
373 | );
374 | OTHER_SWIFT_FLAGS = (
375 | "$(inherited)"
376 | );
377 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = (
378 | "$(inherited)"
379 | );
380 | SWIFT_VERSION = "5.0";
381 | TARGET_NAME = "FutureTests";
382 | TVOS_DEPLOYMENT_TARGET = "10.0";
383 | WATCHOS_DEPLOYMENT_TARGET = "3.0";
384 | };
385 | name = "Release";
386 | };
387 | "OBJ_133" = {
388 | isa = "PBXSourcesBuildPhase";
389 | files = (
390 | "OBJ_134",
391 | "OBJ_135",
392 | "OBJ_136",
393 | "OBJ_137",
394 | "OBJ_138"
395 | );
396 | };
397 | "OBJ_134" = {
398 | isa = "PBXBuildFile";
399 | fileRef = "OBJ_55";
400 | };
401 | "OBJ_135" = {
402 | isa = "PBXBuildFile";
403 | fileRef = "OBJ_56";
404 | };
405 | "OBJ_136" = {
406 | isa = "PBXBuildFile";
407 | fileRef = "OBJ_57";
408 | };
409 | "OBJ_137" = {
410 | isa = "PBXBuildFile";
411 | fileRef = "OBJ_58";
412 | };
413 | "OBJ_138" = {
414 | isa = "PBXBuildFile";
415 | fileRef = "OBJ_59";
416 | };
417 | "OBJ_139" = {
418 | isa = "PBXFrameworksBuildPhase";
419 | files = (
420 | "OBJ_140"
421 | );
422 | };
423 | "OBJ_14" = {
424 | isa = "PBXFileReference";
425 | path = "asAny.swift";
426 | sourceTree = "";
427 | };
428 | "OBJ_140" = {
429 | isa = "PBXBuildFile";
430 | fileRef = "Future::Future::Product";
431 | };
432 | "OBJ_141" = {
433 | isa = "PBXTargetDependency";
434 | target = "Future::Future";
435 | };
436 | "OBJ_15" = {
437 | isa = "PBXFileReference";
438 | path = "asVoid.swift";
439 | sourceTree = "";
440 | };
441 | "OBJ_16" = {
442 | isa = "PBXFileReference";
443 | path = "catch.swift";
444 | sourceTree = "";
445 | };
446 | "OBJ_17" = {
447 | isa = "PBXFileReference";
448 | path = "delay.swift";
449 | sourceTree = "";
450 | };
451 | "OBJ_18" = {
452 | isa = "PBXFileReference";
453 | path = "done.swift";
454 | sourceTree = "";
455 | };
456 | "OBJ_19" = {
457 | isa = "PBXFileReference";
458 | path = "finally.swift";
459 | sourceTree = "";
460 | };
461 | "OBJ_2" = {
462 | isa = "XCConfigurationList";
463 | buildConfigurations = (
464 | "OBJ_3",
465 | "OBJ_4"
466 | );
467 | defaultConfigurationIsVisible = "0";
468 | defaultConfigurationName = "Release";
469 | };
470 | "OBJ_20" = {
471 | isa = "PBXFileReference";
472 | path = "flat.swift";
473 | sourceTree = "";
474 | };
475 | "OBJ_21" = {
476 | isa = "PBXFileReference";
477 | path = "flatMap.swift";
478 | sourceTree = "";
479 | };
480 | "OBJ_22" = {
481 | isa = "PBXFileReference";
482 | path = "hush.swift";
483 | sourceTree = "";
484 | };
485 | "OBJ_23" = {
486 | isa = "PBXFileReference";
487 | path = "map.swift";
488 | sourceTree = "";
489 | };
490 | "OBJ_24" = {
491 | isa = "PBXFileReference";
492 | path = "mute.swift";
493 | sourceTree = "";
494 | };
495 | "OBJ_25" = {
496 | isa = "PBXFileReference";
497 | path = "pipe.swift";
498 | sourceTree = "";
499 | };
500 | "OBJ_26" = {
501 | isa = "PBXFileReference";
502 | path = "race.swift";
503 | sourceTree = "";
504 | };
505 | "OBJ_27" = {
506 | isa = "PBXFileReference";
507 | path = "recover.swift";
508 | sourceTree = "";
509 | };
510 | "OBJ_28" = {
511 | isa = "PBXFileReference";
512 | path = "reduce.swift";
513 | sourceTree = "";
514 | };
515 | "OBJ_29" = {
516 | isa = "PBXFileReference";
517 | path = "retry.swift";
518 | sourceTree = "";
519 | };
520 | "OBJ_3" = {
521 | isa = "XCBuildConfiguration";
522 | buildSettings = {
523 | CLANG_ENABLE_OBJC_ARC = "YES";
524 | COMBINE_HIDPI_IMAGES = "YES";
525 | COPY_PHASE_STRIP = "NO";
526 | DEBUG_INFORMATION_FORMAT = "dwarf";
527 | DYLIB_INSTALL_NAME_BASE = "@rpath";
528 | ENABLE_NS_ASSERTIONS = "YES";
529 | GCC_OPTIMIZATION_LEVEL = "0";
530 | GCC_PREPROCESSOR_DEFINITIONS = (
531 | "$(inherited)",
532 | "SWIFT_PACKAGE=1",
533 | "DEBUG=1"
534 | );
535 | MACOSX_DEPLOYMENT_TARGET = "10.10";
536 | ONLY_ACTIVE_ARCH = "YES";
537 | OTHER_SWIFT_FLAGS = (
538 | "-DXcode"
539 | );
540 | PRODUCT_NAME = "$(TARGET_NAME)";
541 | SDKROOT = "macosx";
542 | SUPPORTED_PLATFORMS = (
543 | "macosx",
544 | "iphoneos",
545 | "iphonesimulator",
546 | "appletvos",
547 | "appletvsimulator",
548 | "watchos",
549 | "watchsimulator"
550 | );
551 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = (
552 | "$(inherited)",
553 | "SWIFT_PACKAGE",
554 | "DEBUG"
555 | );
556 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
557 | USE_HEADERMAP = "NO";
558 | };
559 | name = "Debug";
560 | };
561 | "OBJ_30" = {
562 | isa = "PBXFileReference";
563 | path = "return.swift";
564 | sourceTree = "";
565 | };
566 | "OBJ_31" = {
567 | isa = "PBXFileReference";
568 | path = "some.swift";
569 | sourceTree = "";
570 | };
571 | "OBJ_32" = {
572 | isa = "PBXFileReference";
573 | path = "tap.swift";
574 | sourceTree = "";
575 | };
576 | "OBJ_33" = {
577 | isa = "PBXFileReference";
578 | path = "then.swift";
579 | sourceTree = "";
580 | };
581 | "OBJ_34" = {
582 | isa = "PBXFileReference";
583 | path = "timeout.swift";
584 | sourceTree = "";
585 | };
586 | "OBJ_35" = {
587 | isa = "PBXFileReference";
588 | path = "validate.swift";
589 | sourceTree = "";
590 | };
591 | "OBJ_36" = {
592 | isa = "PBXFileReference";
593 | path = "wait.swift";
594 | sourceTree = "";
595 | };
596 | "OBJ_37" = {
597 | isa = "PBXFileReference";
598 | path = "whenAll.T.swift";
599 | sourceTree = "";
600 | };
601 | "OBJ_38" = {
602 | isa = "PBXFileReference";
603 | path = "whenAll.swift";
604 | sourceTree = "";
605 | };
606 | "OBJ_39" = {
607 | isa = "PBXFileReference";
608 | path = "whenAllVoid.T.swift";
609 | sourceTree = "";
610 | };
611 | "OBJ_4" = {
612 | isa = "XCBuildConfiguration";
613 | buildSettings = {
614 | CLANG_ENABLE_OBJC_ARC = "YES";
615 | COMBINE_HIDPI_IMAGES = "YES";
616 | COPY_PHASE_STRIP = "YES";
617 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
618 | DYLIB_INSTALL_NAME_BASE = "@rpath";
619 | GCC_OPTIMIZATION_LEVEL = "s";
620 | GCC_PREPROCESSOR_DEFINITIONS = (
621 | "$(inherited)",
622 | "SWIFT_PACKAGE=1"
623 | );
624 | MACOSX_DEPLOYMENT_TARGET = "10.10";
625 | OTHER_SWIFT_FLAGS = (
626 | "-DXcode"
627 | );
628 | PRODUCT_NAME = "$(TARGET_NAME)";
629 | SDKROOT = "macosx";
630 | SUPPORTED_PLATFORMS = (
631 | "macosx",
632 | "iphoneos",
633 | "iphonesimulator",
634 | "appletvos",
635 | "appletvsimulator",
636 | "watchos",
637 | "watchsimulator"
638 | );
639 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = (
640 | "$(inherited)",
641 | "SWIFT_PACKAGE"
642 | );
643 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
644 | USE_HEADERMAP = "NO";
645 | };
646 | name = "Release";
647 | };
648 | "OBJ_40" = {
649 | isa = "PBXFileReference";
650 | path = "whenAllVoid.swift";
651 | sourceTree = "";
652 | };
653 | "OBJ_41" = {
654 | isa = "PBXFileReference";
655 | path = "whenAny.T.swift";
656 | sourceTree = "";
657 | };
658 | "OBJ_42" = {
659 | isa = "PBXFileReference";
660 | path = "whenAny.swift";
661 | sourceTree = "";
662 | };
663 | "OBJ_43" = {
664 | isa = "PBXFileReference";
665 | path = "yield.swift";
666 | sourceTree = "";
667 | };
668 | "OBJ_44" = {
669 | isa = "PBXFileReference";
670 | path = "Future.swift";
671 | sourceTree = "";
672 | };
673 | "OBJ_45" = {
674 | isa = "PBXGroup";
675 | children = (
676 | "OBJ_46",
677 | "OBJ_47",
678 | "OBJ_48"
679 | );
680 | name = "Helpers";
681 | path = "Helpers";
682 | sourceTree = "";
683 | };
684 | "OBJ_46" = {
685 | isa = "PBXFileReference";
686 | path = "Atom.swift";
687 | sourceTree = "";
688 | };
689 | "OBJ_47" = {
690 | isa = "PBXFileReference";
691 | path = "Extensions.swift";
692 | sourceTree = "";
693 | };
694 | "OBJ_48" = {
695 | isa = "PBXFileReference";
696 | path = "Lock.swift";
697 | sourceTree = "";
698 | };
699 | "OBJ_49" = {
700 | isa = "PBXFileReference";
701 | path = "Promise.swift";
702 | sourceTree = "";
703 | };
704 | "OBJ_5" = {
705 | isa = "PBXGroup";
706 | children = (
707 | "OBJ_6",
708 | "OBJ_7",
709 | "OBJ_53",
710 | "OBJ_60",
711 | "OBJ_63",
712 | "OBJ_64",
713 | "OBJ_65",
714 | "OBJ_66",
715 | "OBJ_67",
716 | "OBJ_68",
717 | "OBJ_69"
718 | );
719 | path = "";
720 | sourceTree = "";
721 | };
722 | "OBJ_50" = {
723 | isa = "PBXFileReference";
724 | path = "Publisher.swift";
725 | sourceTree = "";
726 | };
727 | "OBJ_51" = {
728 | isa = "PBXFileReference";
729 | path = "Scheduler.swift";
730 | sourceTree = "";
731 | };
732 | "OBJ_52" = {
733 | isa = "PBXFileReference";
734 | path = "Thenable.swift";
735 | sourceTree = "";
736 | };
737 | "OBJ_53" = {
738 | isa = "PBXGroup";
739 | children = (
740 | "OBJ_54"
741 | );
742 | name = "Tests";
743 | path = "";
744 | sourceTree = "SOURCE_ROOT";
745 | };
746 | "OBJ_54" = {
747 | isa = "PBXGroup";
748 | children = (
749 | "OBJ_55",
750 | "OBJ_56",
751 | "OBJ_57",
752 | "OBJ_58",
753 | "OBJ_59"
754 | );
755 | name = "FutureTests";
756 | path = "Tests/FutureTests";
757 | sourceTree = "SOURCE_ROOT";
758 | };
759 | "OBJ_55" = {
760 | isa = "PBXFileReference";
761 | path = "AsyncTests.swift";
762 | sourceTree = "";
763 | };
764 | "OBJ_56" = {
765 | isa = "PBXFileReference";
766 | path = "FeaturesTests.swift";
767 | sourceTree = "";
768 | };
769 | "OBJ_57" = {
770 | isa = "PBXFileReference";
771 | path = "FutureTests.swift";
772 | sourceTree = "";
773 | };
774 | "OBJ_58" = {
775 | isa = "PBXFileReference";
776 | path = "Helpers.swift";
777 | sourceTree = "";
778 | };
779 | "OBJ_59" = {
780 | isa = "PBXFileReference";
781 | path = "XCTestManifests.swift";
782 | sourceTree = "";
783 | };
784 | "OBJ_6" = {
785 | isa = "PBXFileReference";
786 | explicitFileType = "sourcecode.swift";
787 | path = "Package.swift";
788 | sourceTree = "";
789 | };
790 | "OBJ_60" = {
791 | isa = "PBXGroup";
792 | children = (
793 | "Future::Future::Product",
794 | "Future::FutureTests::Product"
795 | );
796 | name = "Products";
797 | path = "";
798 | sourceTree = "BUILT_PRODUCTS_DIR";
799 | };
800 | "OBJ_63" = {
801 | isa = "PBXFileReference";
802 | path = "benchmark";
803 | sourceTree = "SOURCE_ROOT";
804 | };
805 | "OBJ_64" = {
806 | isa = "PBXFileReference";
807 | path = "resources";
808 | sourceTree = "SOURCE_ROOT";
809 | };
810 | "OBJ_65" = {
811 | isa = "PBXFileReference";
812 | path = "utils";
813 | sourceTree = "SOURCE_ROOT";
814 | };
815 | "OBJ_66" = {
816 | isa = "PBXFileReference";
817 | path = "LICENSE";
818 | sourceTree = "";
819 | };
820 | "OBJ_67" = {
821 | isa = "PBXFileReference";
822 | path = "Future.swift.podspec";
823 | sourceTree = "";
824 | };
825 | "OBJ_68" = {
826 | isa = "PBXFileReference";
827 | path = "README.md";
828 | sourceTree = "";
829 | };
830 | "OBJ_69" = {
831 | isa = "PBXFileReference";
832 | path = "logo.png";
833 | sourceTree = "";
834 | };
835 | "OBJ_7" = {
836 | isa = "PBXGroup";
837 | children = (
838 | "OBJ_8"
839 | );
840 | name = "Sources";
841 | path = "";
842 | sourceTree = "SOURCE_ROOT";
843 | };
844 | "OBJ_71" = {
845 | isa = "XCConfigurationList";
846 | buildConfigurations = (
847 | "OBJ_72",
848 | "OBJ_73"
849 | );
850 | defaultConfigurationIsVisible = "0";
851 | defaultConfigurationName = "Release";
852 | };
853 | "OBJ_72" = {
854 | isa = "XCBuildConfiguration";
855 | buildSettings = {
856 | ENABLE_TESTABILITY = "YES";
857 | FRAMEWORK_SEARCH_PATHS = (
858 | "$(inherited)",
859 | "$(PLATFORM_DIR)/Developer/Library/Frameworks"
860 | );
861 | HEADER_SEARCH_PATHS = (
862 | "$(inherited)"
863 | );
864 | INFOPLIST_FILE = "Future.xcodeproj/Future_Info.plist";
865 | IPHONEOS_DEPLOYMENT_TARGET = "10.0";
866 | LD_RUNPATH_SEARCH_PATHS = (
867 | "$(inherited)",
868 | "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx"
869 | );
870 | MACOSX_DEPLOYMENT_TARGET = "10.12";
871 | OTHER_CFLAGS = (
872 | "$(inherited)"
873 | );
874 | OTHER_LDFLAGS = (
875 | "$(inherited)"
876 | );
877 | OTHER_SWIFT_FLAGS = (
878 | "$(inherited)"
879 | );
880 | PRODUCT_BUNDLE_IDENTIFIER = "Future";
881 | PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
882 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
883 | SKIP_INSTALL = "YES";
884 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = (
885 | "$(inherited)"
886 | );
887 | SWIFT_VERSION = "5.0";
888 | TARGET_NAME = "Future";
889 | TVOS_DEPLOYMENT_TARGET = "10.0";
890 | WATCHOS_DEPLOYMENT_TARGET = "3.0";
891 | };
892 | name = "Debug";
893 | };
894 | "OBJ_73" = {
895 | isa = "XCBuildConfiguration";
896 | buildSettings = {
897 | ENABLE_TESTABILITY = "YES";
898 | FRAMEWORK_SEARCH_PATHS = (
899 | "$(inherited)",
900 | "$(PLATFORM_DIR)/Developer/Library/Frameworks"
901 | );
902 | HEADER_SEARCH_PATHS = (
903 | "$(inherited)"
904 | );
905 | INFOPLIST_FILE = "Future.xcodeproj/Future_Info.plist";
906 | IPHONEOS_DEPLOYMENT_TARGET = "10.0";
907 | LD_RUNPATH_SEARCH_PATHS = (
908 | "$(inherited)",
909 | "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx"
910 | );
911 | MACOSX_DEPLOYMENT_TARGET = "10.12";
912 | OTHER_CFLAGS = (
913 | "$(inherited)"
914 | );
915 | OTHER_LDFLAGS = (
916 | "$(inherited)"
917 | );
918 | OTHER_SWIFT_FLAGS = (
919 | "$(inherited)"
920 | );
921 | PRODUCT_BUNDLE_IDENTIFIER = "Future";
922 | PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
923 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
924 | SKIP_INSTALL = "YES";
925 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = (
926 | "$(inherited)"
927 | );
928 | SWIFT_VERSION = "5.0";
929 | TARGET_NAME = "Future";
930 | TVOS_DEPLOYMENT_TARGET = "10.0";
931 | WATCHOS_DEPLOYMENT_TARGET = "3.0";
932 | };
933 | name = "Release";
934 | };
935 | "OBJ_74" = {
936 | isa = "PBXSourcesBuildPhase";
937 | files = (
938 | "OBJ_75",
939 | "OBJ_76",
940 | "OBJ_77",
941 | "OBJ_78",
942 | "OBJ_79",
943 | "OBJ_80",
944 | "OBJ_81",
945 | "OBJ_82",
946 | "OBJ_83",
947 | "OBJ_84",
948 | "OBJ_85",
949 | "OBJ_86",
950 | "OBJ_87",
951 | "OBJ_88",
952 | "OBJ_89",
953 | "OBJ_90",
954 | "OBJ_91",
955 | "OBJ_92",
956 | "OBJ_93",
957 | "OBJ_94",
958 | "OBJ_95",
959 | "OBJ_96",
960 | "OBJ_97",
961 | "OBJ_98",
962 | "OBJ_99",
963 | "OBJ_100",
964 | "OBJ_101",
965 | "OBJ_102",
966 | "OBJ_103",
967 | "OBJ_104",
968 | "OBJ_105",
969 | "OBJ_106",
970 | "OBJ_107",
971 | "OBJ_108",
972 | "OBJ_109",
973 | "OBJ_110",
974 | "OBJ_111",
975 | "OBJ_112",
976 | "OBJ_113",
977 | "OBJ_114",
978 | "OBJ_115",
979 | "OBJ_116"
980 | );
981 | };
982 | "OBJ_75" = {
983 | isa = "PBXBuildFile";
984 | fileRef = "OBJ_9";
985 | };
986 | "OBJ_76" = {
987 | isa = "PBXBuildFile";
988 | fileRef = "OBJ_11";
989 | };
990 | "OBJ_77" = {
991 | isa = "PBXBuildFile";
992 | fileRef = "OBJ_12";
993 | };
994 | "OBJ_78" = {
995 | isa = "PBXBuildFile";
996 | fileRef = "OBJ_13";
997 | };
998 | "OBJ_79" = {
999 | isa = "PBXBuildFile";
1000 | fileRef = "OBJ_14";
1001 | };
1002 | "OBJ_8" = {
1003 | isa = "PBXGroup";
1004 | children = (
1005 | "OBJ_9",
1006 | "OBJ_10",
1007 | "OBJ_44",
1008 | "OBJ_45",
1009 | "OBJ_49",
1010 | "OBJ_50",
1011 | "OBJ_51",
1012 | "OBJ_52"
1013 | );
1014 | name = "Future";
1015 | path = "Sources/Future";
1016 | sourceTree = "SOURCE_ROOT";
1017 | };
1018 | "OBJ_80" = {
1019 | isa = "PBXBuildFile";
1020 | fileRef = "OBJ_15";
1021 | };
1022 | "OBJ_81" = {
1023 | isa = "PBXBuildFile";
1024 | fileRef = "OBJ_16";
1025 | };
1026 | "OBJ_82" = {
1027 | isa = "PBXBuildFile";
1028 | fileRef = "OBJ_17";
1029 | };
1030 | "OBJ_83" = {
1031 | isa = "PBXBuildFile";
1032 | fileRef = "OBJ_18";
1033 | };
1034 | "OBJ_84" = {
1035 | isa = "PBXBuildFile";
1036 | fileRef = "OBJ_19";
1037 | };
1038 | "OBJ_85" = {
1039 | isa = "PBXBuildFile";
1040 | fileRef = "OBJ_20";
1041 | };
1042 | "OBJ_86" = {
1043 | isa = "PBXBuildFile";
1044 | fileRef = "OBJ_21";
1045 | };
1046 | "OBJ_87" = {
1047 | isa = "PBXBuildFile";
1048 | fileRef = "OBJ_22";
1049 | };
1050 | "OBJ_88" = {
1051 | isa = "PBXBuildFile";
1052 | fileRef = "OBJ_23";
1053 | };
1054 | "OBJ_89" = {
1055 | isa = "PBXBuildFile";
1056 | fileRef = "OBJ_24";
1057 | };
1058 | "OBJ_9" = {
1059 | isa = "PBXFileReference";
1060 | path = "Async.swift";
1061 | sourceTree = "";
1062 | };
1063 | "OBJ_90" = {
1064 | isa = "PBXBuildFile";
1065 | fileRef = "OBJ_25";
1066 | };
1067 | "OBJ_91" = {
1068 | isa = "PBXBuildFile";
1069 | fileRef = "OBJ_26";
1070 | };
1071 | "OBJ_92" = {
1072 | isa = "PBXBuildFile";
1073 | fileRef = "OBJ_27";
1074 | };
1075 | "OBJ_93" = {
1076 | isa = "PBXBuildFile";
1077 | fileRef = "OBJ_28";
1078 | };
1079 | "OBJ_94" = {
1080 | isa = "PBXBuildFile";
1081 | fileRef = "OBJ_29";
1082 | };
1083 | "OBJ_95" = {
1084 | isa = "PBXBuildFile";
1085 | fileRef = "OBJ_30";
1086 | };
1087 | "OBJ_96" = {
1088 | isa = "PBXBuildFile";
1089 | fileRef = "OBJ_31";
1090 | };
1091 | "OBJ_97" = {
1092 | isa = "PBXBuildFile";
1093 | fileRef = "OBJ_32";
1094 | };
1095 | "OBJ_98" = {
1096 | isa = "PBXBuildFile";
1097 | fileRef = "OBJ_33";
1098 | };
1099 | "OBJ_99" = {
1100 | isa = "PBXBuildFile";
1101 | fileRef = "OBJ_34";
1102 | };
1103 | };
1104 | rootObject = "OBJ_1";
1105 | }
1106 |
--------------------------------------------------------------------------------
/Future.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
--------------------------------------------------------------------------------
/Future.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Future.xcodeproj/xcshareddata/xcschemes/Future-Package.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
11 |
12 |
13 |
14 |
15 |
21 |
22 |
24 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Quentin Jin
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Package.resolved:
--------------------------------------------------------------------------------
1 | {
2 | "object": {
3 | "pins": [
4 | {
5 | "package": "swift-atomics",
6 | "repositoryURL": "https://github.com/apple/swift-atomics.git",
7 | "state": {
8 | "branch": null,
9 | "revision": "26e346cd64f6b92d4089e7fafe2f8e82f60ddb8c",
10 | "version": "0.0.2"
11 | }
12 | }
13 | ]
14 | },
15 | "version": 1
16 | }
17 |
--------------------------------------------------------------------------------
/Package.swift:
--------------------------------------------------------------------------------
1 | // swift-tools-version:5.0
2 |
3 | import PackageDescription
4 |
5 | let package = Package(
6 | name: "Future",
7 | platforms: [
8 | .macOS(.v10_12),
9 | .iOS(.v10),
10 | .tvOS(.v10),
11 | .watchOS(.v3)
12 | ],
13 | products: [
14 | .library(name: "Future", targets: ["Future"])
15 | ],
16 | dependencies: [
17 | .package(url: "https://github.com/apple/swift-atomics.git", .upToNextMinor(from: "0.0.1"))
18 | ],
19 | targets: [
20 | .target(name: "Future", dependencies: ["Atomics"]),
21 | .testTarget(name: "FutureTests", dependencies: ["Future"])
22 | ],
23 | swiftLanguageVersions: [
24 | .v5
25 | ]
26 | )
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Future.swift
2 |
3 | 
4 | 
5 | 
6 | 
7 | 
8 |
9 |
10 | `Future.swift` is a [futures and promises](https://en.wikipedia.org/wiki/Futures_and_promises) implementation for Swift.
11 |
12 |
13 |
14 | ## Highlights
15 |
16 | - **Unlimited features**
17 | - **Unmatched performance**
18 | - **Friendly api**
19 | - **Type safe**
20 |
21 | ## Benchmark
22 |
23 | The performance tests I'm using follows [google/promises](https://github.com/google/promises/blob/master/g3doc/index.md#benchmark). The comparison libraries include [promises](https://github.com/google/promises), [PromiseKit](https://github.com/mxcl/PromiseKit), [BrightFutures](https://github.com/Thomvis/BrightFutures) and [Hydra](https://github.com/malcommac/Hydra). In fact, [promises](https://github.com/google/promises) is implemented in Objective-C, but whatever.
24 |
25 | You can see [benchmark/benchmark.xcodeporj](https://github.com/luoxiu/Future.swift/tree/master/benchmark) for more information.
26 |
27 | > Average time in nanoseconds needed to create a resolved promise, chain 1/2/3 blocks and get into the last chained block on a serial queue (measured with 10,000 tries).
28 |
29 |
30 |
31 | > Average time in nanoseconds needed to resolve 10,000 pending promises with chained blocks and wait for control to get into each block on a concurrent queue.
32 |
33 |
34 |
35 | ## Usage
36 |
37 | `Future.swift`'s api is very friendly, here is a real-wold demo:
38 |
39 | ```swift
40 | func fetch(_ str: String) -> Future {
41 | guard let url = URL(string: str) else {
42 | return .failure(.invalidURL(str))
43 | }
44 |
45 | let p = Promise()
46 | URLSession.shared.dataTask(with: url) { (data, response, error) in
47 | if let e = error {
48 | p.fail(HTTPError.session(e))
49 | return
50 | }
51 | p.succeed(HTTPResponse(response, data))
52 | }
53 | return p.future
54 | }
55 |
56 | let img = "https://cdn.io/me.png"
57 | fetch(img)
58 | .validate {
59 | $0.status.isValid()
60 | }
61 | .userInitiated()
62 | .tryMap {
63 | try ImageDecoder().decode($0.data)
64 | }
65 | .main {
66 | self.imageView = $0
67 | }
68 | .background {
69 | cache.add($0, for: img)
70 | }
71 | .catch {
72 | Log.error($0)
73 | }
74 | ```
75 |
76 | `Future.swift`'s core interface is extremely simple, let's take a look:
77 |
78 |
79 | ### Future
80 |
81 | A future represents an eventual result of an asynchronous operation.
82 |
83 | - `isPending`: Return true if the future is pending.
84 |
85 | - `isCompleted`: Return true if the future is completed.
86 |
87 | - `inspect()`: Inspect the future atomically, return nil if the future is pending.
88 |
89 | - `whenComplete(_ callback: @escaping (Result) -> Void)`: Add a callback to the future that will be called when the future is completed.
90 |
91 | ### Promise
92 |
93 | A promise is responsible for managing the state of a future.
94 |
95 | ```swift
96 | let p = Promise()
97 |
98 | DispatchQueue.background {
99 | do {
100 | let r = try task()
101 | p.succeed(r)
102 | } catch let e {
103 | p.fail(e)
104 | }
105 | }
106 |
107 | p.future
108 | ```
109 |
110 | ### Features
111 |
112 | `Future.swift` provides 30+ methods to enhance future's capabilities:
113 |
114 | - `always`
115 | - `and`
116 | - `any`
117 | - `asAny`
118 | - `asVoid`
119 | - `catch`
120 | - `delay`
121 | - `done`
122 | - `finally`
123 | - `flat`
124 | - `flatMap`
125 | - `hush`
126 | - `map`
127 | - `mute`
128 | - `pipe`
129 | - `race`
130 | - `recover`
131 | - `reduce`
132 | - `retry`
133 | - `return`
134 | - `some`
135 | - `tap`
136 | - `then`
137 | - `timeout`
138 | - `validate`
139 | - `wait`
140 | - `yield`
141 | - `whenAll`
142 | - `whenAny`
143 | - ...
144 |
145 | Detailed documentation is still being written, if you have good new ideas, welcome to contribute!
146 |
147 | ## Install
148 |
149 | ```swift
150 | dependencies: [
151 | .package(url: "https://github.com/luoxiu/Future.swift", from: "0.0.0")
152 | ]
153 | ```
154 |
155 | ## License
156 |
157 | MIT
158 |
--------------------------------------------------------------------------------
/Sources/Future/Async.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | public typealias Async = Future
4 |
5 | extension Async {
6 |
7 | public static func background(after seconds: Double = 0, body: @escaping () throws -> T) -> Future {
8 | return self.async(after: seconds, queue: .global(qos: .background), body: body)
9 | }
10 |
11 | public static func utility(after seconds: Double = 0, body: @escaping () throws -> T) -> Future {
12 | return self.async(after: seconds, queue: .global(qos: .utility), body: body)
13 | }
14 |
15 | public static func userInitiated(after seconds: Double = 0, body: @escaping () throws -> T) -> Future {
16 | return self.async(after: seconds, queue: .global(qos: .userInitiated), body: body)
17 | }
18 |
19 | public static func userInteractive(after seconds: Double = 0, body: @escaping () throws -> T) -> Future {
20 | return self.async(after: seconds, queue: .global(qos: .userInteractive), body: body)
21 | }
22 |
23 | public static func main(after seconds: Double = 0, body: @escaping () throws -> T) -> Future {
24 | return self.async(after: seconds, queue: .main, body: body)
25 | }
26 |
27 | private static func async(after seconds: Double = 0, queue: DispatchQueue, body: @escaping () throws -> T) -> Future {
28 | let p = Promise()
29 |
30 | queue.asyncAfter(deadline: .now() + seconds) {
31 | p.complete(Result(catching: body))
32 | }
33 |
34 | return p.future
35 | }
36 | }
37 |
38 | extension Future {
39 |
40 | public func background(after seconds: Double = 0, body: @escaping (Success) -> U) -> Future {
41 | return self.delay(seconds, on: .global(qos: .background)).map(body)
42 | }
43 |
44 | public func utility(after seconds: Double = 0, body: @escaping (Success) -> U) -> Future {
45 | return self.delay(seconds, on: .global(qos: .utility)).map(body)
46 | }
47 |
48 | public func userInitiated(after seconds: Double = 0, body: @escaping (Success) -> U) -> Future {
49 | return self.delay(seconds, on: .global(qos: .userInitiated)).map(body)
50 | }
51 |
52 | public func userInteractive(after seconds: Double = 0, body: @escaping (Success) -> U) -> Future {
53 | return self.delay(seconds, on: .global(qos: .userInteractive)).map(body)
54 | }
55 |
56 | public func main(after seconds: Double = 0, body: @escaping (Success) -> U) -> Future {
57 | return self.delay(seconds, on: .main).map(body)
58 | }
59 |
60 | public func background() -> Future {
61 | return self.yield(on: .global(qos: .background))
62 | }
63 |
64 | public func utility() -> Future {
65 | return self.yield(on: .global(qos: .utility))
66 | }
67 |
68 | public func userInitiated() -> Future {
69 | return self.yield(on: .global(qos: .userInitiated))
70 | }
71 |
72 | public func userInteractive() -> Future {
73 | return self.yield(on: .global(qos: .userInteractive))
74 | }
75 |
76 | public func main() -> Future {
77 | return self.yield(on: .main)
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/Sources/Future/Features/always.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public func always(_ body: @escaping () -> Void) -> Future {
7 | let p = Promise()
8 | self.whenComplete {
9 | body()
10 | p.complete($0)
11 | }
12 | return p.future
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Sources/Future/Features/and.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | public func and(_ thenable: U) -> Future<(Success, U.Success), Failure> where U.Failure == Failure {
6 | return Async.whenAllSucceed(self, thenable)
7 | }
8 |
9 | public func and(_ u: U) -> Future<(Success, U), Failure> {
10 | return self.map { ($0, u) }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Sources/Future/Features/any.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | // Alias for whenAnyComplete
6 | @inlinable
7 | public static func any(_ futures: S) -> Future where S.Element: Thenable {
8 | return self.whenAnyComplete(futures)
9 | }
10 |
11 | // Alias for whenAnyComplete
12 | @inlinable
13 | public static func any(_ futures: T...) -> Future {
14 | return self.whenAnyComplete(futures)
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Sources/Future/Features/asAny.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public func asAny() -> Future {
7 | return self.map { $0 }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Sources/Future/Features/asVoid.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public func asVoid() -> Future {
7 | return self.map { _ in () }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Sources/Future/Features/catch.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public func `catch`(_ body: @escaping (Failure) -> Void) -> Future {
7 | let p = Promise()
8 | self.whenComplete { r in
9 | switch r {
10 | case .success(let s):
11 | p.succeed(s)
12 | case .failure(let e):
13 | body(e)
14 | p.fail(e)
15 | }
16 | }
17 | return p.future
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Sources/Future/Features/delay.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public func delay(_ seconds: Double, on queue: DispatchQueue) -> Future {
7 | let p = Promise()
8 | self.whenComplete { r in
9 | queue.asyncAfter(deadline: .now() + seconds) {
10 | p.complete(r)
11 | }
12 | }
13 | return p.future
14 | }
15 |
16 | @inlinable
17 | public func delay(_ seconds: Double, on scheduler: TimeoutScheduler) -> Future {
18 | let p = Promise()
19 | self.whenComplete { r in
20 | scheduler.schedule(after: seconds) {
21 | p.complete(r)
22 | }
23 | }
24 | return p.future
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Sources/Future/Features/done.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public func done(_ body: @escaping (Success) -> Void) -> Future {
7 | return self.map {
8 | body($0)
9 | return $0
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Sources/Future/Features/finally.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | // Alias for `always`
6 | @inlinable
7 | public func finally(_ body: @escaping () -> Void) -> Future {
8 | return self.always(body)
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Sources/Future/Features/flat.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable where Success: Thenable, Success.Failure == Failure {
4 |
5 | public func flat() -> Future {
6 | return self.flatMap { $0.toFuture() }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/Sources/Future/Features/flatMap.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public func flatMap(_ body: @escaping (Success) -> Future) -> Future {
7 | let p = Promise()
8 | self.whenComplete { r in
9 | switch r {
10 | case .success(let s):
11 | body(s).pipe(to: p)
12 | case .failure(let e):
13 | p.fail(e)
14 | }
15 | }
16 | return p.future
17 | }
18 |
19 | @inlinable
20 | public func flatMapError(_ body: @escaping (Failure) -> Future) -> Future {
21 | let p = Promise()
22 | self.whenComplete { r in
23 | switch r {
24 | case .success(let s):
25 | p.succeed(s)
26 | case .failure(let e):
27 | body(e).pipe(to: p)
28 | }
29 | }
30 | return p.future
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Sources/Future/Features/hush.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | // 🤣
6 | @inlinable
7 | public func hush() { }
8 | }
9 |
--------------------------------------------------------------------------------
/Sources/Future/Features/map.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public func map(_ body: @escaping (Success) -> U) -> Future {
7 | let p = Promise()
8 | self.whenComplete { r in
9 | switch r {
10 | case .success(let s):
11 | p.succeed(body(s))
12 | case .failure(let e):
13 | p.fail(e)
14 | }
15 | }
16 | return p.future
17 | }
18 |
19 | @inlinable
20 | public func tryMap(_ body: @escaping (Success) throws -> U) -> Future {
21 | let p = Promise()
22 | self.whenComplete { r in
23 | switch r {
24 | case .success(let s):
25 | do {
26 | p.succeed(try body(s))
27 | } catch let e {
28 | p.fail(e)
29 | }
30 | case .failure(let e):
31 | p.fail(e)
32 | }
33 | }
34 | return p.future
35 | }
36 |
37 | @inlinable
38 | public func mapError(_ body: @escaping (Error) -> E) -> Future {
39 | let p = Promise()
40 | self.whenComplete { r in
41 | switch r {
42 | case .success(let s):
43 | p.succeed(s)
44 | case .failure(let e):
45 | p.fail(body(e))
46 | }
47 | }
48 | return p.future
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/Sources/Future/Features/mute.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public func mute() { }
7 | }
8 |
--------------------------------------------------------------------------------
/Sources/Future/Features/pipe.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public func pipe(to promise: Promise) {
7 | self.whenComplete(promise.complete)
8 | }
9 |
10 | @inlinable
11 | public func pipeSuccess(to promise: Promise) {
12 | self.whenSucceed(promise.succeed)
13 | }
14 |
15 | @inlinable
16 | public func pipeFailure(to promise: Promise) {
17 | self.whenFail(promise.fail)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Sources/Future/Features/race.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | // Alias for `whenAnyComplete`.
6 | @inlinable
7 | public static func race(_ futures: [T]) -> Future {
8 | return self.whenAnyComplete(futures)
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Sources/Future/Features/recover.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public func recover(_ body: @escaping (Error) -> Success) -> Future {
7 | let p = Promise()
8 |
9 | self.whenComplete { r in
10 | switch r {
11 | case .success(let s):
12 | p.succeed(s)
13 | case .failure(let e):
14 | p.succeed(body(e))
15 | }
16 | }
17 |
18 | return p.future
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Sources/Future/Features/reduce.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public static func reduce(_ thenables: S, initial: U, nextPartial: @escaping (U, S.Element.Success) -> Future) -> Future where S.Element: Thenable {
7 | return self.reduce(thenables, initial: Future.success(initial), nextPartial: nextPartial)
8 | }
9 |
10 | @inlinable
11 | public static func reduce(_ thenables: S, initial: U, nextPartial: @escaping (U.Success, S.Element.Success) -> Future) -> Future where S.Element: Thenable, S.Element.Failure == U.Failure {
12 | return thenables.reduce(initial.toFuture()) { (fu, ft) -> Future in
13 | return whenAllSucceed(fu, ft).flatMap { (ut) in
14 | return nextPartial(ut.0, ut.1)
15 | }
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Sources/Future/Features/retry.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public static func retry(count: Int, task: @escaping () -> Future) -> Future {
7 | return self._retry(count: count, task: task)
8 | }
9 |
10 | @inlinable
11 | static func _retry(count: Int, task: @escaping () -> Future) -> Future {
12 | return task().flatMapError {
13 | if count == 0 {
14 | return Future.failure($0)
15 | } else {
16 | return _retry(count: count - 1, task: task)
17 | }
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Sources/Future/Features/return.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Future {
4 |
5 | // Alias for thenReturn
6 | @inlinable
7 | public func `return`(_ body: @escaping (Success) -> U) -> Future {
8 | return self.map(body)
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Sources/Future/Features/some.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public static func some(_ thenables: S, count: Int) -> Future<[S.Element.Success], S.Element.Failure> where S.Element: Thenable {
7 | let p = Promise<[S.Element.Success], S.Element.Failure>()
8 |
9 | var vals: [S.Element.Success] = []
10 | vals.reserveCapacity(count)
11 |
12 | let atomicVals = Atom(vals)
13 |
14 | for f in thenables {
15 | f.whenSucceed { s in
16 | let after = atomicVals.append(s)
17 | if after.count == count {
18 | p.succeed(after)
19 | }
20 | }
21 | }
22 |
23 | return p.future
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Sources/Future/Features/tap.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public func tap(_ body: @escaping (Success) -> Void) -> Future {
7 | let p = Promise()
8 |
9 | self.whenComplete {
10 | if case .success(let s) = $0 {
11 | body(s)
12 | }
13 | p.complete($0)
14 | }
15 |
16 | return p.future
17 | }
18 |
19 | @inlinable
20 | public func tapError(_ body: @escaping (Failure) -> Void) -> Future {
21 | let p = Promise()
22 |
23 | self.whenComplete {
24 | if case .failure(let e) = $0 {
25 | body(e)
26 | }
27 | p.complete($0)
28 | }
29 |
30 | return p.future
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Sources/Future/Features/then.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | // Alias for whenComplete
6 | @inlinable
7 | public func then(_ callback: @escaping (Result) -> Void) {
8 | self.whenComplete(callback)
9 | }
10 |
11 | // Alias for flatMap
12 | @inlinable
13 | public func then(_ body: @escaping (Success) -> Future) -> Future {
14 | return self.flatMap(body)
15 | }
16 |
17 | // Alias for map
18 | @inlinable
19 | public func thenReturn(_ body: @escaping (Success) -> U) -> Future {
20 | return self.map(body)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Sources/Future/Features/timeout.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public func timeout(_ seconds: Double, on queue: DispatchQueue, whenTimeout: @autoclosure @escaping () -> Failure) -> Future {
7 | let p = Promise()
8 | queue.asyncAfter(deadline: .now() + seconds) {
9 | p.fail(whenTimeout())
10 | }
11 |
12 | self.whenComplete { r in
13 | queue.async {
14 | switch r {
15 | case .success(let s):
16 | p.succeed(s)
17 | case .failure(let e):
18 | p.fail(e)
19 | }
20 | }
21 | }
22 |
23 | return p.future
24 | }
25 |
26 | @inlinable
27 | public func timeout(_ seconds: Double, on scheduler: TimeoutScheduler, whenTimeout: @autoclosure @escaping () -> Failure) -> Future {
28 | let p = Promise()
29 | scheduler.schedule(after: seconds) {
30 | p.fail(whenTimeout())
31 | }
32 |
33 | self.whenComplete { r in
34 | scheduler.schedule {
35 | switch r {
36 | case .success(let s):
37 | p.succeed(s)
38 | case .failure(let e):
39 | p.fail(e)
40 | }
41 | }
42 | }
43 |
44 | return p.future
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Sources/Future/Features/validate.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public func validate(_ body: @escaping (Success) -> Bool, whenFail: @autoclosure @escaping () -> Failure) -> Future {
7 |
8 | let p = Promise()
9 |
10 | self.whenComplete { r in
11 | switch r {
12 | case .success(let s):
13 | if body(s) {
14 | p.succeed(s)
15 | } else {
16 | p.fail(whenFail())
17 | }
18 | case .failure(let e):
19 | p.fail(e)
20 | }
21 | }
22 |
23 | return p.future
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Sources/Future/Features/wait.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public func wait() -> Success? {
7 | let sema = DispatchSemaphore(value: 0)
8 | self.whenComplete { _ in
9 | sema.signal()
10 | }
11 | sema.wait()
12 |
13 | return self.inspectWithoutLock()!.value
14 | }
15 |
16 | @inlinable
17 | public func waitError() -> Failure? {
18 | let sema = DispatchSemaphore(value: 0)
19 | self.whenComplete { _ in
20 | sema.signal()
21 | }
22 | sema.wait()
23 |
24 | return self.inspectWithoutLock()!.error
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Sources/Future/Features/whenAll.T.gyb:
--------------------------------------------------------------------------------
1 | /*
2 | ⚠️️️️⚠️️️️⚠️️️️
3 | This file was generated from `./whenAll.T.gyb`, you shouldn't modify it directly.
4 | ./utils/gyb.py ./Sources/Future/Features/whenAll.T.gyb -o ./Sources/Future/Features/whenAll.T.swift --line-directive ''
5 | */
6 | %{
7 | r = range(2, 8)
8 |
9 | def typeList(i):
10 | names = map(lambda x: "T%d: Thenable" % x, range(1, i + 1))
11 | return ", ".join(names)
12 |
13 | def paramList(i):
14 | names = map(lambda x: "_ thenable%d: T%d" % (x, x), range(1, i + 1))
15 | return ",\n\t\t".join(names)
16 |
17 | def whereList(i):
18 | names = map(lambda x: "T%d.Failure == T%d.Failure" % (x, x + 1), range(1, i))
19 | return ", ".join(names)
20 |
21 | def resultList(i):
22 | names = map(lambda x: "Result" % (x, x), range(1, i + 1))
23 | return ", ".join(names)
24 |
25 | def valueList(i):
26 | names = map(lambda x: "T%d.Success" % x, range(1, i + 1))
27 | return ", ".join(names)
28 |
29 | def asVoidList(i):
30 | names = map(lambda x: "thenable%d.asVoid()" % x, range(1, i + 1))
31 | return ", ".join(names)
32 |
33 | def getResultList(i):
34 | names = map(lambda x: "thenable%d.inspectRoughly()!" % x, range(1, i + 1))
35 | return ", ".join(names)
36 |
37 | def getValueList(i):
38 | names = map(lambda x: "thenable%d.inspectRoughly()!.value!" % x, range(1, i + 1))
39 | return ", ".join(names)
40 | }%
41 | import Foundation
42 |
43 | extension Thenable {
44 |
45 | % for i in r:
46 | @inlinable
47 | public static func whenAllComplete<${typeList(i)}>(
48 | ${paramList(i)}
49 | )
50 | -> Future<(${resultList(i)}), T1.Failure>
51 | where ${whereList(i)}
52 | {
53 | return self.whenAllSucceedVoid(
54 | [${asVoidList(i)}]
55 | )
56 | .map { _ in
57 | (${getResultList(i)})
58 | }
59 | }
60 |
61 | % end
62 | % for i in r:
63 | @inlinable
64 | public static func whenAllSucceed<${typeList(i)}>(
65 | ${paramList(i)}
66 | )
67 | -> Future<(${valueList(i)}), T1.Failure>
68 | where ${whereList(i)}
69 | {
70 | return self.whenAllSucceedVoid(
71 | [${asVoidList(i)}]
72 | )
73 | .map { _ in
74 | (${getValueList(i)})
75 | }
76 | }
77 |
78 | % end
79 | }
80 |
--------------------------------------------------------------------------------
/Sources/Future/Features/whenAll.T.swift:
--------------------------------------------------------------------------------
1 | /*
2 | ⚠️️️️⚠️️️️⚠️️️️
3 | This file was generated from `./whenAll.T.gyb`, you shouldn't modify it directly.
4 | ./utils/gyb.py ./Sources/FutureQ/Features/whenAll.T.gyb -o ./Sources/FutureQ/Features/whenAll.T.swift --line-directive ''
5 | */
6 | import Foundation
7 |
8 | extension Thenable {
9 |
10 | @inlinable
11 | public static func whenAllComplete(
12 | _ thenable1: T1,
13 | _ thenable2: T2
14 | )
15 | -> Future<(Result, Result), T1.Failure>
16 | where T1.Failure == T2.Failure
17 | {
18 | return self.whenAllSucceedVoid(
19 | [thenable1.asVoid(), thenable2.asVoid()]
20 | )
21 | .map { _ in
22 | (thenable1.inspectWithoutLock()!, thenable2.inspectWithoutLock()!)
23 | }
24 | }
25 |
26 | @inlinable
27 | public static func whenAllComplete(
28 | _ thenable1: T1,
29 | _ thenable2: T2,
30 | _ thenable3: T3
31 | )
32 | -> Future<(Result, Result, Result), T1.Failure>
33 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure
34 | {
35 | return self.whenAllSucceedVoid(
36 | [thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid()]
37 | )
38 | .map { _ in
39 | (thenable1.inspectWithoutLock()!, thenable2.inspectWithoutLock()!, thenable3.inspectWithoutLock()!)
40 | }
41 | }
42 |
43 | @inlinable
44 | public static func whenAllComplete(
45 | _ thenable1: T1,
46 | _ thenable2: T2,
47 | _ thenable3: T3,
48 | _ thenable4: T4
49 | )
50 | -> Future<(Result, Result, Result, Result), T1.Failure>
51 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure, T3.Failure == T4.Failure
52 | {
53 | return self.whenAllSucceedVoid(
54 | [thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid(), thenable4.asVoid()]
55 | )
56 | .map { _ in
57 | (thenable1.inspectWithoutLock()!, thenable2.inspectWithoutLock()!, thenable3.inspectWithoutLock()!, thenable4.inspectWithoutLock()!)
58 | }
59 | }
60 |
61 | @inlinable
62 | public static func whenAllComplete(
63 | _ thenable1: T1,
64 | _ thenable2: T2,
65 | _ thenable3: T3,
66 | _ thenable4: T4,
67 | _ thenable5: T5
68 | )
69 | -> Future<(Result, Result, Result, Result, Result), T1.Failure>
70 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure, T3.Failure == T4.Failure, T4.Failure == T5.Failure
71 | {
72 | return self.whenAllSucceedVoid(
73 | [thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid(), thenable4.asVoid(), thenable5.asVoid()]
74 | )
75 | .map { _ in
76 | (thenable1.inspectWithoutLock()!, thenable2.inspectWithoutLock()!, thenable3.inspectWithoutLock()!, thenable4.inspectWithoutLock()!, thenable5.inspectWithoutLock()!)
77 | }
78 | }
79 |
80 | @inlinable
81 | public static func whenAllComplete(
82 | _ thenable1: T1,
83 | _ thenable2: T2,
84 | _ thenable3: T3,
85 | _ thenable4: T4,
86 | _ thenable5: T5,
87 | _ thenable6: T6
88 | )
89 | -> Future<(Result, Result, Result, Result, Result, Result), T1.Failure>
90 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure, T3.Failure == T4.Failure, T4.Failure == T5.Failure, T5.Failure == T6.Failure
91 | {
92 | return self.whenAllSucceedVoid(
93 | [thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid(), thenable4.asVoid(), thenable5.asVoid(), thenable6.asVoid()]
94 | )
95 | .map { _ in
96 | (thenable1.inspectWithoutLock()!, thenable2.inspectWithoutLock()!, thenable3.inspectWithoutLock()!, thenable4.inspectWithoutLock()!, thenable5.inspectWithoutLock()!, thenable6.inspectWithoutLock()!)
97 | }
98 | }
99 |
100 | @inlinable
101 | public static func whenAllComplete(
102 | _ thenable1: T1,
103 | _ thenable2: T2,
104 | _ thenable3: T3,
105 | _ thenable4: T4,
106 | _ thenable5: T5,
107 | _ thenable6: T6,
108 | _ thenable7: T7
109 | )
110 | -> Future<(Result, Result, Result, Result, Result, Result, Result), T1.Failure>
111 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure, T3.Failure == T4.Failure, T4.Failure == T5.Failure, T5.Failure == T6.Failure, T6.Failure == T7.Failure
112 | {
113 | return self.whenAllSucceedVoid(
114 | [thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid(), thenable4.asVoid(), thenable5.asVoid(), thenable6.asVoid(), thenable7.asVoid()]
115 | )
116 | .map { _ in
117 | (thenable1.inspectWithoutLock()!, thenable2.inspectWithoutLock()!, thenable3.inspectWithoutLock()!, thenable4.inspectWithoutLock()!, thenable5.inspectWithoutLock()!, thenable6.inspectWithoutLock()!, thenable7.inspectWithoutLock()!)
118 | }
119 | }
120 |
121 | @inlinable
122 | public static func whenAllSucceed(
123 | _ thenable1: T1,
124 | _ thenable2: T2
125 | )
126 | -> Future<(T1.Success, T2.Success), T1.Failure>
127 | where T1.Failure == T2.Failure
128 | {
129 | return self.whenAllSucceedVoid(
130 | [thenable1.asVoid(), thenable2.asVoid()]
131 | )
132 | .map { _ in
133 | (thenable1.inspectWithoutLock()!.value!, thenable2.inspectWithoutLock()!.value!)
134 | }
135 | }
136 |
137 | @inlinable
138 | public static func whenAllSucceed(
139 | _ thenable1: T1,
140 | _ thenable2: T2,
141 | _ thenable3: T3
142 | )
143 | -> Future<(T1.Success, T2.Success, T3.Success), T1.Failure>
144 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure
145 | {
146 | return self.whenAllSucceedVoid(
147 | [thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid()]
148 | )
149 | .map { _ in
150 | (thenable1.inspectWithoutLock()!.value!, thenable2.inspectWithoutLock()!.value!, thenable3.inspectWithoutLock()!.value!)
151 | }
152 | }
153 |
154 | @inlinable
155 | public static func whenAllSucceed(
156 | _ thenable1: T1,
157 | _ thenable2: T2,
158 | _ thenable3: T3,
159 | _ thenable4: T4
160 | )
161 | -> Future<(T1.Success, T2.Success, T3.Success, T4.Success), T1.Failure>
162 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure, T3.Failure == T4.Failure
163 | {
164 | return self.whenAllSucceedVoid(
165 | [thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid(), thenable4.asVoid()]
166 | )
167 | .map { _ in
168 | (thenable1.inspectWithoutLock()!.value!, thenable2.inspectWithoutLock()!.value!, thenable3.inspectWithoutLock()!.value!, thenable4.inspectWithoutLock()!.value!)
169 | }
170 | }
171 |
172 | @inlinable
173 | public static func whenAllSucceed(
174 | _ thenable1: T1,
175 | _ thenable2: T2,
176 | _ thenable3: T3,
177 | _ thenable4: T4,
178 | _ thenable5: T5
179 | )
180 | -> Future<(T1.Success, T2.Success, T3.Success, T4.Success, T5.Success), T1.Failure>
181 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure, T3.Failure == T4.Failure, T4.Failure == T5.Failure
182 | {
183 | return self.whenAllSucceedVoid(
184 | [thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid(), thenable4.asVoid(), thenable5.asVoid()]
185 | )
186 | .map { _ in
187 | (thenable1.inspectWithoutLock()!.value!, thenable2.inspectWithoutLock()!.value!, thenable3.inspectWithoutLock()!.value!, thenable4.inspectWithoutLock()!.value!, thenable5.inspectWithoutLock()!.value!)
188 | }
189 | }
190 |
191 | @inlinable
192 | public static func whenAllSucceed(
193 | _ thenable1: T1,
194 | _ thenable2: T2,
195 | _ thenable3: T3,
196 | _ thenable4: T4,
197 | _ thenable5: T5,
198 | _ thenable6: T6
199 | )
200 | -> Future<(T1.Success, T2.Success, T3.Success, T4.Success, T5.Success, T6.Success), T1.Failure>
201 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure, T3.Failure == T4.Failure, T4.Failure == T5.Failure, T5.Failure == T6.Failure
202 | {
203 | return self.whenAllSucceedVoid(
204 | [thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid(), thenable4.asVoid(), thenable5.asVoid(), thenable6.asVoid()]
205 | )
206 | .map { _ in
207 | (thenable1.inspectWithoutLock()!.value!, thenable2.inspectWithoutLock()!.value!, thenable3.inspectWithoutLock()!.value!, thenable4.inspectWithoutLock()!.value!, thenable5.inspectWithoutLock()!.value!, thenable6.inspectWithoutLock()!.value!)
208 | }
209 | }
210 |
211 | @inlinable
212 | public static func whenAllSucceed(
213 | _ thenable1: T1,
214 | _ thenable2: T2,
215 | _ thenable3: T3,
216 | _ thenable4: T4,
217 | _ thenable5: T5,
218 | _ thenable6: T6,
219 | _ thenable7: T7
220 | )
221 | -> Future<(T1.Success, T2.Success, T3.Success, T4.Success, T5.Success, T6.Success, T7.Success), T1.Failure>
222 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure, T3.Failure == T4.Failure, T4.Failure == T5.Failure, T5.Failure == T6.Failure, T6.Failure == T7.Failure
223 | {
224 | return self.whenAllSucceedVoid(
225 | [thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid(), thenable4.asVoid(), thenable5.asVoid(), thenable6.asVoid(), thenable7.asVoid()]
226 | )
227 | .map { _ in
228 | (thenable1.inspectWithoutLock()!.value!, thenable2.inspectWithoutLock()!.value!, thenable3.inspectWithoutLock()!.value!, thenable4.inspectWithoutLock()!.value!, thenable5.inspectWithoutLock()!.value!, thenable6.inspectWithoutLock()!.value!, thenable7.inspectWithoutLock()!.value!)
229 | }
230 | }
231 |
232 | }
233 |
--------------------------------------------------------------------------------
/Sources/Future/Features/whenAll.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | extension Thenable {
4 |
5 | @inlinable
6 | public static func whenAllComplete(_ thenables: C) -> Future<[Result], C.Element.Failure> where C.Element: Thenable {
7 | let p = Promise<[Result], C.Element.Failure>()
8 |
9 | let count = Atom(thenables.count)
10 |
11 | for t in thenables {
12 | t.whenComplete { _ in
13 | if count.sub(1) == 0 {
14 | p.succeed(thenables.map({ $0.inspectWithoutLock()! }))
15 | }
16 | }
17 | }
18 |
19 | return p.future
20 | }
21 |
22 | @inlinable
23 | public static func whenAllComplete(_ thenables: T...) -> Future<[Result], T.Failure> {
24 | return self.whenAllComplete(thenables)
25 | }
26 |
27 | @inlinable
28 | public static func whenAllSucceed(_ thenables: C) -> Future<[C.Element.Success], C.Element.Failure> where C.Element: Thenable {
29 | let p = Promise<[C.Element.Success], C.Element.Failure>()
30 |
31 | let count = Atom(thenables.count)
32 |
33 | for t in thenables {
34 | t.whenComplete { r in
35 | switch r {
36 | case .success:
37 | if count.sub(1) == 0 {
38 | p.succeed(thenables.map({ $0.inspectWithoutLock()!.value! }))
39 | }
40 | case .failure(let e):
41 | p.fail(e)
42 | }
43 | }
44 | }
45 |
46 | return p.future
47 | }
48 |
49 | @inlinable
50 | public static func whenAllSucceed(_ thenables: T...) -> Future<[T.Success], T.Failure> {
51 | return self.whenAllSucceed(thenables)
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Sources/Future/Features/whenAllVoid.T.gyb:
--------------------------------------------------------------------------------
1 | /*
2 | ⚠️️️️⚠️️️️⚠️️️️
3 | This file was generated from `./whenAllVoid.T.gyb`, you shouldn't modify it directly.
4 | ./utils/gyb.py ./Sources/Future/Features/whenAllVoid.T.gyb -o ./Sources/Future/Features/whenAllVoid.T.swift --line-directive ''
5 | */
6 | %{
7 | r = range(2, 8)
8 |
9 | def typeList(i):
10 | names = map(lambda x: "T%d: Thenable" % x, range(1, i + 1))
11 | return ", ".join(names)
12 |
13 | def paramList(i):
14 | names = map(lambda x: "_ thenable%d: T%d" % (x, x), range(1, i + 1))
15 | return ",\n\t\t".join(names)
16 |
17 | def whereList(i):
18 | names = map(lambda x: "T%d.Failure == T%d.Failure" % (x, x + 1), range(1, i))
19 | return ", ".join(names)
20 |
21 | def asVoidList(i):
22 | names = map(lambda x: "thenable%d.asVoid()" % x, range(1, i + 1))
23 | return ", ".join(names)
24 | }%
25 |
26 | import Foundation
27 |
28 | extension Thenable {
29 |
30 | % for i in r:
31 | @inlinable
32 | public static func whenAllCompleteVoid<${typeList(i)}>(
33 | ${paramList(i)}
34 | )
35 | -> Future
36 | where ${whereList(i)}
37 | {
38 | return self.whenAllCompleteVoid([${asVoidList(i)}])
39 | }
40 |
41 | % end
42 | % for i in r:
43 | @inlinable
44 | public static func whenAllSucceedVoid<${typeList(i)}>(
45 | ${paramList(i)}
46 | )
47 | -> Future
48 | where ${whereList(i)}
49 | {
50 | return self.whenAllSucceedVoid([${asVoidList(i)}])
51 | }
52 |
53 | % end
54 | }
55 |
--------------------------------------------------------------------------------
/Sources/Future/Features/whenAllVoid.T.swift:
--------------------------------------------------------------------------------
1 | /*
2 | ⚠️️️️⚠️️️️⚠️️️️
3 | This file was generated from `./whenAllVoid.T.gyb`, you shouldn't modify it directly.
4 | ./utils/gyb.py ./Sources/FutureQ/Features/whenAllVoid.T.gyb -o ./Sources/FutureQ/Features/whenAllVoid.T.swift --line-directive ''
5 | */
6 |
7 | import Foundation
8 |
9 | extension Thenable {
10 |
11 | @inlinable
12 | public static func whenAllCompleteVoid(
13 | _ thenable1: T1,
14 | _ thenable2: T2
15 | )
16 | -> Future
17 | where T1.Failure == T2.Failure
18 | {
19 | return self.whenAllCompleteVoid([thenable1.asVoid(), thenable2.asVoid()])
20 | }
21 |
22 | @inlinable
23 | public static func whenAllCompleteVoid(
24 | _ thenable1: T1,
25 | _ thenable2: T2,
26 | _ thenable3: T3
27 | )
28 | -> Future
29 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure
30 | {
31 | return self.whenAllCompleteVoid([thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid()])
32 | }
33 |
34 | @inlinable
35 | public static func whenAllCompleteVoid(
36 | _ thenable1: T1,
37 | _ thenable2: T2,
38 | _ thenable3: T3,
39 | _ thenable4: T4
40 | )
41 | -> Future
42 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure, T3.Failure == T4.Failure
43 | {
44 | return self.whenAllCompleteVoid([thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid(), thenable4.asVoid()])
45 | }
46 |
47 | @inlinable
48 | public static func whenAllCompleteVoid(
49 | _ thenable1: T1,
50 | _ thenable2: T2,
51 | _ thenable3: T3,
52 | _ thenable4: T4,
53 | _ thenable5: T5
54 | )
55 | -> Future
56 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure, T3.Failure == T4.Failure, T4.Failure == T5.Failure
57 | {
58 | return self.whenAllCompleteVoid([thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid(), thenable4.asVoid(), thenable5.asVoid()])
59 | }
60 |
61 | @inlinable
62 | public static func whenAllCompleteVoid(
63 | _ thenable1: T1,
64 | _ thenable2: T2,
65 | _ thenable3: T3,
66 | _ thenable4: T4,
67 | _ thenable5: T5,
68 | _ thenable6: T6
69 | )
70 | -> Future
71 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure, T3.Failure == T4.Failure, T4.Failure == T5.Failure, T5.Failure == T6.Failure
72 | {
73 | return self.whenAllCompleteVoid([thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid(), thenable4.asVoid(), thenable5.asVoid(), thenable6.asVoid()])
74 | }
75 |
76 | @inlinable
77 | public static func whenAllCompleteVoid(
78 | _ thenable1: T1,
79 | _ thenable2: T2,
80 | _ thenable3: T3,
81 | _ thenable4: T4,
82 | _ thenable5: T5,
83 | _ thenable6: T6,
84 | _ thenable7: T7
85 | )
86 | -> Future
87 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure, T3.Failure == T4.Failure, T4.Failure == T5.Failure, T5.Failure == T6.Failure, T6.Failure == T7.Failure
88 | {
89 | return self.whenAllCompleteVoid([thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid(), thenable4.asVoid(), thenable5.asVoid(), thenable6.asVoid(), thenable7.asVoid()])
90 | }
91 |
92 | @inlinable
93 | public static func whenAllSucceedVoid(
94 | _ thenable1: T1,
95 | _ thenable2: T2
96 | )
97 | -> Future
98 | where T1.Failure == T2.Failure
99 | {
100 | return self.whenAllSucceedVoid([thenable1.asVoid(), thenable2.asVoid()])
101 | }
102 |
103 | @inlinable
104 | public static func whenAllSucceedVoid(
105 | _ thenable1: T1,
106 | _ thenable2: T2,
107 | _ thenable3: T3
108 | )
109 | -> Future
110 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure
111 | {
112 | return self.whenAllSucceedVoid([thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid()])
113 | }
114 |
115 | @inlinable
116 | public static func whenAllSucceedVoid(
117 | _ thenable1: T1,
118 | _ thenable2: T2,
119 | _ thenable3: T3,
120 | _ thenable4: T4
121 | )
122 | -> Future
123 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure, T3.Failure == T4.Failure
124 | {
125 | return self.whenAllSucceedVoid([thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid(), thenable4.asVoid()])
126 | }
127 |
128 | @inlinable
129 | public static func whenAllSucceedVoid(
130 | _ thenable1: T1,
131 | _ thenable2: T2,
132 | _ thenable3: T3,
133 | _ thenable4: T4,
134 | _ thenable5: T5
135 | )
136 | -> Future
137 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure, T3.Failure == T4.Failure, T4.Failure == T5.Failure
138 | {
139 | return self.whenAllSucceedVoid([thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid(), thenable4.asVoid(), thenable5.asVoid()])
140 | }
141 |
142 | @inlinable
143 | public static func whenAllSucceedVoid(
144 | _ thenable1: T1,
145 | _ thenable2: T2,
146 | _ thenable3: T3,
147 | _ thenable4: T4,
148 | _ thenable5: T5,
149 | _ thenable6: T6
150 | )
151 | -> Future
152 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure, T3.Failure == T4.Failure, T4.Failure == T5.Failure, T5.Failure == T6.Failure
153 | {
154 | return self.whenAllSucceedVoid([thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid(), thenable4.asVoid(), thenable5.asVoid(), thenable6.asVoid()])
155 | }
156 |
157 | @inlinable
158 | public static func whenAllSucceedVoid(
159 | _ thenable1: T1,
160 | _ thenable2: T2,
161 | _ thenable3: T3,
162 | _ thenable4: T4,
163 | _ thenable5: T5,
164 | _ thenable6: T6,
165 | _ thenable7: T7
166 | )
167 | -> Future
168 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure, T3.Failure == T4.Failure, T4.Failure == T5.Failure, T5.Failure == T6.Failure, T6.Failure == T7.Failure
169 | {
170 | return self.whenAllSucceedVoid([thenable1.asVoid(), thenable2.asVoid(), thenable3.asVoid(), thenable4.asVoid(), thenable5.asVoid(), thenable6.asVoid(), thenable7.asVoid()])
171 | }
172 |
173 | }
174 |
--------------------------------------------------------------------------------
/Sources/Future/Features/whenAllVoid.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | // For performance
4 |
5 | extension Thenable {
6 |
7 | @inlinable
8 | public static func whenAllCompleteVoid(_ thenables: C) -> Future where C.Element: Thenable {
9 | let p = Promise()
10 |
11 | let count = Atom(thenables.count)
12 |
13 | for t in thenables {
14 | t.whenComplete { _ in
15 | if count.sub(1) == 0 {
16 | p.succeed(())
17 | }
18 | }
19 | }
20 |
21 | return p.future
22 | }
23 |
24 | @inlinable
25 | public static func whenAllCompleteVoid(_ thenables: T...) -> Future {
26 | return self.whenAllCompleteVoid(thenables)
27 | }
28 |
29 | @inlinable
30 | public static func whenAllSucceedVoid(_ thenables: C) -> Future where C.Element: Thenable {
31 | let p = Promise()
32 |
33 | let count = Atom(thenables.count)
34 |
35 | for t in thenables {
36 | t.whenComplete { r in
37 | switch r {
38 | case .success:
39 | if count.sub(1) == 0 {
40 | p.succeed(())
41 | }
42 | case .failure(let e):
43 | p.fail(e)
44 | }
45 | }
46 | }
47 |
48 | return p.future
49 | }
50 |
51 | @inlinable
52 | public static func whenAllSucceedVoid(_ thenables: T...) -> Future {
53 | return self.whenAllSucceedVoid(thenables)
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/Sources/Future/Features/whenAny.T.gyb:
--------------------------------------------------------------------------------
1 | /*
2 | ⚠️️️️⚠️️️️⚠️️️️
3 | This file was generated from `./whenAny.T.gyb`, you shouldn't modify it directly.
4 | ./utils/gyb.py ./Sources/Future/Features/whenAny.T.gyb -o ./Sources/Future/Features/whenAny.T.swift --line-directive ''
5 | */
6 | %{
7 | r = range(2, 8)
8 |
9 | def typeList(i):
10 | names = map(lambda x: "T%d: Thenable" % x, range(1, i + 1))
11 | return ", ".join(names)
12 |
13 | def paramList(i):
14 | names = map(lambda x: "_ thenable%d: T%d" % (x, x), range(1, i + 1))
15 | return ",\n\t\t".join(names)
16 |
17 | def whereList(i):
18 | names = map(lambda x: "T%d.Failure == T%d.Failure" % (x, x + 1), range(1, i))
19 | return ", ".join(names)
20 |
21 | def asAnyList(i):
22 | names = map(lambda x: "thenable%d.asAny()" % x, range(1, i + 1))
23 | return ", ".join(names)
24 | }%
25 |
26 | import Foundation
27 |
28 | extension Thenable {
29 |
30 | % for i in r:
31 | @inlinable
32 | public static func whenAnyComplete<${typeList(i)}>(
33 | ${paramList(i)}
34 | )
35 | -> Future
36 | where ${whereList(i)}
37 | {
38 | return self.whenAnyComplete([${asAnyList(i)}])
39 | }
40 |
41 | % end
42 | % for i in r:
43 | @inlinable
44 | public static func whenAnySucceed<${typeList(i)}>(
45 | ${paramList(i)}
46 | )
47 | -> Future
48 | where ${whereList(i)}
49 | {
50 | return self.whenAnySucceed([${asAnyList(i)}])
51 | }
52 |
53 | % end
54 | }
55 |
--------------------------------------------------------------------------------
/Sources/Future/Features/whenAny.T.swift:
--------------------------------------------------------------------------------
1 | /*
2 | ⚠️️️️⚠️️️️⚠️️️️
3 | This file was generated from `./whenAny.T.gyb`, you shouldn't modify it directly.
4 | ./utils/gyb.py ./Sources/FutureQ/Features/whenAny.T.gyb -o ./Sources/FutureQ/Features/whenAny.T.swift --line-directive ''
5 | */
6 |
7 | import Foundation
8 |
9 | extension Thenable {
10 |
11 | @inlinable
12 | public static func whenAnyComplete(
13 | _ thenable1: T1,
14 | _ thenable2: T2
15 | )
16 | -> Future
17 | where T1.Failure == T2.Failure
18 | {
19 | return self.whenAnyComplete([thenable1.asAny(), thenable2.asAny()])
20 | }
21 |
22 | @inlinable
23 | public static func whenAnyComplete(
24 | _ thenable1: T1,
25 | _ thenable2: T2,
26 | _ thenable3: T3
27 | )
28 | -> Future
29 | where T1.Failure == T2.Failure, T2.Failure == T3.Failure
30 | {
31 | return self.whenAnyComplete([thenable1.asAny(), thenable2.asAny(), thenable3.asAny()])
32 | }
33 |
34 | @inlinable
35 | public static func whenAnyComplete