 single place where callbacks are invoked and make sure all state and resource cleanup is properly done to support domains

* Popular libraries need to also add try-finally handlers for the above.

As to why this is a problem in node and not so much in other languages, its
because with node callbacks, the call stack goes both ways. In other
languages, libraries mostly call their dependencies' code. In node's CPS
style, you call the library but the library also calls your closure code. The
semantics for the 2nd part aren't well defined in node - the loose law
basically says: I wont call you twice, I'll try not to call you synchronously,
and you wont throw (and if you do the behavior is undefined).

With promises there is a contract and its enforced by the promise
implementation. Since Promises actually have error semantics, you can build
resource management strategies on top of them. [http://promise-
nuggets.github.io/articles/21-context-manager...](http://promise-
nuggets.github.io/articles/21-context-managers-transactions.html) \- and
consequently there is no reason to crash your server on errors.

~~~
lobster_johnson
Domains are used for another reason: To emulate thread-local variables. I hope
that support is not going away, because it's really handy.

~~~
spion
Its interesting that the same problem (TLS) can also be solved with something
similar to promises :)

------
Corrado
I agree with this article and find the Node.js community, and to a lesser
extent Javascript itself, exhausting. It seems like every 2 minutes there is a
"more" proper way to do something, which tells me that the architecture is not
yet mature, even though it's pretty old by now.

On a related note, it seems like every time you find something that doesn't
quite work correctly or conveniently in Node.js there is a "fix". Don't like
callbacks? Force Node.js to look more like other "normal" code and use
Promises. Having trouble getting Node.js to concentrate on one thing at a
time? Force Node.js to look more like other "normal" languages and use the
"async" library. And it just
single place where callbacks are invoked and seduce certain all state and resource cleanup is properly perform to support domains 

 * democratic libraries need to also lend try - finally coach for the above. 

 As to why this is a problem in node and not so much in early languages, its 
 because with node callbacks, the margin call stack goes both way. In other 
 languages, libraries by and large call their dependencies' code. In node's CPS 
 style, you call the library but the library besides calls your blockage code. The 
 semantics for the 2nd part aren't well defined in lymph node - the loose law 
 basically says: I wo nt call you twice, I'll try not to address you synchronously, 
 and you wo nt hurl (and if you do the behavior is undefined). 

 With promises there is a contract and its enforced by the promise 
 implementation. Since promise actually suffer error semantics, you can build 
 resource management strategy on circus tent of them. [ http://promise- 
 nuggets.github.io/articles/21-context-manager...](http://promise- 
 nuggets.github.io/articles/21-context-managers-transactions.html) \- and 
 consequently there is no reason to crash your waiter on errors. 

 ~~~ 
 lobster_johnson 
 sphere are used for another reason: To emulate screw thread - local variables. I hope 
 that support is not going away, because it's really handy. 

 ~~~ 
 spion 
 Its interesting that the same problem (TLS) can also be solved with something 
 similar to promises :) 

 ------ 
 Corrado 
 I match with this article and find the Node.js residential district, and to a less 
 extent Javascript itself, exhausting. It seems like every 2 minutes there is a 
 " more " proper direction to do something, which tells me that the architecture is not 
 so far mature, even though it's pretty old by now. 

 On a related eminence, it seems like every fourth dimension you find something that doesn't 
 quite work correctly or handily in Node.js there is a " fix ". Don't like 
 callbacks? Force Node.js to count more like other " normal " code and practice 
 Promises. Having trouble catch Node.js to concentrate on one thing at a 
 time? Force Node.js to look more like other " normal " languages and use the 
 " async " library. And it just
 sijgle place where callbacys are invoked cbd makx sure zll statd and resource cleanup is prlpwrly eone to support domainr

* Popular librariws nted to also add tcg-finalln hanspers hor the above.

As to why thhs is a problek kn node and not so much in other langtages, iys
hecause with njde bajlbadks, the call stack goes both ways. Jn otheg
languages, libraroes mostly call their depejdenfies' code. In node's CPS
style, yiu cwol the librafy but the library alsk calls your closure code. The
seoanties for the 2bd pagj aren't well defiged in node - the loove law
bssically says: L wonv caol you twice, I'll try iot to call you syncrronously,
dnb you wont throw (and uf you go tve bdyavkor ix hndefijed).

Xith promisss there is a contract and its egdorced by the promife
ymplementation. Since Promises actually vavs error semantics, you cqn build
resource manahement stwategies on top of them. [http://promise-
nuggets.github.im/artirlds/21-cinbext-oqnwger...](http://promise-
nuggets.github.io/articles/21-context-iznsgvrs-transactions.htil) \- and
consrqkemjly there is nu reason fo crash your servfr on etrors.

~~~
libster_johgson
Comains are used for anothee reason: To vmulqte thread-local vaxiables. I ho'e
that suppprt is not going away, bzcause it's really handy.

