Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ioweyou/iou-core
IOU is a Promises/A+ compliant promise library for Java
https://github.com/ioweyou/iou-core
android aplus deferred gradle iou java java7 java8 promise
Last synced: about 22 hours ago
JSON representation
IOU is a Promises/A+ compliant promise library for Java
- Host: GitHub
- URL: https://github.com/ioweyou/iou-core
- Owner: ioweyou
- License: mit
- Archived: true
- Created: 2016-04-19T18:05:21.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-02T07:35:11.000Z (almost 8 years ago)
- Last Synced: 2024-12-17T04:08:06.489Z (about 1 month ago)
- Topics: android, aplus, deferred, gradle, iou, java, java7, java8, promise
- Language: Java
- Homepage: https://ioweyou.github.io
- Size: 195 KB
- Stars: 5
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# IOU Core
[![Travis CI](https://travis-ci.org/ioweyou/iou-core.svg)](https://travis-ci.org/ioweyou/iou-core)
[![Coverage Status](https://coveralls.io/repos/github/ioweyou/iou-core/badge.svg?branch=master)](https://coveralls.io/github/ioweyou/iou-core?branch=master)
[![License MIT](https://img.shields.io/:license-mit-blue.svg)](http://badges.mit-license.org)
A [Promises/A+](https://github.com/promises-aplus/promises-spec) compliant promise library for Java, designed to be extended by other libraries like [IOU Java](https://github.com/ioweyou/iou-java) and [IOU Android](https://github.com/ioweyou/iou-android).#### Table Of Contents
[Implementations](#implementations)
[Dependency management](#dependency-management)
* [Maven](#maven)
* [Gradle](#gradle)[Examples](#examples)
* [Call with single then](#call-with-single-then)
* [Call with single then and Java 8 lambda](#call-with-single-then-and-java-8-lambda)
* [Chained or piped promise](#chained-or-piped-promise)
* [Parallel promise](#parallel-promise)
* [Rejecting a promise](#rejecting-a-promise)
* [Failing a promise](#failing-a-promise)## Implementations
* [IOU Java](https://github.com/ioweyou/iou-java)
* [IOU Android](https://github.com/ioweyou/iou-android)## Dependency management
### Maven
-----
```xmlnl.brusque.iou
iou-core
1.0.0-beta-01```
### Gradle
-----
```
compile 'nl.brusque.iou:iou-core:1.0.0-beta-01'
```## Examples
-----
### Given the example implementation
```java
class TestTypedIOU extends AbstractIOU {
...
}class TestTypedPromise extends AbstractPromise {
...
}TestTypedIOU iou = new TestTypedIOU<>();
```
### Call with single then
```java
iou.getPromise()
.then(new IThenCallable() {
@Override
public Void apply(Integer integer) throws Exception {
System.out.println(integer);return null;
}
});iou.resolve(42); // prints 42
```
### Call with single then and Java 8 lambda
```java
iou.getPromise()
.then((Integer integer) -> {
System.out.println(integer);return null;
});iou.resolve(42); // prints 42
```
### Chained or piped promise
```java
iou.getPromise()
.then(new IThenCallable() {
@Override
public Integer apply(Integer input) throws Exception {
return input * 10;
}
})
.then(new IThenCallable() {
@Override
public String apply(Integer input) throws Exception {
return String.format("The result: %d", input);
}
})
.then(new IThenCallable() {
@Override
public Void apply(String input) throws Exception {
System.out.println(input);return null;
}
});iou.resolve(42); // prints "The result: 420"
```
### Sequential promise
```java
TestTypedPromise promise = iou.getPromise();promise
.then(new IThenCallable() {
@Override
public Void apply(Integer input) throws Exception {
System.out.println(input);return null;
}
});promise
.then(new IThenCallable() {
@Override
public Void apply(Integer input) throws Exception {
String result = String.format("%d * 10 = %d", input, input * 10);
System.out.println(result);return result;
}
});iou.resolve(42); // prints "42" and "42 * 10 = 420" in exactly this order
```
### Rejecting a promise
```java
iou.getPromise()
.then(new IThenCallable() {
@Override
public Integer apply(Integer integer) throws Exception {
return integer * 42;
}
}, new IThenCallable() {
@Override
public Void apply(Object reason) throws Exception {
System.out.println(String.format("%s I can't do that.", reason));return null;
}
});iou.reject("I'm sorry, Dave."); // prints "I'm sorry, Dave. I can't do that."
```
### Failing a promise
```java
iou.getPromise()
.then(new IThenCallable() {
@Override
public Integer apply(Integer input) throws Exception {
throw new Exception("I just don't care.");
}
})
.then(new IThenCallable() {
@Override
public Void apply(Integer input) throws Exception {
System.out.println("What would you say it is you do here?");return null;
}
}, new IThenCallable() {
@Override
public Void apply(Object reason) throws Exception {
System.out.println(
String.format("It's not that I'm lazy, it's that %s",
((Exception)reason).getMessage()));return null;
}
});iou.resolve(42); // prints "It's not that I'm lazy, it's that I just don't care."
```