Deferred object

P
Deferred-Object
Deferred-Object
Callbacks
A callback is a piece of executable code that
is passed as an argument to other code,
which is expected to call back ( execute )
the argument at some convenient time
— Wikipedia
Promises & Deferreds: WTF?
Promises are a programming construct that
have been around since 1976.
A promise represents a value that is not yet
known
A deferred represents work that is not yet
finished
Deferred object
Why/When should I use the Deferred Object
/ Promise pattern?
DeferredObject/Promise pattern can help
you to better organise your code,
especially the asynchronous type
it also makes it really easy to merge and
pipe the execution of different pieces of
asynchronous code, which otherwise
would get really messy to code.
Normal case
new DeferredAsyncTask<HttpResponse,HttpResponse,Void>() {
protected abstract Resolved doInBackground() throws Exception {
//do your async code here
}
}
.done( new ResolveCallback<HttpResponse> {
public void onResolve(HttpResponse resolved) {
//your success code here
}
})
.fail ( new RejectCallback<HttpResponse> {
public void onReject(HttpResponse rejected) {
//your failure code here
}
});
Several promises
Promise<A1,B1,C1> p1 = new DeferredAsyncTask<A1,B1,C1>() { ... };
Promise<A2,B2,C2> p1 = new DeferredAsyncTask<A2,B2,C2>() { ... };
Promise<A3,B3,C3> p3 = new DeferredAsyncTask<A3,B3,C3>() { ... };
//when gives you a new promise that gets triggered when all the merged promises are resolved or one of them fails
DeferredObject.when(p1,p2,p3)
.done(new ResolveCallback<MergedPromiseResult3<A1,A2,A3>() {
public void onResolve(MergedPromiseResult3<A1,A2,A3> resolved){
Log.i(TAG, "got: " + resolved.first() + resolved.second() + resolved.third());
}
})
.fail(new RejectCallback<MergedPromiseReject>() {
public void onReject(MergedPromiseReject rejected) {
//failure handling here
}
})
.progress(new ProgressCallback<MergedPromiseProgress>() {
public void onProgress(final MergedPromiseProgress progress){
//you get notified as the merged promises keep coming in
}
});
//Merging doesn't stop you do add individual callbacks for promises that are in the merge
p1.done(...).fail(...)
//Or even merging them in another way
DeferredObject.when(p1,p2).done(...).fail(...)
new DeferredAsyncTask<HttpResponse,HttpResponse,Void>() {...}
.done( /* callback to first call here */ )
.pipe(new ResolvePipe<HttpResponse,HttpResponse,Void>() {
public Promise<HttpResponse,HttpResponse,Void> pipeResolved(HttpResponse response1){
return new DeferredAsyncTask<HttpResponse,HttpResponse,Void>() { ... }
}
})
.done( /* callback to second call here */ )
.pipe(new ResolvePipe<HttpResponse,HttpResponse,Void>() {
public Promise<HttpResponse,HttpResponse,Void> pipeResolved(HttpResponse response1){
return new DeferredAsyncTask<HttpResponse,HttpResponse,Void>() { ... }
}
})
.done( /* callback to third call here */ )
TERMINO!
Ahora si algo mas interesante!
Oculus Rift!!!!!
Que es?
Es la vara mas rajada en
existencia!!
Deferred object
Sensors
Gyroscope
Accelerometer
Magnetometer
Update rate
2-3 miliseconds
Hecho por
El dios de la programación
Deferred object
Deferred object
El otro épico video!
Gracias, Gracias!!
1 of 22

Recommended

#3 (Multi Threads With TCP) by
#3 (Multi Threads With TCP)#3 (Multi Threads With TCP)
#3 (Multi Threads With TCP)Ghadeer AlHasan
67 views17 slides
Unit 1 introduction to middleware technologies by
Unit 1  introduction to middleware technologiesUnit 1  introduction to middleware technologies
Unit 1 introduction to middleware technologiesKristu Jayanti College
23 views48 slides
Intro to Asynchronous Javascript by
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous JavascriptGarrett Welson
601 views62 slides
Mule esb object_to_jackson_json by
Mule esb object_to_jackson_jsonMule esb object_to_jackson_json
Mule esb object_to_jackson_jsonDavide Rapacciuolo
206 views5 slides
The Internet own boy by
The Internet own boyThe Internet own boy
The Internet own boyPiXeL16
536 views134 slides
Unit testing by
Unit testingUnit testing
Unit testingPiXeL16
542 views52 slides

