-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from jurvis/regtest_monitor_tooling
Add blockchain monitor publisher to reconcile chain tips
- Loading branch information
Showing
3 changed files
with
48 additions
and
1 deletion.
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
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
31 changes: 31 additions & 0 deletions
31
xcode/DirectBindingsApp/DirectBindingsApp/app-batteries/CombineUtils.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,31 @@ | ||
// | ||
// CombineUtils.swift | ||
// DirectBindingsApp | ||
// | ||
// From https://www.swiftbysundell.com/articles/async-and-concurrent-forEach-and-map/ | ||
// | ||
// Created by Jurvis Tan on 4/18/22. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
extension Publisher { | ||
func asyncMap<T>( | ||
_ transform: @escaping (Output) async throws -> T | ||
) -> Publishers.FlatMap<Future<T, Error>, | ||
Publishers.SetFailureType<Self, Error>> { | ||
flatMap { value in | ||
Future { promise in | ||
Task { | ||
do { | ||
let output = try await transform(value) | ||
promise(.success(output)) | ||
} catch { | ||
promise(.failure(error)) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |