Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(SyncStream): add method makeStream(of:) #1

Merged
merged 1 commit into from
Apr 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Sources/SyncStream/SyncStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ public class SyncStream<Element>: Sequence, IteratorProtocol {

// MARK: Public

/// Constructs an synchronous stream from the Element Type
/// - Parameter type: The Element Type
///
/// - Returns: A tuple containing the stream and its continuation. The continuation
/// should be passed to the producer while the stream should be passed to the consumer.
public static func makeStream(
of _: Element.Type = Element.self
) -> (stream: SyncStream<Element>, continuation: SyncStream<Element>.Continuation) {
let stream = SyncStream<Element> { _ in }
let continuation = stream.continuation
return (stream, continuation)
}

public func next() -> Element? {
if finished {
return nil
Expand Down