More Related Content

Viewers also liked

WWDC 2014 by
WWDC 2014WWDC 2014
WWDC 2014PiXeL16
512 views38 slides
An introduction to Mobile Development (Spanish) by
An introduction to Mobile Development (Spanish)An introduction to Mobile Development (Spanish)
An introduction to Mobile Development (Spanish)PiXeL16
434 views54 slides
DevOps and Chef by
DevOps and ChefDevOps and Chef
DevOps and ChefPiXeL16
477 views32 slides
REST with Eve and Python by
REST with Eve and PythonREST with Eve and Python
REST with Eve and PythonPiXeL16
1.9K views57 slides
WWDC 2016 by
WWDC 2016WWDC 2016
WWDC 2016PiXeL16
582 views36 slides
Mobile architecture problems and solutions. by
Mobile architecture problems and solutions.Mobile architecture problems and solutions.
Mobile architecture problems and solutions.PiXeL16
538 views25 slides

Viewers also liked(8)

WWDC 2014 by PiXeL16
WWDC 2014WWDC 2014
WWDC 2014
PiXeL16512 views
An introduction to Mobile Development (Spanish) by PiXeL16
An introduction to Mobile Development (Spanish)An introduction to Mobile Development (Spanish)
An introduction to Mobile Development (Spanish)
PiXeL16434 views
DevOps and Chef by PiXeL16
DevOps and ChefDevOps and Chef
DevOps and Chef
PiXeL16477 views
REST with Eve and Python by PiXeL16
REST with Eve and PythonREST with Eve and Python
REST with Eve and Python
PiXeL161.9K views
WWDC 2016 by PiXeL16
WWDC 2016WWDC 2016
WWDC 2016
PiXeL16582 views
Mobile architecture problems and solutions. by PiXeL16
Mobile architecture problems and solutions.Mobile architecture problems and solutions.
Mobile architecture problems and solutions.
PiXeL16538 views
Hooked - How to build habit forming products by PiXeL16
Hooked - How to build habit forming products Hooked - How to build habit forming products
Hooked - How to build habit forming products
PiXeL16801 views
Rest Introduction (Chris Jimenez) by PiXeL16
Rest Introduction (Chris Jimenez)Rest Introduction (Chris Jimenez)
Rest Introduction (Chris Jimenez)
PiXeL161K views

Similar to Deferred object

The Promised Land (in Angular) by
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)Domenic Denicola
23.1K views42 slides
JavaScript Promises by
JavaScript PromisesJavaScript Promises
JavaScript PromisesDerek Willian Stavis
1.1K views64 slides
TDC2016POA | Trilha JavaScript - JavaScript Promises na Prática by
TDC2016POA | Trilha JavaScript - JavaScript Promises na PráticaTDC2016POA | Trilha JavaScript - JavaScript Promises na Prática
TDC2016POA | Trilha JavaScript - JavaScript Promises na Práticatdc-globalcode
297 views64 slides
JSON Part 3: Asynchronous Ajax & JQuery Deferred by
JSON Part 3: Asynchronous Ajax & JQuery DeferredJSON Part 3: Asynchronous Ajax & JQuery Deferred
JSON Part 3: Asynchronous Ajax & JQuery DeferredJeff Fox
7.5K views33 slides
Grails transactions by
Grails   transactionsGrails   transactions
Grails transactionsHusain Dalal
1.4K views36 slides
Asynchronous development in JavaScript by
Asynchronous development  in JavaScriptAsynchronous development  in JavaScript
Asynchronous development in JavaScriptAmitai Barnea
330 views25 slides

Similar to Deferred object(20)

