Created
May 27, 2010 16:59
-
-
Save canonic-epicure/416053 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class('DataStore.Async', { | |
trait : JooseX.CPS, | |
continued : { | |
methods : { | |
log : function () { | |
var resultFromLog = // somehow get the response from logging operation | |
this.CONTINUE(resultFromLog) | |
return whatever | |
}, | |
save : function (data) { | |
this.log().then(function (resultFromLog) { | |
var CONT = this.CONT | |
require('fs').saveFile('filename.txt', data, function (err, written) { | |
if (err) { | |
CONT.THROW(err) | |
return | |
} | |
CONT.CONTINUE(written) | |
}) | |
}).now() | |
} | |
} | |
} | |
}) | |
var store = new DataStore.Async | |
store.save('some data').then(function (written) { | |
// do smth | |
}).CATCH(function (exception) { | |
// do smth | |
}).FINALLY(function () { | |
// do smth | |
}).now() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment