-
Notifications
You must be signed in to change notification settings - Fork 199
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
Showing
4 changed files
with
88 additions
and
113 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
43 changes: 43 additions & 0 deletions
43
...nitoAuthPlugin/StateMachine/hierarchical-state-machine-swift/CancellableAsyncStream.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,43 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Combine | ||
|
||
class CancellableAsyncStream<Element>: AsyncSequence { | ||
|
||
typealias AsyncIterator = AsyncStream<Element>.AsyncIterator | ||
private let asyncStream: AsyncStream<Element> | ||
private let cancellable: AnyCancellable? | ||
|
||
deinit { | ||
cancel() | ||
} | ||
|
||
init(asyncStream: AsyncStream<Element>, cancellable: AnyCancellable?) { | ||
self.asyncStream = asyncStream | ||
self.cancellable = cancellable | ||
} | ||
|
||
convenience init(with publisher: AnyPublisher<Element, Never>) { | ||
var cancellable: AnyCancellable? | ||
self.init(asyncStream: AsyncStream { continuation in | ||
cancellable = publisher.sink { _ in | ||
continuation.finish() | ||
} receiveValue: { | ||
continuation.yield($0) | ||
} | ||
}, cancellable: cancellable) | ||
} | ||
|
||
func makeAsyncIterator() -> AsyncStream<Element>.AsyncIterator { | ||
asyncStream.makeAsyncIterator() | ||
} | ||
|
||
func cancel() { | ||
cancellable?.cancel() | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
...SCognitoAuthPlugin/StateMachine/hierarchical-state-machine-swift/StateAsyncSequence.swift
This file was deleted.
Oops, something went wrong.
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