-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c16d27
commit d71ba44
Showing
14 changed files
with
1,127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## [Point-Free](https://www.pointfree.co) | ||
|
||
> #### This directory contains code from Point-Free Episode: [Concurrency's Future: Structured and Unstructured](https://www.pointfree.co/episodes/ep194-concurrency-s-future-structured-and-unstructured) | ||
> | ||
> There are amazing features of Swift concurrency that don’t quite fit into our narrative of examining it through the lens of past concurrency tools. Instead, we’ll examine them through the lens of a past programming paradigm, structured programming, and see what is has to say about structured concurrency. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/config/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
102 changes: 102 additions & 0 deletions
102
0194-concurrency-pt5/concurrency/.swiftpm/xcode/xcshareddata/xcschemes/concurrency.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1340" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "concurrency" | ||
BuildableName = "concurrency" | ||
BlueprintName = "concurrency" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "NO" | ||
buildForArchiving = "NO" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "concurrencyTests" | ||
BuildableName = "concurrencyTests" | ||
BlueprintName = "concurrencyTests" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES"> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "concurrencyTests" | ||
BuildableName = "concurrencyTests" | ||
BlueprintName = "concurrencyTests" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Release" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "concurrency" | ||
BuildableName = "concurrency" | ||
BlueprintName = "concurrency" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "concurrency" | ||
BuildableName = "concurrency" | ||
BlueprintName = "concurrency" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// swift-tools-version: 5.6 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "concurrency", | ||
platforms: [.macOS(.v12)], | ||
dependencies: [ | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "concurrency", | ||
dependencies: [], | ||
swiftSettings: [ | ||
.unsafeFlags([ | ||
"-Xfrontend", "-warn-concurrency", | ||
]), | ||
] | ||
), | ||
.testTarget( | ||
name: "concurrencyTests", | ||
dependencies: ["concurrency"]), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# concurrency | ||
|
||
A description of this package. |
104 changes: 104 additions & 0 deletions
104
0194-concurrency-pt5/concurrency/Sources/concurrency/Combine.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import Combine | ||
import Foundation | ||
|
||
let publisher1 = Deferred { | ||
Future<Int, Never> { callback in | ||
print(Thread.current) | ||
callback(.success(42)) | ||
} | ||
} | ||
.subscribe(on: DispatchQueue(label: "queue1")) | ||
|
||
let publisher2 = Deferred { | ||
Future<String, Never> { callback in | ||
print(Thread.current) | ||
callback(.success("Hello world")) | ||
} | ||
} | ||
.subscribe(on: DispatchQueue(label: "queue2")) | ||
|
||
let cancellable = publisher1 | ||
.flatMap { integer in | ||
Deferred { | ||
Future<String, Never> { callback in | ||
print(Thread.current) | ||
callback(.success("\(integer)")) | ||
} | ||
} | ||
.subscribe(on: DispatchQueue(label: "queue3")) | ||
} | ||
.zip(publisher2) | ||
.sink { | ||
print("sink", $0, Thread.current) | ||
} | ||
|
||
//_ = cancellable | ||
|
||
|
||
func operationQueueCoordination() { | ||
let queue = OperationQueue() | ||
|
||
let operationA = BlockOperation { | ||
print("A") | ||
Thread.sleep(forTimeInterval: 1) | ||
} | ||
let operationB = BlockOperation { | ||
print("B") | ||
} | ||
let operationC = BlockOperation { | ||
print("C") | ||
} | ||
let operationD = BlockOperation { | ||
print("D") | ||
} | ||
operationB.addDependency(operationA) | ||
operationC.addDependency(operationA) | ||
operationD.addDependency(operationB) | ||
operationD.addDependency(operationC) | ||
queue.addOperation(operationA) | ||
queue.addOperation(operationB) | ||
queue.addOperation(operationC) | ||
queue.addOperation(operationD) | ||
|
||
operationA.cancel() | ||
|
||
/* | ||
A ➡️ B | ||
⬇️ ⬇️ | ||
C ➡️ D | ||
*/ | ||
} | ||
|
||
//a | ||
// .handleEvents(...) | ||
// .compactMap { $0 } | ||
// .flatMap { a in zip(b(a), c(a)) } | ||
// .flatMap { b, c in d(b, c) } | ||
// .handleEvents(receiveCompletion: { _ in print("Finished") }) | ||
|
||
// defer { print("Finished") } | ||
// guard let a = await f() | ||
// else { return } | ||
// async let b = g(a) | ||
// async let c = h(a) | ||
// let d = await i(b, c) | ||
|
||
|
||
func dispatchDiamondDependency() { | ||
let queue = DispatchQueue(label: "queue", attributes: .concurrent) | ||
queue.async { | ||
print("A") | ||
|
||
let group = DispatchGroup() | ||
queue.async(group: group) { | ||
print("B") | ||
} | ||
queue.async(group: group) { | ||
print("C") | ||
} | ||
|
||
group.notify(queue: queue) { | ||
print("D") | ||
} | ||
} | ||
} |
Oops, something went wrong.