https://github.com/dsiner/taskscheduler
Thread Pool. Task/Thread switching, scheduling, without RxJava2; 线程池、线程切换、任务调度
https://github.com/dsiner/taskscheduler
flow scheduler task thread thread-pool
Last synced: 5 months ago
JSON representation
Thread Pool. Task/Thread switching, scheduling, without RxJava2; 线程池、线程切换、任务调度
- Host: GitHub
- URL: https://github.com/dsiner/taskscheduler
- Owner: Dsiner
- License: apache-2.0
- Created: 2018-05-16T10:02:15.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-12-24T13:33:00.000Z (about 5 years ago)
- Last Synced: 2025-03-27T05:02:05.809Z (10 months ago)
- Topics: flow, scheduler, task, thread, thread-pool
- Language: Java
- Homepage:
- Size: 150 KB
- Stars: 6
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# TaskScheduler for Android
[](https://www.apache.org/licenses/LICENSE-2.0)
[](https://android-arsenal.com/api?level=9)
[ ](https://bintray.com/dsiner/maven/taskscheduler/_latestVersion)
> TaskScheduler is a library for composing asynchronous and event-based programs by using observable sequences.
## Set up
Maven:
```xml
com.dsiner.lib
taskscheduler
1.0.2
```
or Gradle:
```groovy
compile 'com.dsiner.lib:taskscheduler:1.0.2'
```
## Getting started
Execute sync task in main thread
```java
TaskScheduler.executeMain(new Runnable() {
@Override
public void run() {
...do something in main thread
}
});
```
Execute async task in cached thread pool
```java
TaskScheduler.executeTask(new Runnable() {
@Override
public void run() {
...do something in asynchronous thread
}
});
```
Execute async task in single thread pool
```java
TaskScheduler.executeSingle(new Runnable() {
@Override
public void run() {
...do something in asynchronous thread
}
});
```
Execute async task in a new thread
```java
TaskScheduler.executeNew(new Runnable() {
@Override
public void run() {
...do something in asynchronous thread
}
});
```
Create task
```java
TaskScheduler.create(new Task>() {
@Override
public List run() {
...do something in io thread
return new ArrayList<>();
}
}).subscribeOn(Schedulers.io())
.observeOn(Schedulers.newThread())
.map(new Function, String>() {
@Override
public String apply(@NonNull List strings) throws Exception {
...do something in a new thread, such as time-consuming, map conversion, etc.
return "";
}
})
.observeOn(Schedulers.io())
.map(new Function() {
@Override
public Boolean apply(@NonNull String s) throws Exception {
...do something in io thread, such as time-consuming, map conversion, etc.
return true;
}
})
...
.observeOn(Schedulers.mainThread())
.subscribe(new Observer() {
@Override
public void onNext(@NonNull Boolean result) {
...do something in main thread
}
@Override
public void onError(Throwable e) {
...do something in main thread
}
});
```
## Latest Changes
- [Changelog.md](CHANGELOG.md)
## Licence
```txt
Copyright 2018 D
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.
```