@@ -9,8 +9,58 @@ It is licensed under [MIT](https://opensource.org/licenses/MIT).
9
9
[ ![ 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 )
10
10
11
11
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
+
12
62
** 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:
14
64
15
65
``` Java
16
66
Promise . resolve()
0 commit comments