forked from ReactiveX/RxJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
apply plugin: 'osgi' | ||
|
||
dependencies { | ||
compile project(':rxjava-core') | ||
|
||
// testing | ||
provided 'junit:junit-dep:4.10' | ||
compile 'org.robovm:robovm-rt:0.0.12' | ||
compile 'org.robovm:robovm-objc:0.0.12' | ||
compile 'org.robovm:robovm-cocoatouch:0.0.12' | ||
} | ||
|
||
javadoc { | ||
options { | ||
doclet = "org.benjchristensen.doclet.DocletExclude" | ||
docletpath = [rootProject.file('./gradle/doclet-exclude.jar')] | ||
stylesheetFile = rootProject.file('./gradle/javadocStyleSheet.css') | ||
windowTitle = "RxJava iOS Javadoc ${project.version}" | ||
} | ||
options.addStringOption('top').value = '<h2 class="title" style="padding-top:40px">RxJava iOS</h2>' | ||
} | ||
|
||
jar { | ||
manifest { | ||
name = 'rxjava-ios' | ||
instruction 'Bundle-Vendor', 'Netflix' | ||
instruction 'Bundle-DocURL', 'https://github.com/Netflix/RxJava' | ||
instruction 'Import-Package', '!org.junit,!junit.framework,!org.mockito.*,*' | ||
instruction 'Fragment-Host', 'com.netflix.rxjava.core' | ||
} | ||
} | ||
|
||
test { | ||
testLogging { | ||
exceptionFormat "full" | ||
events "started" | ||
displayGranularity 2 | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
rxjava-contrib/rxjava-ios/src/main/java/rx/ios/schedulers/HandlerThreadScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package rx.ios.schedulers; | ||
/** | ||
* Copyright 2013 Netflix, Inc. | ||
* Copyright 2014 Ashley Williams | ||
* | ||
* 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. | ||
*/ | ||
|
||
|
||
import org.robovm.apple.foundation.NSBlockOperation; | ||
import org.robovm.apple.foundation.NSOperationQueue; | ||
import rx.Scheduler; | ||
import rx.Subscription; | ||
import rx.functions.Action0; | ||
import rx.subscriptions.BooleanSubscription; | ||
import rx.subscriptions.Subscriptions; | ||
|
||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Schedules actions to run on an iOS Handler thread. | ||
*/ | ||
public class HandlerThreadScheduler extends Scheduler { | ||
|
||
private final NSOperationQueue operationQueue; | ||
|
||
public HandlerThreadScheduler(NSOperationQueue operationQueue) { | ||
this.operationQueue = operationQueue; | ||
} | ||
|
||
@Override | ||
public Worker createWorker() { | ||
return new InnerHandlerThreadScheduler(operationQueue); | ||
} | ||
|
||
|
||
private static class InnerHandlerThreadScheduler extends Worker { | ||
|
||
private final NSOperationQueue operationQueue; | ||
private BooleanSubscription innerSubscription = new BooleanSubscription(); | ||
|
||
|
||
public InnerHandlerThreadScheduler(NSOperationQueue operationQueue) { | ||
this.operationQueue = operationQueue; | ||
} | ||
|
||
@Override | ||
public void unsubscribe() { | ||
innerSubscription.unsubscribe(); | ||
} | ||
|
||
@Override | ||
public boolean isUnsubscribed() { | ||
return innerSubscription.isUnsubscribed(); | ||
} | ||
|
||
@Override | ||
public Subscription schedule(Action0 action0) { | ||
return schedule(action0, 0, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
@Override | ||
public Subscription schedule(final Action0 action, long delayTime, TimeUnit unit) { | ||
|
||
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); | ||
final NSBlockOperation runOperation = new NSBlockOperation(); | ||
|
||
executor.schedule(new Runnable() { | ||
@Override | ||
public void run() { | ||
if (isUnsubscribed()) { | ||
return; | ||
} | ||
/* Runnable for action */ | ||
final Runnable actionRunner = new Runnable() { | ||
@Override | ||
public void run() { | ||
action.call(); | ||
} | ||
}; | ||
|
||
runOperation.addExecutionBlock$(actionRunner); | ||
|
||
/* Add operation to operation queue*/ | ||
operationQueue.addOperation(runOperation); | ||
} | ||
}, delayTime, unit); | ||
|
||
return Subscriptions.create(new Action0() { | ||
@Override | ||
public void call() { | ||
runOperation.cancel(); | ||
} | ||
}); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
rxjava-contrib/rxjava-ios/src/main/java/rx/ios/schedulers/IOSSchedulers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright 2013 Netflix, Inc. | ||
* Copyright 2014 Ashley Williams | ||
* | ||
* 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.ios.schedulers; | ||
|
||
import rx.Scheduler; | ||
import org.robovm.apple.foundation.NSOperationQueue; | ||
|
||
|
||
public class IOSSchedulers { | ||
|
||
private static final Scheduler MAIN_THREAD_SCHEDULER = | ||
new HandlerThreadScheduler((NSOperationQueue) NSOperationQueue.getMainQueue()); | ||
|
||
private IOSSchedulers(){ | ||
|
||
} | ||
|
||
|
||
public static Scheduler handlerThread(final NSOperationQueue operationQueue) { | ||
return new HandlerThreadScheduler(operationQueue); | ||
} | ||
|
||
public static Scheduler mainThread() { | ||
return MAIN_THREAD_SCHEDULER; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters