Skip to content

Commit e9bdb7b

Browse files
committed
update readme
1 parent f8d3df4 commit e9bdb7b

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,58 @@ It is licensed under [MIT](https://opensource.org/licenses/MIT).
99
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.riversun/java-promise/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.riversun/java-promise)
1010

1111

12+
# Quick Look
13+
14+
**Writing a Promise in Javascript**
15+
16+
A typical example of using promise in JavaScript is:
17+
18+
```JavaScript
19+
Promise.resolve('foo')
20+
.then(function (data) {
21+
return new Promise(function (resolve, reject) {
22+
setTimeout(function () {
23+
const newData = data + 'bar';
24+
resolve(newData);
25+
}, 1);
26+
});
27+
})
28+
.then(function (data) {
29+
return new Promise(function (resolve, reject) {
30+
console.log(data);
31+
});
32+
});
33+
console.log("Promise in JavaScript");
34+
```
35+
36+
**Writing a Promise in java-promise**
37+
38+
Write the same thing using **java-promise**
39+
40+
```Java
41+
import org.riversun.promise.Promise;
42+
public class Example {
43+
44+
public static void main(String[] args) {
45+
Promise.resolve("foo")
46+
.then(new Promise((action, data) -> {
47+
new Thread(() -> {
48+
String newData = data + "bar";
49+
action.resolve(newData);
50+
}).start();
51+
}))
52+
.then(new Promise((action, data) -> {
53+
System.out.println(data);
54+
action.resolve();
55+
}))
56+
.start();
57+
System.out.println("Promise in Java");
58+
}
59+
}
60+
```
61+
1262
**Syntax:**
13-
You can write in a syntax similar to JavaScript as follows:
63+
Yes,you can write in a syntax similar to JavaScript as follows:
1464

1565
```Java
1666
Promise.resolve()

0 commit comments

Comments
 (0)