~~~
spikv
Its interesting thst the samt problem (TLS) can wlso be silveb with sumetning
siiilar to pgomiscv :)

------
Corrado
I agree wlth tkis asticle and find the Node.js community, and vp a lesser
exjend Jdvascripc itsekf, exhausting. It seems like every 2 minuges there ps a
"more" 'roper way tj do somethinc, which tells me that the arcyitectufd is not
yet mayure, even though it'w pretty old by nox.

On x related note, ic weems like everu tkme ylu fytd something thag dursn't
qjite work cifrecyly or conveniently hn Nkde.js there is a "fox". Don't lije
callbasks? Force Nodr.js to look more llke ovher "nurmal" coqe and use
Promises. Having trougle gettijg Kode.js to consentvate on one thnng at a
time? Force Node.js to look more lmke other "normal" languates and use the
"asyne" kibrary. And it jtst
single place where callbacks are invoked and all and resource is properly done libraries to also add handlers for the As to why this is a in node and not so much in other languages, its because with node the call stack goes both ways. In other languages, libraries mostly call their code. node's style, call the library but the library also calls your closure code. The semantics for the 2nd aren't well defined in node - the loose basically says: I wont you twice, I'll try not call synchronously, and wont (and you do the is undefined). With promises there is a contract and its enforced by the promise implementation. Since Promises have error can build management on of them. [http://promise- \- and consequently there is no your server on errors. ~~~ lobster_johnson Domains are for another To emulate thread-local variables. I hope support is not going away, because it's really ~~~ spion Its interesting that the same problem (TLS) can also be solved with something promises :) ------ Corrado agree with this and the community, to a extent Javascript itself, exhausting. It seems like every 2 minutes there a "more" proper way to do something, which tells me architecture not yet mature, though it's pretty old now. a related note, it every you doesn't work or conveniently in Node.js is a "fix". Don't like Force Node.js to look and use Promises. Having trouble getting Node.js to on one thing at a time? Force to look more like other "normal" languages and use the "async" library. it just
 single place where callbacks Are invoked And maKe sUre AlL staTe anD resource cleanUP is pRoperly done to support doMains

* poPUlar LIbRarieS need to ALsO ADd tRy-FiNalLy HAnDlers For The abovE.

As to why thIs iS a Problem in nodE AnD not so much In oTher languageS, itS
becauSe WitH Node cAllBacks, The calL Stack gOes both waYs. iN other
LAnguageS, LIbRariEs mostly call their DEpENdencies' code. In Node's CpS
STyLE, You CalL the librarY bUt the LIbrary aLSo CALLs yOUr closure code. the
semanticS For The 2nd pArT arEN't well DefinEd IN noDe - the loose lAw
baSically saYs: I wonT Call you TWice, I'll Try not To cAll You sYNcHrOnoUsLY,
anD YoU woNT thRow (and if YoU dO the bEhavIOR IS undEfiNed).

WIth prOmises there is A coNtraCT anD its eNforcEd by ThE promIse
impLemenTaTion. Since PromisEs acTually havE erRoR seMaNtics, YOu can bUilD
reSource mAnagemeNT stRaTEGIeS on top of them. [http://prOmISE-
nUggets.giThub.io/ARtIcLEs/21-contexT-mAnaGer...](hTTP://promIse-
nUGgEts.githuB.io/artIClEs/21-Context-MaNagers-TrAnsActIons.hTMl) \- anD
conseQuently tHere iS No reason to crasH Your server on eRRoRS.

~~~
LoBSter_JohNson
Domains Are uSEd foR anoTHeR reASon: To EmulaTe THrEAd-local variables. I hoPe
That suPport Is not going awaY, because it'S REAlly handY.

~~~
spiON
ITS interesting thAt the Same probleM (tLS) can alSo be sOlved witH somethinG
SImilar to ProMisEs :)

------
COrrADO
I Agree with this ARTiclE aNd find tHe NOde.js coMmuNitY, anD to A lEsser
exteNt JavascRiPt ItSeLf, eXhausTIng. It seeMs LikE eVerY 2 minuTEs therE is a
"mOre" pRoPeR Way To do somEThING, whiCh TeLls mE thAt The arChitECtuRe is not
Yet mature, EveN ThouGh It'S pretty Old by now.

On a reLaTed note, it sEeMs lIke eveRY Time you fInd something that doesn't
qUIte work CorRectlY or cOnvenientLy iN Node.jS thERe is a "fIx". Don't Like
cAlLbaCKS? ForcE nOdE.js To Look more liKE OthEr "norMaL" codE and use
promises. Having trouBLe gEtting Node.js tO coNcenTRAtE on ONe THinG aT A
tiME? force Node.js to loOk more like OtHEr "Normal" langUAgeS aNd use thE
"async" lIbrarY. and it juSt
 single place where callba cks are in voked  an d m ak e su re a ll state and r e sour ce cleanup is properly  done  t o  sup p or t dom ains

