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

Created interfaces with documentation #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output

# Mac Specific
.DS_Store
1 change: 1 addition & 0 deletions CopyrightWaivers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ Underwriting parties:

github name | Real Name, Email Address used for git commits, Company
---------------+----------------------------------------------------------------------------
00benallen Ben Pinhorn, [email protected] Independant
8 changes: 8 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"object": {
"pins": [

]
},
"version": 1
}
28 changes: 28 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "reactive-streams-swift",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "reactive-streams-swift",
targets: ["reactive-streams-swift"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "reactive-streams-swift",
dependencies: []),
.testTarget(
name: "reactive-streams-swiftTests",
dependencies: ["reactive-streams-swift"]),
]
)
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
# Reactive Streams #

The purpose of Reactive Streams is to provide a standard for asynchronous stream processing with non-blocking backpressure.
# Reactive Streams Swift

The purpose of Reactive Streams is to provide a standard for asynchronous stream processing with non-blocking backpressure.

The latest release will always be the master branch on this repo (use SPM to integrate, it pulls from github as a repository source).

To install:

1. Add reactive-streams-swift to your Package.swift:
```
Swift 3: .Package(url: "https://github.com/reactive-streams/reactive-streams-swift.git", majorVersion: 1)

Swift 4: .package(url: "https://github.com/reactive-streams/reactive-streams-swift.git", from: "1.0.0")
```

2. For Swift 4 you also need to add reactive-streams-swift to your target's dependencies.

```
.target(name: "MyTarget", dependencies: ["reactive-streams-swift"])

```

3. After a `swift package update`, you can now use reactive-streams-swift:

4. Extend the given interfaces to create your own Reactive Streams components, use the tck to test that you're in compliance (when its ready).

## Goals, Design and Scope ##

Expand Down
25 changes: 25 additions & 0 deletions Sources/reactive-streams-swift/Interfaces/Processor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/************************************************************************
* Licensed under Public Domain (CC0) *
* *
* To the extent possible under law, the person who associated CC0 with *
* this code has waived all copyright and related or neighboring *
* rights to this code. *
* *
* You should have received a copy of the CC0 legalcode along with this *
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.*
************************************************************************/

/**
Processor.swift
reactive-streams-swift

Created by Ben Pinhorn on 2018-09-01.

A Processor represents a processing stage—which is both a Subscriber
and a Publisher and obeys the contracts of both.

*/

import Foundation

public protocol Processor: Subscriber, Publisher {}
42 changes: 42 additions & 0 deletions Sources/reactive-streams-swift/Interfaces/Publisher.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/************************************************************************
* Licensed under Public Domain (CC0) *
* *
* To the extent possible under law, the person who associated CC0 with *
* this code has waived all copyright and related or neighboring *
* rights to this code. *
* *
* You should have received a copy of the CC0 legalcode along with this *
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.*
************************************************************************/

/**
Publisher.swift
reactive-streams-swift

Created by Ben Pinhorn on 2018-09-01.

A Publisher is a provider of a potentially unbounded number of sequenced elements, publishing them according to
the demand received from its Subscriber(s).

A Publisher can serve multiple Subscribers subscribed dynamically
at various points in time.


*/

import Foundation

public protocol Publisher {

/**

Subscribe a Subscriber to this Publisher, to receive elements from it

Request elements using the Subscription given back by the Publisher using onSubscribe(), by calling Subscription.request(num of elements)

- parameter subscriber: The subscriber which will receive the elements given by the Publisher

*/
func subscribe(subscriber: Subscriber)

}
69 changes: 69 additions & 0 deletions Sources/reactive-streams-swift/Interfaces/Subscriber.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/************************************************************************
* Licensed under Public Domain (CC0) *
* *
* To the extent possible under law, the person who associated CC0 with *
* this code has waived all copyright and related or neighboring *
* rights to this code. *
* *
* You should have received a copy of the CC0 legalcode along with this *
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.*
************************************************************************/

/**
Subscriber.swift
reactive-streams-swift

Created by Ben Pinhorn on 2018-09-01.

Will receive call to onSubscribe() once after passing an instance of Subscriber to Publisher.subscribe().

No further notifications will be received until Subscription.request() is called.

After signaling demand:

1. One or more invocations of Subscriber.onNext(element) up to the maximum number defined by Subscription.request(n)
2. Single invocation of Subscriber.onError(error) or Subscriber.onComplete() which signals a terminal state after which no further events will be sent.
3. Demand can be signaled via Subscription.request(n) whenever the Subscriber instance is capable of handling more.

*/

import Foundation

public protocol Subscriber {

/**

Function which receives the signal that the Publisher has received the .subscribe() signal, and has created a Subscription
for the Subscriber to use to request elements.

- parameter subscription: the subscription created by the Publisher

*/
func onSubscribe(subscription: Subscription) -> Void

/**

Function which receives the next element requested using the Subscription. Only to be called by the subscribed Publisher.

- parameter next: the next element published by the Publisher

*/
func onNext(next: Any) -> Void

/**

Function which receives the signal that the Publisher encountered an unrecoverable error. The Subscriber should receive no more elements after this is called, as it signals a terminal state.

- parameter error: the error the Publisher encountered

*/
func onError(error: Error) -> Void

/**

Function which receives the signal that the Publisher has published all of the requested elements. The Subscriber should receive no more elements after this is called, as it signals a terminal state.

*/
func onComplete() -> Void

}
49 changes: 49 additions & 0 deletions Sources/reactive-streams-swift/Interfaces/Subscription.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/************************************************************************
* Licensed under Public Domain (CC0) *
* *
* To the extent possible under law, the person who associated CC0 with *
* this code has waived all copyright and related or neighboring *
* rights to this code. *
* *
* You should have received a copy of the CC0 legalcode along with this *
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.*
************************************************************************/

/**
Subscription.swift
reactive-streams-swift

Created by Ben Pinhorn on 2018-09-01.

A Subscription represents a one-to-one lifecycle of a Subscriber subscribing to a Publisher.
It can only be used once by a single Subscriber.
It is used to both signal desire for data and cancel demand (and allow resource cleanup).

*/

import Foundation

public protocol Subscription {

/**

This function is used by the Subscriber to signal a request for elements from the Publisher. This function is additive, meaning if you do:

1. .request(1)
then
2. .request(3)
You will eventually receive 4 elements from the Publisher.

- parameter requested: The number of elements the Subscriber is ready for next

*/
func request(requested: CLong) -> Void

/**

This function is used by the Subscriber to signal that it wants no more elements from the Publisher. More elements may still come, but the Publisher should stop as soon as possible once this signal is called.

*/
func cancel() -> Void

}
7 changes: 7 additions & 0 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import XCTest

import reactive_streams_swift_frameworkTests

var tests = [XCTestCaseEntry]()
tests += reactive_streams_swift_frameworkTests.allTests()
XCTMain(tests)
9 changes: 9 additions & 0 deletions Tests/reactive-streams-swiftTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import XCTest

#if !os(macOS)
public func allTests() -> [XCTestCaseEntry] {
return [
testCase(reactive_streams_swift_frameworkTests.allTests),
]
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import XCTest
@testable import reactive_streams_swift

final class reactive_streams_swift_frameworkTests: XCTestCase {

func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
}


static var allTests = [
("testExample", testExample),
]
}
Loading