-
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
0549f70
commit 8f039da
Showing
15 changed files
with
1,000 additions
and
2 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
## [Point-Free](https://www.pointfree.co) | ||
|
||
> #### This directory contains code from Point-Free Episode: [Tour of Concurrency's Past: Threads](https://www.pointfree.co/episodes/ep190-concurrency-s-past-threads) | ||
> #### This directory contains code from Point-Free Episode: [Concurrency's Past: Threads](https://www.pointfree.co/episodes/ep190-concurrency-s-past-threads) | ||
> | ||
> To better understand Swift’s concurrency tools, let’s first look to the past, starting with threads. Threads are a tool most developers don’t reach for these days, but are important to understand, and the way they solve problems reverberate even in today’s tools. |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
## [Point-Free](https://www.pointfree.co) | ||
|
||
> #### This directory contains code from Point-Free Episode: [Tour of Concurrency's Past: Queues and Combine](https://www.pointfree.co/episodes/ep191-concurrency-s-present-queues-and-combine) | ||
> #### This directory contains code from Point-Free Episode: [Concurrency's Past: Queues and Combine](https://www.pointfree.co/episodes/ep191-concurrency-s-present-queues-and-combine) | ||
> | ||
> Before developing Swift’s modern concurrency tools, Apple improved upon threads with several other abstractions, including operation queues, Grand Central Dispatch, and Combine. Let’s see what these newer tools brought to the table. |
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
0192-concurrency-pt3/.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,5 @@ | ||
## [Point-Free](https://www.pointfree.co) | ||
|
||
> #### This directory contains code from Point-Free Episode: [Concurrency's Future: Tasks and Cooperation](https://www.pointfree.co/episodes/ep192-concurrency-s-future-tasks-and-cooperation) | ||
> | ||
> Let’s look at what the future of concurrency looks like in Swift. A recent release of Swift came with a variety of tools with concurrency. Let’s examine its fundamental unit in depth, and explore how they “cooperate” in your applications. |
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
0192-concurrency-pt3/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,19 @@ | ||
// 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: []), | ||
.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
0192-concurrency-pt3/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.