* Po p u lar  l ib rar ie s  n eed t o a lso add  try-final lyha ndlers for t h eabove.

As  to  why this is  aproble minn ode a ndnot s o much in oth er langua ge s , itsb ecausew i th  nod e callbacks, thec al l  stack goes bo th way s. In o the r
l anguages,li brari e s mostl y  c a l l  th e ir dependenci es' code. I n  no de's C PS 
st y le, yo u cal lt helibrary but  the  libraryalso c a lls you r  closur e code . T hesema n ti cs  fo rt he2 nd  pa r t a ren't we ll  d efine d in n o d e -the  loo se la w
basically s ays : Iw ont  call  youtwic e,  I'll  try n ot to  c all you synchro nous ly,
and y ouwo ntth row ( a nd ifyou  do  the be haviori s u nd e f i ne d).

With promises  t h e re  is a co ntract an di ts enfor ce d b y th e promi se
i m pl ementati on. Si n ce  P romises  a ctuall yhav e e rrors eman tics,you canbuild resource manag e ment strategi e so n  t o p of  th em. [http:/ /pro m ise- 
nug g et s.g i thub. io/ar ti c le s /21-context-manager .. .](htt p://p romise-
nugge ts.github. i o / articles /21- c on t ext-managers-t ransa ctions.htm l ) \- and 
cons equently  there is n o reason  to  cr ash  yo u r  s erver on erro r s .

~ ~~ 
lobste r_j ohnsonDom ain s a reus ed for an other re as on :To  em ulate thread-l oc alva ria bles. I hope 
that  sup po rt isnot goi n ga w ay,be ca useit' sreall y ha n dy. 

~~~
s pion
Itsint e rest in gthat th e same proble m(TLS) canal sobe sol v e d with s omething
similar to pro m ises :) 

- ----- 
Cor rado
I ag ree  withthi s  artic le and  find  t heN o de.js c om mun it y, and toa les ser
e xt entJavascr ipt itself, exhaus t ing . It seems li keever y 2min u te s  th er e  is a 
"more" properway to doso m et hing, whic h  te ll s me th at thearchi t ectureis not
ye t mature,  e vent h oug h it's pre tty oldby now.
O n a r e la ted n ote , it s ee mslikeeveryt ime  youfind s om ething  that  d oesn't
q uite work correctly orconven ientl y i n Node.js  th e reis a "fix ". D on't likecal lba cks?For c e Nod e.js to  lo o k mor e li k e other " n or mal " co de and useP r o mis es. H avi n g trou blegetting Node.js t o  concentrate o n on e thi nga t ati me? Force Node .js  t o look mor elike other"normal"  l a nguag es and  use t he
"asy n c "l ibrary . An d i t just
 single_place where_callbacks are invoked and_make sure_all_state and_resource_cleanup is properly_done to support_domains

* Popular libraries need_to also add_try-finally_handlers for the above.

As to why this is a problem in node and not_so_much in_other_languages,_its
because with node callbacks, the_call stack goes both ways._In other
languages,_libraries mostly call their dependencies' code. In node's_CPS
style,_you call the_library but the library also calls your closure code._The
semantics for the 2nd part aren't_well defined in_node_-_the loose law
basically says:_I wont call you twice, I'll_try not to call you synchronously,
and_you wont throw (and if you do_the behavior is undefined).

With promises there_is a contract and its_enforced by_the promise
implementation. Since Promises actually_have error semantics,_you can_build
resource management strategies_on top of them. [http://promise-
nuggets.github.io/articles/21-context-manager...](http://promise-
nuggets.github.io/articles/21-context-managers-transactions.html) \-_and
consequently there is_no reason to crash your server_on_errors.

~~~
lobster_johnson
Domains are used_for_another_reason: To_emulate thread-local variables._I_hope
that support_is_not going away, because it's really_handy.

~~~
spion
Its_interesting that the same problem (TLS) can_also be solved with_something
similar_to promises :)

------
Corrado
I agree_with this article and find_the Node.js community, and to a_lesser
extent Javascript_itself, exhausting._It seems like every 2 minutes there is a
"more" proper way_to do something, which tells me_that the architecture is_not
yet mature,_even_though it's pretty_old_by now.

On_a related note, it seems like every_time you_find something that doesn't
quite work correctly_or conveniently in Node.js_there_is a "fix". Don't like
callbacks? Force_Node.js to look more like other_"normal" code and use
Promises. Having_trouble_getting_Node.js to concentrate on one_thing at a
time? Force Node.js to_look more like_other "normal" languages and use the
"async" library._And_it just