@@ -189,6 +189,60 @@ While there are sparse features, there is a large sum of methods you can use to
189189
190190## Examples
191191> ```java
192- > // WIP
192+ > void main() throws InterruptedException {
193+ > AsyncTask<String > task = AsyncTask . of(
194+ > () - > 10 ,
195+ > () - > System . out. println(" Task 1" ), // shows that the tasks are parallelized
196+ > () - > System . out. println(" Task 2" ),
197+ > () - > System . out. println(" Task 3" ),
198+ > () - > System . out. println(" Task 4" ),
199+ > () - > System . out. println(" Task 5" )
200+ > ) // creates a returnable of type integer
201+ >
202+ > .onStart(() - > {
203+ > System . out. println(" Started main task" );
204+ > }) // shows when the task starts
205+ >
206+ > .after((item) - > {
207+ > return item + 3 ;
208+ > }) // returns 13 (doesn't change return type)
209+ >
210+ > .after((item) - > {
211+ > System . out. println(" Resulted in " + item);
212+ > System . out. println(" Changed type to a runnable" );
213+ > }) // converts to runnable
214+ >
215+ > .after(() - > {
216+ > System . out. println(" Changed type back to returnable, its type is String" );
217+ > return " capybara" ;
218+ > }) // converts to returnable of type string
219+ >
220+ > .onComplete((item) - > {
221+ > System . out. println(" Entire task completed with result " + item);
222+ > }) // calls after the entire task is completed
223+ > .start();
224+ >
225+ > System . out. println(" Sleep Started" );
226+ > Thread . sleep(1500 ); // proves it's actually asynced
227+ > System . out. println(" Sleep Ended" );
228+ > System . out. println(" Collecting results of the task back into main thread with result: " + task. collect());
229+ > }
230+ > ```
231+ > ## Console Output
232+ > The console output can be seen below, this naturally proves all I ' ve depicted in the code.
233+ > ```.shell
234+ > Started main task
235+ > Sleep Started
236+ > Task 1
237+ > Task 5
238+ > Task 3
239+ > Task 2
240+ > Task 4
241+ > Resulted in 13
242+ > Changed type to a runnable
243+ > Changed type back to returnable, its type is String
244+ > Entire task completed with result capybara
245+ > Sleep Ended
246+ > Collecting results of the task back into main thread with result: capybara
193247> ```
194248
0 commit comments