Skip to content

Instantly share code, notes, and snippets.

@Marak
Created February 25, 2010 02:45
Show Gist options
  • Select an option

  • Save Marak/314169 to your computer and use it in GitHub Desktop.

Select an option

Save Marak/314169 to your computer and use it in GitHub Desktop.
application.start = function(){
//load data.json into application state
var x = posix.open(application.dataPath,process.O_CREAT|process.O_WRONLY|process.O_EXCL,0444).addCallback(function(fd){
debug.log('new datastore created');
});
var boot = posix.cat( application.dataPath ).addCallback(function (applicationState) {
//debug.log(JSON.stringify(applicationState));
/* try to evaluate application state into memory */
try {
eval( applicationState )
}
catch(err){
debug.log( 'applicationState failed to evaluate : ' + JSON.stringify(err) )
}
});
};
application.saveState = function(shutdown){
debug.log('application saveState');
//dump data.json into application state
var mode = 0444;
var x = posix.open(application.dataPath ,process.O_RDWR|process.O_TRUNC,0444).addCallback(function(fd){
debug.log('opening : ' + application.dataPath);
/* open and write */
posix.write( fd, 'application.data = ' + JSON.stringify( application.data ) + ';' ).addCallback(function(){
debug.log('application state serialized and stored in : ' + application.dataPath);
posix.close(fd).addCallback(function () {
if (shutdown) {
process.exit();
}
});
}).addErrback(function(err){debug.log('file write error' + JSON.stringify( application.data ));});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment