PRESENTING:
SEQ
ABOUT ME
Who I am: Douglas Muth
How to contact me: dmuth@dmuth.org / @dmuth
What I do: Software Engineer ...mostly.
THE PROBLEM
Flow control in node.js.
Node.js is a callback-heavy language.
Often, it looks like this:
d.ur(SLC ..,fnto(ro,rsls {
bqey"EET ." ucinerr eut)
i (err {
f !ro)
d.ur(UDT ..,fnto(ro,rsls {
bqey"PAE ." ucinerr eut)
i (err {
f !ro)
d.ur(ISR ..,fnto(ro,rsls {
bqey"NET ." ucinerr eut)
/ O Gd wy
/ h o, h?
}
}
};
)
}
};
)

Also known as "boomerang code"!
SEQ 101
INSTALLATION
$nmisalsq
p ntl e

That was easy!
SEQ 101
USAGE
vrsq=rqie"e";
a e
eur(sq)
sq)sqfnto( {
e(.e(ucin)
d.ur(SLC ..,ti)
bqey"EET ." hs;
}.e(ucinrsls {
)sqfnto(eut)
d.ur(UDT ..,ti)
bqey"PAE ." hs;
}.e(ucinrsls {
)sqfnto(eut)
d.ur(ISR ..,ti) / Pet set
bqey"NET ." hs; / rty we!
};
)

"this()" is the callback which goes to the next block of code
SEQ 101
WHEN THINGS GO WRONG
sq)sqfnto( {
e(.e(ucin)
d.ur(SLC ..,ti)
bqey"EET ." hs;
}.e(ucinrsls {
)sqfnto(eut)
ti(e Err"hk tig u altl")
hsnw ro(Sae hns p
ite);
}.e(ucinrsls {
)sqfnto(eut)
/ Ti wl nvrrn
/ hs il ee u
d.ur(ISR ..,ti)
bqey"NET ." hs;
}.ac(ucinerr {
)cthfnto(ro)
/ Igtti!
/
o hs
};
)
HOW TO SEQ
IT'S A TRAP!
sq)sqfnto( {
e(.e(ucin)
d.ur(SLC ..,ti)
bqey"EET ." hs;
}.e(ucinrsls {
)sqfnto(eut)
sq)sqfnto( {
e(.e(ucin)
/ D smtig
/ o oehn
}.e(ucin){
)sqfnto(
/ D smtiges
/ o oehn le
/ Ti wntg t teotrSq
/ hs o' o o h ue e
ti(;
hs)
}.e(ucin){
)sqfnto(
/ Ti gt cle b acdn
/ hs es ald y ciet
};
)
}.e(ucinrsls {
)sqfnto(eut)
/ Ti wl nvrrn
/ hs il ee u
d.ur(ISR ..,ti)
bqey"NET ." hs;
};
)
SEQ 101
SAFE NESTING OF SEQ
sq)sqfnto( {
e(.e(ucin)
d.ur(SLC ..,ti)
bqey"EET ." hs;
}.e(ucinrsls {
)sqfnto(eut)
vrc =ti;/ ti( b ayohrnm.
a b
hs / hs) y n te ae.
sq)sqfnto( {
e(.e(ucin)
/ D smtig
/ o oehn
}.e(ucin){
)sqfnto(
/ D smtiges
/ o oehn le
/ Ti wntg t teotrSq
/ hs o' o o h ue e
c(;
b)
}.e(ucin){
)sqfnto(
/ Ti nvrgt cle
/ hs ee es ald
};
)
}.e(ucinrsls {
)sqfnto(eut)
/ Ti gt cle
/ hs es ald
d.ur(ISR ..,ti)
bqey"NET ." hs;
};
)
ADVANCED SEQ
vrf =rqie's)
a s
eur(f';
vree =rqie'hl_rcs'.xc
a xc
eur(cidpoes)ee;
vrSq=rqie'e';
a e
eur(sq)
Sq)
e(
.e(ucinse1){
sqfnto tp(
ee(wom' ti)
xc'hai, hs
}
)
.a(ucinse2wo {
prfnto tp(h)
ee(gop '+wo ti)
xc'rus
h, hs;
}
)
.a(ucinse3wo {
prfnto tp(h)
f.edie_flnm,'si' ti)
sraFl(_ieae aci, hs;
}
)
.e(ucinse4gop,sc {
sqfnto tp(rus r)
cnoelg'rus '+gop.rm);
osl.o(Gop:
rusti()
cnoelg'hsfl hs'+sclnt +'bts)
osl.o(Ti ie a
r.egh
ye';
}
)
;

Order of execution is as follows:

step1()
step2() and step3() are executed in parallel
step4() ONLY when step2() and step3() complete
EVEN MORE SEQ
Process an array of elements:
forEach()
seqEach()
parEach()
Play around with "this":
this.stack
this.vars
this.into(key)
this.args
Not for the faint of heart, and WAY beyond the scope of this
presentation.
FURTHER READING
The Seq repo:
https://github.com/substack/node-seq/
ON THE WEB
https://github.com/dmuth/nodejs-presentations
Feel free to clone and add your own presentations based off of
template.html!
QUESTIONS?

Presenting Seq for Node.js

  • 1.
  • 2.
    ABOUT ME Who Iam: Douglas Muth How to contact me: dmuth@dmuth.org / @dmuth What I do: Software Engineer ...mostly.
  • 3.
    THE PROBLEM Flow controlin node.js. Node.js is a callback-heavy language. Often, it looks like this: d.ur(SLC ..,fnto(ro,rsls { bqey"EET ." ucinerr eut) i (err { f !ro) d.ur(UDT ..,fnto(ro,rsls { bqey"PAE ." ucinerr eut) i (err { f !ro) d.ur(ISR ..,fnto(ro,rsls { bqey"NET ." ucinerr eut) / O Gd wy / h o, h? } } }; ) } }; ) Also known as "boomerang code"!
  • 4.
  • 5.
    SEQ 101 USAGE vrsq=rqie"e"; a e eur(sq) sq)sqfnto({ e(.e(ucin) d.ur(SLC ..,ti) bqey"EET ." hs; }.e(ucinrsls { )sqfnto(eut) d.ur(UDT ..,ti) bqey"PAE ." hs; }.e(ucinrsls { )sqfnto(eut) d.ur(ISR ..,ti) / Pet set bqey"NET ." hs; / rty we! }; ) "this()" is the callback which goes to the next block of code
  • 6.
    SEQ 101 WHEN THINGSGO WRONG sq)sqfnto( { e(.e(ucin) d.ur(SLC ..,ti) bqey"EET ." hs; }.e(ucinrsls { )sqfnto(eut) ti(e Err"hk tig u altl") hsnw ro(Sae hns p ite); }.e(ucinrsls { )sqfnto(eut) / Ti wl nvrrn / hs il ee u d.ur(ISR ..,ti) bqey"NET ." hs; }.ac(ucinerr { )cthfnto(ro) / Igtti! / o hs }; )
  • 7.
    HOW TO SEQ IT'SA TRAP! sq)sqfnto( { e(.e(ucin) d.ur(SLC ..,ti) bqey"EET ." hs; }.e(ucinrsls { )sqfnto(eut) sq)sqfnto( { e(.e(ucin) / D smtig / o oehn }.e(ucin){ )sqfnto( / D smtiges / o oehn le / Ti wntg t teotrSq / hs o' o o h ue e ti(; hs) }.e(ucin){ )sqfnto( / Ti gt cle b acdn / hs es ald y ciet }; ) }.e(ucinrsls { )sqfnto(eut) / Ti wl nvrrn / hs il ee u d.ur(ISR ..,ti) bqey"NET ." hs; }; )
  • 8.
    SEQ 101 SAFE NESTINGOF SEQ sq)sqfnto( { e(.e(ucin) d.ur(SLC ..,ti) bqey"EET ." hs; }.e(ucinrsls { )sqfnto(eut) vrc =ti;/ ti( b ayohrnm. a b hs / hs) y n te ae. sq)sqfnto( { e(.e(ucin) / D smtig / o oehn }.e(ucin){ )sqfnto( / D smtiges / o oehn le / Ti wntg t teotrSq / hs o' o o h ue e c(; b) }.e(ucin){ )sqfnto( / Ti nvrgt cle / hs ee es ald }; ) }.e(ucinrsls { )sqfnto(eut) / Ti gt cle / hs es ald d.ur(ISR ..,ti) bqey"NET ." hs; }; )
  • 9.
    ADVANCED SEQ vrf =rqie's) as eur(f'; vree =rqie'hl_rcs'.xc a xc eur(cidpoes)ee; vrSq=rqie'e'; a e eur(sq) Sq) e( .e(ucinse1){ sqfnto tp( ee(wom' ti) xc'hai, hs } ) .a(ucinse2wo { prfnto tp(h) ee(gop '+wo ti) xc'rus h, hs; } ) .a(ucinse3wo { prfnto tp(h) f.edie_flnm,'si' ti) sraFl(_ieae aci, hs; } ) .e(ucinse4gop,sc { sqfnto tp(rus r) cnoelg'rus '+gop.rm); osl.o(Gop: rusti() cnoelg'hsfl hs'+sclnt +'bts) osl.o(Ti ie a r.egh ye'; } ) ; Order of execution is as follows: step1() step2() and step3() are executed in parallel step4() ONLY when step2() and step3() complete
  • 10.
    EVEN MORE SEQ Processan array of elements: forEach() seqEach() parEach() Play around with "this": this.stack this.vars this.into(key) this.args Not for the faint of heart, and WAY beyond the scope of this presentation.
  • 11.
    FURTHER READING The Seqrepo: https://github.com/substack/node-seq/
  • 12.
    ON THE WEB https://github.com/dmuth/nodejs-presentations Feelfree to clone and add your own presentations based off of template.html!
  • 13.