Created
May 17, 2013 15:13
-
-
Save kylegetson/5599722 to your computer and use it in GitHub Desktop.
get or set example
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
var levelup = require('levelup'); | |
var db = levelup('./mydb', {cacheSize: 0}); | |
function getOrSet(num){ | |
if( num == 0 ) return; | |
var hash = num.toString(); | |
db.get(hash, function(err,result){ | |
if( err ){ | |
db.put(hash, num, function(){ | |
return getOrSet(--num); | |
}); | |
return; | |
} | |
return getOrSet(--num); | |
}); | |
} | |
getOrSet(500000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment