Skip to content

Instantly share code, notes, and snippets.

@canonic-epicure
Created May 27, 2010 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save canonic-epicure/416053 to your computer and use it in GitHub Desktop.
Save canonic-epicure/416053 to your computer and use it in GitHub Desktop.
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