diff --git a/rxjava-contrib/rxjava-async-util/build.gradle b/rxjava-contrib/rxjava-async-util/build.gradle
new file mode 100644
index 0000000000..09d9aae655
--- /dev/null
+++ b/rxjava-contrib/rxjava-async-util/build.gradle
@@ -0,0 +1,20 @@
+apply plugin: 'osgi'
+
+sourceCompatibility = JavaVersion.VERSION_1_6
+targetCompatibility = JavaVersion.VERSION_1_6
+
+dependencies {
+ compile project(':rxjava-core')
+ testCompile project(":rxjava-core").sourceSets.test.output
+ provided 'junit:junit-dep:4.10'
+ provided 'org.mockito:mockito-core:1.8.5'
+}
+
+jar {
+ manifest {
+ name = 'rxjava-async-util'
+ instruction 'Bundle-Vendor', 'Netflix'
+ instruction 'Bundle-DocURL', 'https://github.com/Netflix/RxJava'
+ instruction 'Import-Package', '!org.junit,!junit.framework,!org.mockito.*,*'
+ }
+}
diff --git a/rxjava-core/src/main/java/rx/util/functions/Async.java b/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/Async.java
similarity index 75%
rename from rxjava-core/src/main/java/rx/util/functions/Async.java
rename to rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/Async.java
index 51a1787715..5505d9a91e 100644
--- a/rxjava-core/src/main/java/rx/util/functions/Async.java
+++ b/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/Async.java
@@ -1,374 +1,482 @@
- /**
- * Copyright 2013 Netflix, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package rx.util.functions;
+/**
+ * Copyright 2013 Netflix, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package rx.util.async;
import rx.Observable;
import rx.Scheduler;
-import rx.schedulers.ExecutorScheduler;
import rx.schedulers.Schedulers;
import rx.subjects.AsyncSubject;
+import rx.util.functions.Action0;
+import rx.util.functions.Action1;
+import rx.util.functions.Action2;
+import rx.util.functions.Action3;
+import rx.util.functions.Action4;
+import rx.util.functions.Action5;
+import rx.util.functions.Action6;
+import rx.util.functions.Action7;
+import rx.util.functions.Action8;
+import rx.util.functions.Action9;
+import rx.util.functions.ActionN;
+import rx.util.functions.Actions;
+import rx.util.functions.Func0;
+import rx.util.functions.Func1;
+import rx.util.functions.Func2;
+import rx.util.functions.Func3;
+import rx.util.functions.Func4;
+import rx.util.functions.Func5;
+import rx.util.functions.Func6;
+import rx.util.functions.Func7;
+import rx.util.functions.Func8;
+import rx.util.functions.Func9;
+import rx.util.functions.FuncN;
/**
* Utility methods to convert functions and actions into asynchronous
* operations through the Observable/Observer pattern.
*/
public final class Async {
- private Async() { throw new IllegalStateException("No instances!"); }
+ private Async() {
+ throw new IllegalStateException("No instances!");
+ }
+
/**
- * {@link Scheduler} intended for asynchronous conversions.
+ * Invokes the specified function asynchronously and returns an Observable
+ * that emits the result.
+ *
+ * Note: The function is called immediately and once, not whenever an
+ * observer subscribes to the resulting Observable. Multiple subscriptions
+ * to this Observable observe the same return value.
*
- * Defaults to {@link #threadPoolForComputation()}.
- *
- * @return {@link ExecutorScheduler} for asynchronous conversion work.
+ *
+ *
+ * @param func
+ * function to run asynchronously
+ * @return an Observable that emits the function's result value, or notifies
+ * observers of an exception
+ * @see RxJava Wiki: start()
+ * @see MSDN: Observable.Start
*/
- public static Scheduler threadPoolForAsyncConversions() {
- return Schedulers.threadPoolForComputation();
+ public static Observable start(Func0 func) {
+ return Async.toAsync(func).call();
}
+
+ /**
+ * Invokes the specified function asynchronously on the specified scheduler
+ * and returns an Observable that emits the result.
+ *
+ * Note: The function is called immediately and once, not whenever an
+ * observer subscribes to the resulting Observable. Multiple subscriptions
+ * to this Observable observe the same return value.
+ *
+ *
+ *
+ * @param func
+ * function to run asynchronously
+ * @param scheduler
+ * scheduler to run the function on
+ * @return an Observable that emits the function's result value, or notifies
+ * observers of an exception
+ * @see RxJava Wiki: start()
+ * @see MSDN: Observable.Start
+ */
+ public static Observable start(Func0 func, Scheduler scheduler) {
+ return Async.toAsync(func, scheduler).call();
+ }
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- *
+ *
+ * @param action
+ * the action to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func0> toAsync(Action0 action) {
- return toAsync(action, threadPoolForAsyncConversions());
+ return toAsync(action, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- *
+ *
+ * @param func
+ * the function to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func0> toAsync(Func0 extends R> func) {
- return toAsync(func, threadPoolForAsyncConversions());
+ return toAsync(func, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- *
+ *
+ * @param action
+ * the action to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func1> toAsync(Action1 super T1> action) {
- return toAsync(action, threadPoolForAsyncConversions());
+ return toAsync(action, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- *
+ *
+ * @param func
+ * the function to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func1> toAsync(Func1 super T1, ? extends R> func) {
- return toAsync(func, threadPoolForAsyncConversions());
+ return toAsync(func, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- *
+ *
+ * @param action
+ * the action to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func2> toAsync(Action2 super T1, ? super T2> action) {
- return toAsync(action, threadPoolForAsyncConversions());
+ return toAsync(action, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- *
+ *
+ * @param func
+ * the function to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func2> toAsync(Func2 super T1, ? super T2, ? extends R> func) {
- return toAsync(func, threadPoolForAsyncConversions());
+ return toAsync(func, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- *
+ *
+ * @param action
+ * the action to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func3> toAsync(Action3 super T1, ? super T2, ? super T3> action) {
- return toAsync(action, threadPoolForAsyncConversions());
+ return toAsync(action, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- *
+ *
+ * @param func
+ * the function to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func3> toAsync(Func3 super T1, ? super T2, ? super T3, ? extends R> func) {
- return toAsync(func, threadPoolForAsyncConversions());
+ return toAsync(func, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- *
+ *
+ * @param action
+ * the action to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
- public static Func4> toAsync(Action4 super T1,? super T2,? super T3,? super T4> action) {
- return toAsync(action, threadPoolForAsyncConversions());
+ public static Func4> toAsync(Action4 super T1, ? super T2, ? super T3, ? super T4> action) {
+ return toAsync(action, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- *
+ *
+ * @param func
+ * the function to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func4> toAsync(Func4 super T1, ? super T2, ? super T3, ? super T4, ? extends R> func) {
- return toAsync(func, threadPoolForAsyncConversions());
+ return toAsync(func, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- *
+ *
+ * @param action
+ * the action to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func5> toAsync(Action5 super T1, ? super T2, ? super T3, ? super T4, ? super T5> action) {
- return toAsync(action, threadPoolForAsyncConversions());
+ return toAsync(action, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- *
+ *
+ * @param func
+ * the function to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func5> toAsync(Func5 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? extends R> func) {
- return toAsync(func, threadPoolForAsyncConversions());
+ return toAsync(func, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- *
+ *
+ * @param action
+ * the action to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func6> toAsync(Action6 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6> action) {
- return toAsync(action, threadPoolForAsyncConversions());
+ return toAsync(action, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- *
+ *
+ * @param func
+ * the function to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func6> toAsync(Func6 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? extends R> func) {
- return toAsync(func, threadPoolForAsyncConversions());
+ return toAsync(func, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- *
+ *
+ * @param action
+ * the action to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func7> toAsync(Action7 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7> action) {
- return toAsync(action, threadPoolForAsyncConversions());
+ return toAsync(action, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- *
+ *
+ * @param func
+ * the function to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func7> toAsync(Func7 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> func) {
- return toAsync(func, threadPoolForAsyncConversions());
+ return toAsync(func, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- *
+ *
+ * @param action
+ * the action to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func8> toAsync(Action8 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8> action) {
- return toAsync(action, threadPoolForAsyncConversions());
+ return toAsync(action, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- *
+ *
+ * @param func
+ * the function to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func8> toAsync(Func8 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? extends R> func) {
- return toAsync(func, threadPoolForAsyncConversions());
+ return toAsync(func, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- *
+ *
+ * @param action
+ * the action to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func9> toAsync(Action9 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? super T9> action) {
- return toAsync(action, threadPoolForAsyncConversions());
+ return toAsync(action, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- *
+ *
+ * @param func
+ * the function to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func9> toAsync(Func9 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? super T9, ? extends R> func) {
- return toAsync(func, threadPoolForAsyncConversions());
+ return toAsync(func, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- *
+ *
+ * @param action
+ * the action to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
*/
public static FuncN> toAsync(ActionN action) {
- return toAsync(action, threadPoolForAsyncConversions());
+ return toAsync(action, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- *
+ *
+ * @param func
+ * the function to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
*/
public static FuncN> toAsync(FuncN extends R> func) {
- return toAsync(func, threadPoolForAsyncConversions());
+ return toAsync(func, Schedulers.threadPoolForComputation());
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- * @param scheduler the scheduler used to execute the {@code action}
- *
+ *
+ * @param action
+ * the action to convert
+ * @param scheduler
+ * the scheduler used to execute the {@code action}
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func0> toAsync(final Action0 action, final Scheduler scheduler) {
return toAsync(Actions.toFunc(action), scheduler);
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- * @param scheduler the scheduler used to call the {@code func}
- *
+ *
+ * @param func
+ * the function to convert
+ * @param scheduler
+ * the scheduler used to call the {@code func}
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func0> toAsync(final Func0 extends R> func, final Scheduler scheduler) {
@@ -394,31 +502,37 @@ public void call() {
}
};
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- * @param scheduler the scheduler used to execute the {@code action}
- *
+ *
+ * @param action
+ * the action to convert
+ * @param scheduler
+ * the scheduler used to execute the {@code action}
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func1> toAsync(final Action1 super T1> action, final Scheduler scheduler) {
return toAsync(Actions.toFunc(action), scheduler);
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- * @param scheduler the scheduler used to call the {@code func}
- *
+ *
+ * @param func
+ * the function to convert
+ * @param scheduler
+ * the scheduler used to call the {@code func}
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func1> toAsync(final Func1 super T1, ? extends R> func, final Scheduler scheduler) {
@@ -444,31 +558,37 @@ public void call() {
}
};
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- * @param scheduler the scheduler used to execute the {@code action}
- *
+ *
+ * @param action
+ * the action to convert
+ * @param scheduler
+ * the scheduler used to execute the {@code action}
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func2> toAsync(final Action2 super T1, ? super T2> action, final Scheduler scheduler) {
return toAsync(Actions.toFunc(action), scheduler);
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- * @param scheduler the scheduler used to call the {@code func}
- *
+ *
+ * @param func
+ * the function to convert
+ * @param scheduler
+ * the scheduler used to call the {@code func}
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func2> toAsync(final Func2 super T1, ? super T2, ? extends R> func, final Scheduler scheduler) {
@@ -494,31 +614,37 @@ public void call() {
}
};
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- * @param scheduler the scheduler used to execute the {@code action}
- *
+ *
+ * @param action
+ * the action to convert
+ * @param scheduler
+ * the scheduler used to execute the {@code action}
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func3> toAsync(final Action3 super T1, ? super T2, ? super T3> action, final Scheduler scheduler) {
return toAsync(Actions.toFunc(action), scheduler);
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- * @param scheduler the scheduler used to call the {@code func}
- *
+ *
+ * @param func
+ * the function to convert
+ * @param scheduler
+ * the scheduler used to call the {@code func}
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func3> toAsync(final Func3 super T1, ? super T2, ? super T3, ? extends R> func, final Scheduler scheduler) {
@@ -536,7 +662,7 @@ public void call() {
subject.onError(t);
return;
}
- subject.onNext(result);
+ subject.onNext(result);
subject.onCompleted();
}
});
@@ -544,31 +670,37 @@ public void call() {
}
};
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- * @param scheduler the scheduler used to execute the {@code action}
- *
+ *
+ * @param action
+ * the action to convert
+ * @param scheduler
+ * the scheduler used to execute the {@code action}
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func4> toAsync(final Action4 super T1, ? super T2, ? super T3, ? super T4> action, final Scheduler scheduler) {
return toAsync(Actions.toFunc(action), scheduler);
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- * @param scheduler the scheduler used to call the {@code func}
- *
+ *
+ * @param func
+ * the function to convert
+ * @param scheduler
+ * the scheduler used to call the {@code func}
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func4> toAsync(final Func4 super T1, ? super T2, ? super T3, ? super T4, ? extends R> func, final Scheduler scheduler) {
@@ -586,7 +718,7 @@ public void call() {
subject.onError(t);
return;
}
- subject.onNext(result);
+ subject.onNext(result);
subject.onCompleted();
}
});
@@ -594,31 +726,37 @@ public void call() {
}
};
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- * @param scheduler the scheduler used to execute the {@code action}
- *
+ *
+ * @param action
+ * the action to convert
+ * @param scheduler
+ * the scheduler used to execute the {@code action}
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func5> toAsync(final Action5 super T1, ? super T2, ? super T3, ? super T4, ? super T5> action, final Scheduler scheduler) {
return toAsync(Actions.toFunc(action), scheduler);
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- * @param scheduler the scheduler used to call the {@code func}
- *
+ *
+ * @param func
+ * the function to convert
+ * @param scheduler
+ * the scheduler used to call the {@code func}
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func5> toAsync(final Func5 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? extends R> func, final Scheduler scheduler) {
@@ -636,7 +774,7 @@ public void call() {
subject.onError(t);
return;
}
- subject.onNext(result);
+ subject.onNext(result);
subject.onCompleted();
}
});
@@ -644,31 +782,37 @@ public void call() {
}
};
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- * @param scheduler the scheduler used to execute the {@code action}
- *
+ *
+ * @param action
+ * the action to convert
+ * @param scheduler
+ * the scheduler used to execute the {@code action}
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func6> toAsync(final Action6 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6> action, final Scheduler scheduler) {
return toAsync(Actions.toFunc(action), scheduler);
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- * @param scheduler the scheduler used to call the {@code func}
- *
+ *
+ * @param func
+ * the function to convert
+ * @param scheduler
+ * the scheduler used to call the {@code func}
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func6> toAsync(final Func6 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? extends R> func, final Scheduler scheduler) {
@@ -686,7 +830,7 @@ public void call() {
subject.onError(t);
return;
}
- subject.onNext(result);
+ subject.onNext(result);
subject.onCompleted();
}
});
@@ -694,31 +838,37 @@ public void call() {
}
};
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- * @param scheduler the scheduler used to execute the {@code action}
- *
+ *
+ * @param action
+ * the action to convert
+ * @param scheduler
+ * the scheduler used to execute the {@code action}
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func7> toAsync(final Action7 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7> action, final Scheduler scheduler) {
return toAsync(Actions.toFunc(action), scheduler);
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- * @param scheduler the scheduler used to call the {@code func}
- *
+ *
+ * @param func
+ * the function to convert
+ * @param scheduler
+ * the scheduler used to call the {@code func}
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func7> toAsync(final Func7 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> func, final Scheduler scheduler) {
@@ -736,7 +886,7 @@ public void call() {
subject.onError(t);
return;
}
- subject.onNext(result);
+ subject.onNext(result);
subject.onCompleted();
}
});
@@ -744,31 +894,37 @@ public void call() {
}
};
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- * @param scheduler the scheduler used to execute the {@code action}
- *
+ *
+ * @param action
+ * the action to convert
+ * @param scheduler
+ * the scheduler used to execute the {@code action}
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func8> toAsync(final Action8 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8> action, final Scheduler scheduler) {
return toAsync(Actions.toFunc(action), scheduler);
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- * @param scheduler the scheduler used to call the {@code func}
- *
+ *
+ * @param func
+ * the function to convert
+ * @param scheduler
+ * the scheduler used to call the {@code func}
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func8> toAsync(final Func8 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? extends R> func, final Scheduler scheduler) {
@@ -786,7 +942,7 @@ public void call() {
subject.onError(t);
return;
}
- subject.onNext(result);
+ subject.onNext(result);
subject.onCompleted();
}
});
@@ -794,31 +950,37 @@ public void call() {
}
};
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- * @param scheduler the scheduler used to execute the {@code action}
- *
+ *
+ * @param action
+ * the action to convert
+ * @param scheduler
+ * the scheduler used to execute the {@code action}
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func9> toAsync(final Action9 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? super T9> action, final Scheduler scheduler) {
return toAsync(Actions.toFunc(action), scheduler);
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- * @param scheduler the scheduler used to call the {@code func}
- *
+ *
+ * @param func
+ * the function to convert
+ * @param scheduler
+ * the scheduler used to call the {@code func}
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
* @see MSDN: Observable.ToAsync
*/
public static Func9> toAsync(final Func9 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? super T9, ? extends R> func, final Scheduler scheduler) {
@@ -836,7 +998,7 @@ public void call() {
subject.onError(t);
return;
}
- subject.onNext(result);
+ subject.onNext(result);
subject.onCompleted();
}
});
@@ -844,30 +1006,36 @@ public void call() {
}
};
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
- *
- * @param action the action to convert
- * @param scheduler the scheduler used to execute the {@code action}
- *
+ *
+ * @param action
+ * the action to convert
+ * @param scheduler
+ * the scheduler used to execute the {@code action}
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
*/
public static FuncN> toAsync(final ActionN action, final Scheduler scheduler) {
return toAsync(Actions.toFunc(action), scheduler);
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
- *
- * @param func the function to convert
- * @param scheduler the scheduler used to call the {@code func}
- *
+ *
+ * @param func
+ * the function to convert
+ * @param scheduler
+ * the scheduler used to call the {@code func}
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
*/
public static FuncN> toAsync(final FuncN extends R> func, final Scheduler scheduler) {
return new FuncN>() {
@@ -892,64 +1060,74 @@ public void call() {
}
};
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
*
* Alias for toAsync(ActionN) intended for dynamic languages.
*
- * @param action the action to convert
- *
+ * @param action
+ * the action to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
*/
public static FuncN> asyncAction(final ActionN action) {
return toAsync(action);
}
+
/**
* Convert a synchronous action call into an asynchronous function
* call through an Observable sequence.
*
* Alias for toAsync(ActionN, Scheduler) intended for dynamic languages.
*
- * @param action the action to convert
- * @param scheduler the scheduler used to execute the {@code action}
- *
+ * @param action
+ * the action to convert
+ * @param scheduler
+ * the scheduler used to execute the {@code action}
+ *
* @return a function which returns an observable sequence which
* executes the {@code action} and emits {@code null}.
- *
+ *
*/
public static FuncN> asyncAction(final ActionN action, final Scheduler scheduler) {
return toAsync(action, scheduler);
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
*
* Alias for toAsync(FuncN) intended for dynamic languages.
*
- * @param func the function to convert
- *
+ * @param func
+ * the function to convert
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
*/
public static FuncN> asyncFunc(final FuncN extends R> func) {
return toAsync(func);
}
+
/**
* Convert a synchronous function call into an asynchronous function
* call through an Observable sequence.
*
* Alias for toAsync(FuncN, Scheduler) intended for dynamic languages.
*
- * @param func the function to convert
- * @param scheduler the scheduler used to call the {@code func}
- *
+ * @param func
+ * the function to convert
+ * @param scheduler
+ * the scheduler used to call the {@code func}
+ *
* @return a function which returns an observable sequence which
* executes the {@code func} and emits its returned value.
- *
+ *
*/
public static FuncN> asyncFunc(final FuncN extends R> func, final Scheduler scheduler) {
return toAsync(func, scheduler);
diff --git a/rxjava-core/src/test/java/rx/util/functions/AsyncTest.java b/rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/AsyncTest.java
similarity index 84%
rename from rxjava-core/src/test/java/rx/util/functions/AsyncTest.java
rename to rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/AsyncTest.java
index 05a75c4f85..943e8ff898 100644
--- a/rxjava-core/src/test/java/rx/util/functions/AsyncTest.java
+++ b/rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/AsyncTest.java
@@ -14,20 +14,29 @@
* limitations under the License.
*/
-package rx.util.functions;
+package rx.util.async;
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.*;
+
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
+
import junit.framework.Assert;
+
import org.junit.Before;
import org.junit.Test;
-import static org.mockito.Matchers.any;
+import org.mockito.InOrder;
import org.mockito.Mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import rx.Observable;
import rx.Observer;
import rx.schedulers.Schedulers;
+import rx.schedulers.TestScheduler;
import rx.util.functions.Action0;
import rx.util.functions.Action1;
import rx.util.functions.Action2;
@@ -54,10 +63,12 @@
public class AsyncTest {
@Mock
Observer