The Promised Land (in Angular) by Domenic Denicola
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)
Domenic Denicola23.1K views
TDC2016POA | Trilha JavaScript - JavaScript Promises na Prática by tdc-globalcode
TDC2016POA | Trilha JavaScript - JavaScript Promises na PráticaTDC2016POA | Trilha JavaScript - JavaScript Promises na Prática
TDC2016POA | Trilha JavaScript - JavaScript Promises na Prática
tdc-globalcode297 views
JSON Part 3: Asynchronous Ajax & JQuery Deferred by Jeff Fox
JSON Part 3: Asynchronous Ajax & JQuery DeferredJSON Part 3: Asynchronous Ajax & JQuery Deferred
JSON Part 3: Asynchronous Ajax & JQuery Deferred
Jeff Fox7.5K views
Grails transactions by Husain Dalal
Grails   transactionsGrails   transactions
Grails transactions
Husain Dalal1.4K views
Asynchronous development in JavaScript by Amitai Barnea
Asynchronous development  in JavaScriptAsynchronous development  in JavaScript
Asynchronous development in JavaScript
Amitai Barnea330 views
Promises look into the async future by slicejs
Promises look into the async futurePromises look into the async future
Promises look into the async future
slicejs1.1K views
Getting Comfortable with JS Promises by Asa Kusuma
Getting Comfortable with JS PromisesGetting Comfortable with JS Promises
Getting Comfortable with JS Promises
Asa Kusuma2.9K views
Speed up your Web applications with HTML5 WebSockets by Yakov Fain
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSockets
Yakov Fain3.2K views
Async servers and clients in Rest.li by Karan Parikh
Async servers and clients in Rest.liAsync servers and clients in Rest.li
Async servers and clients in Rest.li
Karan Parikh2.1K views
Avoiding callback hell in Node js using promises by Ankit Agarwal
Avoiding callback hell in Node js using promisesAvoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promises
Ankit Agarwal5.9K views
Async js - Nemetschek Presentaion @ HackBulgaria by HackBulgaria
Async js - Nemetschek Presentaion @ HackBulgariaAsync js - Nemetschek Presentaion @ HackBulgaria
Async js - Nemetschek Presentaion @ HackBulgaria
HackBulgaria886 views
Gopher fest 2017: Adding Context To NATS by Apcera
Gopher fest 2017: Adding Context To NATSGopher fest 2017: Adding Context To NATS
Gopher fest 2017: Adding Context To NATS
Apcera495 views
GopherFest 2017 - Adding Context to NATS by wallyqs
GopherFest 2017 -  Adding Context to NATSGopherFest 2017 -  Adding Context to NATS
GopherFest 2017 - Adding Context to NATS
wallyqs4.7K views
GopherFest 2017 talk - Adding Context to NATS by NATS
GopherFest 2017 talk - Adding Context to NATSGopherFest 2017 talk - Adding Context to NATS
GopherFest 2017 talk - Adding Context to NATS
NATS197 views
Finagle and Java Service Framework at Pinterest by Pavan Chitumalla
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at Pinterest
Pavan Chitumalla546 views

Recently uploaded

Elevate your SAP landscape's efficiency and performance with HCL Workload Aut... by
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...HCLSoftware
6 views2 slides
Advanced API Mocking Techniques by
Advanced API Mocking TechniquesAdvanced API Mocking Techniques
Advanced API Mocking TechniquesDimpy Adhikary
19 views11 slides
Software testing company in India.pptx by
Software testing company in India.pptxSoftware testing company in India.pptx
Software testing company in India.pptxSakshiPatel82
7 views9 slides
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... by
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Marc Müller
37 views83 slides
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... by
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...Deltares
12 views23 slides
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t... by
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...Deltares
9 views26 slides

Recently uploaded(20)

