UNPKG

722 BJavaScriptView Raw
1var outcome = require('../'),
2fs = require('fs')
3
4function doSomething(path, callback) {
5
6 //wrap the callback around an error handler so any errors in *this* function
7 //bubble back up to the callback - I'm lazy and I don't wanna write this stuff...
8 var on = outcome.error(callback);
9
10 //on success, call onRealPath. Any errors caught will be sent back
11 //automatically
12 fs.realpath(path, on.success(onRealPath));
13
14 function onRealPath(path) {
15
16 //ONLY call onStat if we've successfuly grabbed the file stats
17 fs.lstat(path, on.success(onStat));
18 }
19
20 function onStat(stats) {
21
22 //no errors, so send a response back
23 callback(null, stats);
24 }
25}
26
27doSomething(__dirname, function(err, result) {
28 console.log(result);
29})
\No newline at end of file