PROMISES IN
JAVASCRIPT
ABOUT ME
Rubyist / JavaScripter
Yeoman team member
http://blog.revathskumar.com
Twitter/Github - @revathskumar
WHAT ARE PROMISES?
A pattern to work with asyncronous operations much neatly.
A function return a object called promise, w...
WHY WE NEED PROMISES?
Chaining
Attach multiple
callbacks
Pool operations
Easy error handling
Ue.e(,
srgt1{
sces fnto({
ucs: ucin)
cnoelg'ucs';
osl.o(Sces)
}
,
err fnto({
ro: ucin)
cnoelg'ro';
osl.o(Err)
}
}
)
IN PROMISE
Ue.e()te(
srgt1.hn
fnto({
ucin)
cnoelg'ucs';
osl.o(Sces)
}
,
fnto({
ucin)
cnoelg'ro';
osl.o(Err)
}
)
;
Ue.e(1,{
srgt''
sces fnto({
ucs: ucin)
Acut.e(1,{
consgt''
sces fnto({
ucs: ucin)
Acut.pae{wte:@dysai,{
consudt(titr adomn...
Ue.e()
srgt1
.hnAcut.e)
te(consgt
.hnfnto({
te(ucin)
rtr Acut.pae{wte:@dysai)
eun consudt(titr adomn}
}
)
.hnfnto({
te(uci...
POOLING
Alspo(
pu.ol
aycuc)
snFn(,
aohrsnFn(
nteAycuc)
)
.hnaycucs,aycro)
te(snSces snErr;
USING JQUERY
$we(
.hn
$aa("pg1pp )
.jx /ae.h" ,
$aa("pg2pp )
.jx /ae.h" ,
)
.hnoSces oErr;
te(nucs, nro)
JQUERY : MULTIPLE CALLBACKS
$we(ucin)
.hnfnto({
cnoelg'el Poie)
osl.o(Hlo rms';
}
)
.hnfnto({
te(ucin)
cnoelg'ucs1)
osl.o(...
REFERENCE
1.
2.
3.
4.

http://promises-aplus.github.io/promises-spec/
http://wiki.commonjs.org/wiki/Promises/A
https://git...
Upcoming SlideShare
Loading in …5
×

Promises in JavaScript

1,236 views

Published on

Promises in JavaScript.
From KeralaJS meetup

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,236
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Promises in JavaScript

  1. 1. PROMISES IN JAVASCRIPT
  2. 2. ABOUT ME Rubyist / JavaScripter Yeoman team member http://blog.revathskumar.com Twitter/Github - @revathskumar
  3. 3. WHAT ARE PROMISES? A pattern to work with asyncronous operations much neatly. A function return a object called promise, which is the eventual result of the operation. operated via then method. States : Pending / Fulfilled / Rejected poiete(nufle,oRjce) rms.hnoFlild neetd
  4. 4. WHY WE NEED PROMISES? Chaining Attach multiple callbacks Pool operations Easy error handling
  5. 5. Ue.e(, srgt1{ sces fnto({ ucs: ucin) cnoelg'ucs'; osl.o(Sces) } , err fnto({ ro: ucin) cnoelg'ro'; osl.o(Err) } } )
  6. 6. IN PROMISE Ue.e()te( srgt1.hn fnto({ ucin) cnoelg'ucs'; osl.o(Sces) } , fnto({ ucin) cnoelg'ro'; osl.o(Err) } ) ;
  7. 7. Ue.e(1,{ srgt'' sces fnto({ ucs: ucin) Acut.e(1,{ consgt'' sces fnto({ ucs: ucin) Acut.pae{wte:@dysai,{ consudt(titr adomn} sces fcto({ ucs: unin) cnoelg'ucs' osl.o(Sces) } , err fnto({ ro: ucin) cnoelg'ro'; osl.o(Err) } } ) } , err fcto({ ro: unin) cnoelg'ro'; osl.o(Err) } } ) } , err fnto({ ro: ucin) cnoelg'ro'; osl.o(err) } }; )
  8. 8. Ue.e() srgt1 .hnAcut.e) te(consgt .hnfnto({ te(ucin) rtr Acut.pae{wte:@dysai) eun consudt(titr adomn} } ) .hnfnto({ te(ucin) cnoelg'ucs'; osl.o(Sces) } ) .hnudfnd fnto({ te(neie, ucin) cnoelg'ro'; osl.o(Err) }; ) vrUe =(ucin) a sr fnto({ fnto gtue_d{ ucin e(sri) vrpoie=nwAls) a rms e pu(; $gt'ues'+ue_d { .e(/sr/ sri, sces fnto(aa{ ucs: ucindt) poieflildt.con_d; rms.ufl(aaacuti) } , err fnto({ ro: ucin) poierjc(Err) rms.eet'ro'; } }; ) rtr poie eun rms; } rtr { eun gt gt e: e } } )
  9. 9. POOLING Alspo( pu.ol aycuc) snFn(, aohrsnFn( nteAycuc) ) .hnaycucs,aycro) te(snSces snErr;
  10. 10. USING JQUERY $we( .hn $aa("pg1pp ) .jx /ae.h" , $aa("pg2pp ) .jx /ae.h" , ) .hnoSces oErr; te(nucs, nro)
  11. 11. JQUERY : MULTIPLE CALLBACKS $we(ucin) .hnfnto({ cnoelg'el Poie) osl.o(Hlo rms'; } ) .hnfnto({ te(ucin) cnoelg'ucs1) osl.o(Sces'; } fnto({ , ucin) cnoelg'ro1) osl.o(Err'; } ) .hnfnto({ te(ucin) cnoelg'ucs2) osl.o(Sces'; } fnto({ , ucin) cnoelg'ro2) osl.o(Err'; }; )
  12. 12. REFERENCE 1. 2. 3. 4. http://promises-aplus.github.io/promises-spec/ http://wiki.commonjs.org/wiki/Promises/A https://github.com/rhysbrettbowen/Aplus/ http://api.jquery.com/category/deferred-object/

×