Skip to content

Commit d80dfae

Browse files
restore package.scala files (mainly for scaladoc)
1 parent 765d27c commit d80dfae

File tree

5 files changed

+281
-0
lines changed

5 files changed

+281
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright 2013 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package rx.lang.scala
17+
18+
import rx.concurrency.CurrentThreadScheduler
19+
20+
/**
21+
* Provides schedulers.
22+
*/
23+
package object concurrency {
24+
25+
// These classes are not exposed to Scala users, but are accessible through rx.lang.scala.concurrency.Schedulers:
26+
27+
// rx.concurrency.CurrentThreadScheduler
28+
// rx.concurrency.ExecutorScheduler
29+
// rx.concurrency.ImmediateScheduler
30+
// rx.concurrency.NewThreadScheduler
31+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package rx.lang.scala
2+
3+
/**
4+
* Contains special Observables.
5+
*
6+
* In Scala, this package only contains [[BlockingObservable]].
7+
* In the corresponding Java package `rx.observables`, there is also a
8+
* `GroupedObservable` and a `ConnectableObservable`, but these are not needed
9+
* in Scala, because we use a pair `(key, observable)` instead of `GroupedObservable`
10+
* and a pair `(startFunction, observable)` instead of `ConnectableObservable`.
11+
*/
12+
package object observables {}
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/**
2+
* Copyright 2013 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package rx.lang
17+
18+
import java.util.concurrent.TimeUnit
19+
import java.util.Date
20+
21+
/*
22+
* Note that:
23+
* - Scala users cannot use Java's types with variance without always using writing
24+
* e.g. rx.Notification[_ <: T], so we create aliases fixing the variance
25+
* - For consistency, we create aliases for all types which Scala users need
26+
*/
27+
28+
/**
29+
* This package contains all classes that RxScala users need.
30+
*
31+
* It mirrors the structure of package `rx`, but implementation classes that RxScala users
32+
* will not need are left out.
33+
*/
34+
package object scala {
35+
36+
/*
37+
* Here we're imitating C's preprocessor using Search & Replace.
38+
*
39+
* To activate the code needed to get nice Scaladoc, do the following replacements:
40+
* /*//#ifdef SCALADOC --> //#ifdef SCALADOC
41+
* *///#else --> /*//#else
42+
* //#endif --> *///#endif
43+
*
44+
* To get back to the actual code, undo the above replacements.
45+
*
46+
*/
47+
48+
/*//#ifdef SCALADOC
49+
50+
/**
51+
* Provides a mechanism for receiving push-based notifications.
52+
*
53+
* After an Observer calls an [[Observable]]'s `subscribe` method, the Observable
54+
* calls the Observer's `onNext` method to provide notifications. A well-behaved Observable will
55+
* call an Observer's `onCompleted` method exactly once or the Observer's `onError` method exactly once.
56+
*/
57+
trait Observer[-T] {
58+
59+
/**
60+
* Notifies the Observer that the [[Observable]] has finished sending push-based notifications.
61+
*
62+
* The [[Observable]] will not call this method if it calls `onError`.
63+
*/
64+
def onCompleted(): Unit
65+
66+
/**
67+
* Notifies the Observer that the [[Observable]] has experienced an error condition.
68+
*
69+
* If the [[Observable]] calls this method, it will not thereafter call `onNext` or `onCompleted`.
70+
*/
71+
def onError(e: Throwable): Unit
72+
73+
/**
74+
* Provides the Observer with new data.
75+
*
76+
* The [[Observable]] calls this closure 0 or more times.
77+
*
78+
* The [[Observable]] will not call this method again after it calls either `onCompleted` or `onError`.
79+
*/
80+
def onNext(arg: T): Unit
81+
}
82+
83+
/**
84+
* Subscriptions are returned from all `Observable.subscribe` methods to allow unsubscribing.
85+
*
86+
* This interface is the equivalent of `IDisposable` in the .NET Rx implementation.
87+
*/
88+
trait Subscription {
89+
/**
90+
* Call this method to stop receiving notifications on the Observer that was registered when
91+
* this Subscription was received.
92+
*/
93+
def unsubscribe(): Unit
94+
}
95+
96+
import language.implicitConversions
97+
98+
private[scala] implicit def fakeSubscription2RxSubscription(s: Subscription): rx.Subscription =
99+
new rx.Subscription {
100+
def unsubscribe() = s.unsubscribe()
101+
}
102+
private[scala] implicit def rxSubscription2FakeSubscription(s: rx.Subscription): Subscription =
103+
new Subscription {
104+
def unsubscribe() = s.unsubscribe()
105+
}
106+
107+
private[scala] implicit def schedulerActionToFunc2[T](action: (Scheduler, T) => Subscription) =
108+
new rx.util.functions.Func2[rx.Scheduler, T, rx.Subscription] {
109+
def call(s: rx.Scheduler, t: T): rx.Subscription = {
110+
action(ImplicitFunctionConversions.javaSchedulerToScalaScheduler(s), t)
111+
}
112+
}
113+
114+
private[scala] implicit def fakeObserver2RxObserver[T](o: Observer[T]): rx.Observer[_ >: T] = ???
115+
private[scala] implicit def rxObserver2fakeObserver[T](o: rx.Observer[_ >: T]): Observer[T] = ???
116+
117+
*///#else
118+
119+
type Observer[-T] = rx.Observer[_ >: T]
120+
121+
type Subscription = rx.Subscription
122+
123+
//#endif
124+
125+
/**
126+
* Allows to construct observables in a similar way as futures.
127+
*
128+
* Example:
129+
*
130+
* {{{
131+
* implicit val scheduler = Schedulers.threadPoolForIO
132+
* val o: Observable[List[Friend]] = observable {
133+
* session.getFriends
134+
* }
135+
* o.subscribe(
136+
* friendList => println(friendList),
137+
* err => println(err.getMessage)
138+
* )
139+
* }}}
140+
*/
141+
def observable[T](body: => T)(implicit scheduler: Scheduler): Observable[T] = {
142+
Observable(1).observeOn(scheduler).map(_ => body)
143+
}
144+
}
145+
146+
/*
147+
148+
These classes are considered unnecessary for Scala users, so we don't create aliases for them:
149+
150+
rx.plugins.RxJavaErrorHandler
151+
rx.plugins.RxJavaObservableExecutionHook
152+
rx.plugins.RxJavaPlugins
153+
154+
rx.subscriptions.BooleanSubscription
155+
rx.subscriptions.CompositeSubscription
156+
rx.subscriptions.Subscriptions
157+
158+
*/
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package rx.lang.scala
2+
3+
/**
4+
* Provides the type `Subject`.
5+
*/
6+
package object subjects {
7+
8+
/**
9+
* A Subject is an Observable and an Observer at the same time.
10+
*
11+
* The Java Subject looks like this:
12+
* {{{
13+
* public abstract class Subject<T,R> extends Observable<R> implements Observer<T>
14+
* }}}
15+
*/
16+
type Subject[-T, +R] = rx.subjects.Subject[_ >: T, _ <: R]
17+
18+
// For nicer scaladoc, we would like to present something like this:
19+
/*
20+
trait Observable[+R] {}
21+
trait Observer[-T] {}
22+
trait Subject[-T, +R] extends Observable[R] with Observer[T] { }
23+
*/
24+
25+
// We don't make aliases to these types, because they are considered internal/not needed by users:
26+
// rx.subjects.AsyncSubject
27+
// rx.subjects.BehaviorSubject
28+
// rx.subjects.PublishSubject
29+
// rx.subjects.ReplaySubject
30+
31+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright 2013 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package rx.lang.scala
17+
18+
/**
19+
* Provides [[Opening]]s, [[Closing]]s, and [[Timestamped]].
20+
*/
21+
package object util {
22+
23+
/**
24+
* Tagging interface for objects which can open buffers.
25+
* @see [[Observable `Observable.buffer(Observable[Opening], Opening => Observable[Closing])`]]
26+
*/
27+
type Opening = rx.util.Opening
28+
29+
/**
30+
* Creates an object which can open buffers.
31+
* @see [[Observable `Observable.buffer(Observable[Opening], Opening => Observable[Closing])`]]
32+
*/
33+
def Opening() = rx.util.Openings.create()
34+
35+
/**
36+
* Tagging interface for objects which can close buffers.
37+
* @see [[Observable `Observable.buffer(Observable[Opening], Opening => Observable[Closing])`]]
38+
*/
39+
type Closing = rx.util.Closing
40+
41+
/**
42+
* Creates an object which can close buffers.
43+
* @see [[Observable `Observable.buffer(Observable[Opening], Opening => Observable[Closing])`]]
44+
*/
45+
def Closing() = rx.util.Closings.create()
46+
47+
// rx.util.Range not needed because there's a standard Scala Range
48+
49+
}

0 commit comments

Comments
 (0)