From cde51c28c608d9e08f460944eae836881fef47d9 Mon Sep 17 00:00:00 2001 From: Zach Gray Date: Sun, 29 Apr 2018 16:09:26 -0700 Subject: [PATCH] Example: RxSwift. --- Package.swift | 5 ++--- Sources/STSLibrary/Application.swift | 2 ++ Sources/STSLibrary/RxExample.swift | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 Sources/STSLibrary/RxExample.swift diff --git a/Package.swift b/Package.swift index 5be58c1..1b26643 100644 --- a/Package.swift +++ b/Package.swift @@ -12,13 +12,12 @@ let package = Package( ) ], dependencies: [ - //example: - // .package(url: "https://github.com/ReactiveX/RxSwift.git", "4.0.0" ..< "5.0.0") + .package(url: "https://github.com/ReactiveX/RxSwift.git", "4.0.0" ..< "5.0.0") ], targets: [ .target( name: "STSLibrary", - dependencies: []), + dependencies: ["RxSwift"]), .target( name: "STSApplication", dependencies: ["STSLibrary"]), diff --git a/Sources/STSLibrary/Application.swift b/Sources/STSLibrary/Application.swift index aec45b7..2661231 100644 --- a/Sources/STSLibrary/Application.swift +++ b/Sources/STSLibrary/Application.swift @@ -7,5 +7,7 @@ public final class Application { public func run() throws { print("\(prefix): \(TensorFlowExample.multiplyTensor())") + print("\(prefix): Running RxExample:") + RxExample.printHello() } } \ No newline at end of file diff --git a/Sources/STSLibrary/RxExample.swift b/Sources/STSLibrary/RxExample.swift new file mode 100644 index 0000000..421aece --- /dev/null +++ b/Sources/STSLibrary/RxExample.swift @@ -0,0 +1,19 @@ + +import RxSwift +import Foundation + +struct RxExample { + static func printHello() { + let wordList = ["Hello", "Rx", "World"] + + _ = Observable.interval(1, scheduler: SerialDispatchQueueScheduler(qos: .default)) + .take(wordList.count) + .map { index in wordList[index]} + .do(onNext: { word in + print(word) + }) + + // sleep for the duration of the above so the application doesn't exit before completion + Thread.sleep(forTimeInterval: Double(wordList.count)) + } +}