Message from discussion
fibers 0.5; say "no" callbacks (when it makes sense in your application)
Received: by 10.58.218.102 with SMTP id pf6mr3261404vec.36.1352523697197;
Fri, 09 Nov 2012 21:01:37 -0800 (PST)
X-BeenThere: nodejs@googlegroups.com
Received: by 10.220.219.69 with SMTP id ht5ls5514681vcb.7.gmail; Fri, 09 Nov
2012 21:01:23 -0800 (PST)
Received: by 10.52.72.133 with SMTP id d5mr2750095vdv.16.1352523683346;
Fri, 09 Nov 2012 21:01:23 -0800 (PST)
Date: Fri, 9 Nov 2012 21:01:22 -0800 (PST)
From: Alexey Petrushin <alexey.petrus...@gmail.com>
To: nodejs@googlegroups.com
Message-Id: <2ec1b76b-181d-47c4-9416-138dfd754277@googlegroups.com>
In-Reply-To: <1a255cb4-eb9d-4faf-8773-837d98570c7c@googlegroups.com>
References: <CAPgQht0NsofhjKOHqyQm879BzcaubT3ow8uEfpEcb1ZDsuOi_g@mail.gmail.com>
<30865de6-de86-4aa2-8c99-6039c1baec3b@googlegroups.com>
<1a255cb4-eb9d-4faf-8773-837d98570c7c@googlegroups.com>
Subject: Re: fibers 0.5; say "no" callbacks (when it makes sense in your
application)
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_1481_16650298.1352523682775"
------=_Part_1481_16650298.1352523682775
Content-Type: multipart/alternative;
boundary="----=_Part_1482_17505887.1352523682781"
------=_Part_1482_17505887.1352523682781
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Error handling with callbacks is especially interesting, try this code -
the 'Surprise' error won't be caught.
// Catching synchronous errors.
try {
myFunction(function(err){
// Catching asynchronous errors.
if(err) return console.log('error catched')
console.log('no errors')
})
} catch(err) {
console.log('error catched')
}
var myFunction = function(cb){
setTimeout(function(){
someFunctionDeepInLibrary(cb)
}, 100)
}
var someFunctionDeepInLibrary = function(cb){
throw new Error("Surprise!")
}
Live version (open console to see the result) http://tinkerbin.com/axnxQte5
------=_Part_1482_17505887.1352523682781
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Error handling with callbacks is especially interesting, try this code - th=
e 'Surprise' error won't be caught. <div><div><br></div><div><div=
> // Catching synchronous errors.</div><div> try =
{</div><div> myFunction(function(err){</div><div> =
// Catching asynchronous errors.</div><div> &nb=
sp; if(err) return console.log('error catched')</div><div>&nb=
sp; console.log('no errors')</div><div> &=
nbsp; })</div><div> } catch(err) {</div><div> &nb=
sp; console.log('error catched')</div><div> }</div><div><br></=
div><div> var myFunction =3D function(cb){</div><div> &n=
bsp; setTimeout(function(){</div><div> so=
meFunctionDeepInLibrary(cb)</div><div> }, 100)<span cla=
ss=3D"Apple-tab-span" style=3D"white-space:pre">=09=09</span></div><div>&nb=
sp; }</div><div><br></div><div> var someFunctionDeepInL=
ibrary =3D function(cb){</div><div> throw new Error("Su=
rprise!")</div><div> }</div></div><div><br></div><div>Live ver=
sion (open console to see the result) http://tinkerbin.com/axnxQte5</d=
iv></div>
------=_Part_1482_17505887.1352523682781--
------=_Part_1481_16650298.1352523682775--