Skip to content

Commit

Permalink
Example: RxSwift.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachgrayio committed Apr 29, 2018
1 parent 13229e4 commit cde51c2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")

This comment has been minimized.

Copy link
@zachgrayio

zachgrayio Apr 29, 2018

Author Owner

Add the remote package

],
targets: [
.target(
name: "STSLibrary",
dependencies: []),
dependencies: ["RxSwift"]),

This comment has been minimized.

Copy link
@zachgrayio

zachgrayio Apr 29, 2018

Author Owner

Specify dependency on the RxSwift package

.target(
name: "STSApplication",
dependencies: ["STSLibrary"]),
Expand Down
2 changes: 2 additions & 0 deletions Sources/STSLibrary/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ public final class Application {

public func run() throws {
print("\(prefix): \(TensorFlowExample.multiplyTensor())")
print("\(prefix): Running RxExample:")
RxExample.printHello()
}
}
19 changes: 19 additions & 0 deletions Sources/STSLibrary/RxExample.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

import RxSwift

This comment has been minimized.

Copy link
@zachgrayio

zachgrayio Apr 29, 2018

Author Owner

import RxSwift as needed

import Foundation

struct RxExample {
static func printHello() {
let wordList = ["Hello", "Rx", "World"]

_ = Observable<Int>.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))
}
}

0 comments on commit cde51c2

Please sign in to comment.