Skip to content

Commit c450f9c

Browse files
committed
some quick examples added in read me file
1 parent 957270a commit c450f9c

1 file changed

Lines changed: 75 additions & 1 deletion

File tree

README.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,79 @@ It is not very easy to controll a complex flow of asynchronus operations special
4242

4343
## Quick Examples
4444

45-
TODO
45+
### 1. Hello World!!
4646

47+
```java
48+
49+
Deferred<String> deferred = DeferredFactory.createDeferred();
50+
51+
deferred.then(
52+
new Callbacks.SuccessCallBack<VoidType, String>() {
53+
@Override
54+
public Object call(String value) {
55+
System.out.println(value);
56+
return VoidType.NOTHING;
57+
}
58+
},
59+
new Callbacks.FailureCallBack() {
60+
@Override
61+
public VoidType call(Exception reason) {
62+
System.out.println(reason.getMessage());
63+
return VoidType.NOTHING;
64+
}
65+
},
66+
new Callbacks.NotificationCallBack() {
67+
@Override
68+
public VoidType call(NotificationEvent event) {
69+
System.out.println("An update received!!");
70+
return null;
71+
}
72+
});
73+
74+
//to resolve use deferred.resolve("Hello World!!);
75+
//to notify use deferred.notify(new NotificationEvent(deferred.promise()));
76+
//to reject use deferred.reject(new RuntimeException("message here..."))
77+
```
78+
79+
## 2. Promise Chaining
80+
81+
```java
82+
83+
Deferred<String> deferred = DeferredFactory.createDeferred();
84+
85+
deferred.then(new Callbacks.SuccessCallBack<String, String>() {
86+
@Override
87+
public Object call(String value) {
88+
return value + " ";
89+
}
90+
})
91+
.then(new Callbacks.SuccessCallBack<String, String>() {
92+
@Override
93+
public Object call(String value) {
94+
return value + "World";
95+
}
96+
})
97+
.then(new Callbacks.SuccessCallBack<String, String>() {
98+
@Override
99+
public Object call(String value) {
100+
return value + "!!";
101+
}
102+
})
103+
.then(new Callbacks.SuccessCallBack<String, String>() {
104+
@Override
105+
public Object call(String value) {
106+
System.out.println(value);
107+
return null;
108+
}
109+
})
110+
.fail(new FailureCallBack() {
111+
@Override
112+
public VoidType call(Exception ex) {
113+
System.out.println(ex.getMessage());
114+
return null;
115+
}
116+
});
117+
118+
//to resolve use deferred.resolve("Hello");
119+
//to reject use deferred.reject(new RuntimeException("Hello Hell!!"));
120+
```

0 commit comments

Comments
 (0)