Elevate your SAP landscape's efficiency and performance with HCL Workload Aut... by HCLSoftware
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...
HCLSoftware6 views
Advanced API Mocking Techniques by Dimpy Adhikary
Advanced API Mocking TechniquesAdvanced API Mocking Techniques
Advanced API Mocking Techniques
Dimpy Adhikary19 views
Software testing company in India.pptx by SakshiPatel82
Software testing company in India.pptxSoftware testing company in India.pptx
Software testing company in India.pptx
SakshiPatel827 views
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... by Marc Müller
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Marc Müller37 views
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... by Deltares
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
Deltares12 views
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t... by Deltares
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
Deltares9 views
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema by Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - GeertsemaDSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
Deltares17 views
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit... by Deltares
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...
DSD-INT 2023 FloodAdapt - A decision-support tool for compound flood risk mit...
Deltares13 views
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... by Donato Onofri
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Donato Onofri773 views
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ... by Deltares
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
Deltares10 views
360 graden fabriek by info33492
360 graden fabriek360 graden fabriek
360 graden fabriek
info3349236 views
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols by Deltares
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - DolsDSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols
Deltares7 views
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs by Deltares
DSD-INT 2023 The Danube Hazardous Substances Model - KovacsDSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
Deltares8 views
Navigating container technology for enhanced security by Niklas Saari by Metosin Oy
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
Metosin Oy12 views
MariaDB stored procedures and why they should be improved by Federico Razzoli
MariaDB stored procedures and why they should be improvedMariaDB stored procedures and why they should be improved
MariaDB stored procedures and why they should be improved
DSD-INT 2023 Next-Generation Flood Inundation Mapping for Taiwan - Delft3D FM... by Deltares
DSD-INT 2023 Next-Generation Flood Inundation Mapping for Taiwan - Delft3D FM...DSD-INT 2023 Next-Generation Flood Inundation Mapping for Taiwan - Delft3D FM...
DSD-INT 2023 Next-Generation Flood Inundation Mapping for Taiwan - Delft3D FM...
Deltares7 views

Deferred object

  • 2. Callbacks A callback is a piece of executable code that is passed as an argument to other code, which is expected to call back ( execute ) the argument at some convenient time — Wikipedia
  • 3. Promises & Deferreds: WTF? Promises are a programming construct that have been around since 1976. A promise represents a value that is not yet known A deferred represents work that is not yet finished
  • 5. Why/When should I use the Deferred Object / Promise pattern? DeferredObject/Promise pattern can help you to better organise your code, especially the asynchronous type
  • 6. it also makes it really easy to merge and pipe the execution of different pieces of asynchronous code, which otherwise would get really messy to code.
  • 7. Normal case new DeferredAsyncTask<HttpResponse,HttpResponse,Void>() { protected abstract Resolved doInBackground() throws Exception { //do your async code here } } .done( new ResolveCallback<HttpResponse> { public void onResolve(HttpResponse resolved) { //your success code here } }) .fail ( new RejectCallback<HttpResponse> { public void onReject(HttpResponse rejected) { //your failure code here } });
  • 8. Several promises Promise<A1,B1,C1> p1 = new DeferredAsyncTask<A1,B1,C1>() { ... }; Promise<A2,B2,C2> p1 = new DeferredAsyncTask<A2,B2,C2>() { ... }; Promise<A3,B3,C3> p3 = new DeferredAsyncTask<A3,B3,C3>() { ... }; //when gives you a new promise that gets triggered when all the merged promises are resolved or one of them fails DeferredObject.when(p1,p2,p3) .done(new ResolveCallback<MergedPromiseResult3<A1,A2,A3>() { public void onResolve(MergedPromiseResult3<A1,A2,A3> resolved){ Log.i(TAG, "got: " + resolved.first() + resolved.second() + resolved.third()); } })
  • 9. .fail(new RejectCallback<MergedPromiseReject>() { public void onReject(MergedPromiseReject rejected) { //failure handling here } }) .progress(new ProgressCallback<MergedPromiseProgress>() { public void onProgress(final MergedPromiseProgress progress){ //you get notified as the merged promises keep coming in } }); //Merging doesn't stop you do add individual callbacks for promises that are in the merge p1.done(...).fail(...) //Or even merging them in another way DeferredObject.when(p1,p2).done(...).fail(...)
  • 10. new DeferredAsyncTask<HttpResponse,HttpResponse,Void>() {...} .done( /* callback to first call here */ ) .pipe(new ResolvePipe<HttpResponse,HttpResponse,Void>() { public Promise<HttpResponse,HttpResponse,Void> pipeResolved(HttpResponse response1){ return new DeferredAsyncTask<HttpResponse,HttpResponse,Void>() { ... } } }) .done( /* callback to second call here */ ) .pipe(new ResolvePipe<HttpResponse,HttpResponse,Void>() { public Promise<HttpResponse,HttpResponse,Void> pipeResolved(HttpResponse response1){ return new DeferredAsyncTask<HttpResponse,HttpResponse,Void>() { ... } } }) .done( /* callback to third call here */ )
  • 12. Ahora si algo mas interesante!
  • 14. Que es? Es la vara mas rajada en existencia!!
  • 18. El dios de la programación
  • 21. El otro épico video!