Skip to content

Commit

Permalink
feat(SyncStream): add method makeStream(of:) (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
rockmagma02 authored Apr 21, 2024
1 parent 6c9ceed commit b58306c
Showing 1 changed file with 13 additions and 0 deletions.
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

0 comments on commit b58306c

Please sign in to comment.