-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6461abc
Showing
9 changed files
with
409 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/node_modules | ||
/npm-debug.* | ||
/components | ||
/bower_components | ||
.DS_Store | ||
/tmp | ||
/test/coverage |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{ | ||
"disallowKeywordsOnNewLine": [ | ||
"else", | ||
"catch" | ||
], | ||
"disallowMixedSpacesAndTabs": true, | ||
"disallowSpacesInCallExpression": true, | ||
"disallowSpacesInFunctionDeclaration": { | ||
"beforeOpeningRoundBrace": true | ||
}, | ||
"disallowTrailingComma": true, | ||
"disallowTrailingWhitespace": true, | ||
"excludeFiles": [ | ||
"bower_components/**", | ||
"node_modules/**" | ||
], | ||
"fileExtensions": [ | ||
".js", | ||
"jscs" | ||
], | ||
"requireCommaBeforeLineBreak": true, | ||
"requireCurlyBraces": [ | ||
"if", | ||
"else", | ||
"for", | ||
"while", | ||
"do", | ||
"try", | ||
"catch" | ||
], | ||
"requireSpaceAfterBinaryOperators": true, | ||
"requireSpaceAfterKeywords": [ | ||
"if", | ||
"else", | ||
"for", | ||
"while", | ||
"do", | ||
"switch", | ||
"return", | ||
"try", | ||
"catch", | ||
"function" | ||
], | ||
"requireSpaceBeforeBinaryOperators": [ | ||
"=", | ||
"+=", | ||
"-=", | ||
"*=", | ||
"/=", | ||
"%=", | ||
"<<=", | ||
">>=", | ||
">>>=", | ||
"&=", | ||
"|=", | ||
"^=", | ||
"+=", | ||
"+", | ||
"-", | ||
"*", | ||
"/", | ||
"%", | ||
"<<", | ||
">>", | ||
">>>", | ||
"&", | ||
"|", | ||
"^", | ||
"&&", | ||
"||", | ||
"===", | ||
"==", | ||
">=", | ||
"<=", | ||
"<", | ||
">", | ||
"!=", | ||
"!==" | ||
], | ||
"requireSpaceBeforeBlockStatements": true, | ||
"requireSpaceBeforeKeywords": [ | ||
"else" | ||
], | ||
"requireSpaceBeforeObjectValues": true, | ||
"requireSpacesInConditionalExpression": true, | ||
"requireSpacesInFunctionExpression": { | ||
"beforeOpeningCurlyBrace": true, | ||
"beforeOpeningRoundBrace": true | ||
}, | ||
"requireSpacesInsideObjectBrackets": "allButNested", | ||
"validateIndentation": 4, | ||
"validateParameterSeparator": ", ", | ||
"validateQuoteMarks": "'" | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
{ | ||
"predef": [ | ||
"console", | ||
"Intl", | ||
"describe", | ||
"it", | ||
"before", | ||
"beforeEach", | ||
"after", | ||
"afterEach" | ||
], | ||
|
||
"node": true, | ||
"devel": true, | ||
|
||
"bitwise": true, | ||
"curly": true, | ||
"eqeqeq": false, | ||
"forin": false, | ||
"immed": true, | ||
"latedef": false, | ||
"newcap": true, | ||
"noarg": true, | ||
"noempty": false, | ||
"nonew": true, | ||
"plusplus": false, | ||
"regexp": true, | ||
"undef": true, | ||
"unused": true, | ||
"quotmark": "single", | ||
"strict": true, | ||
"trailing": true, | ||
|
||
"asi": false, | ||
"boss": false, | ||
"debug": false, | ||
"eqnull": true, | ||
"esnext": false, | ||
"evil": false, | ||
"expr": true, | ||
"funcscope": false, | ||
"globalstrict": false, | ||
"iterator": false, | ||
"lastsemic": false, | ||
"laxbreak": false, | ||
"laxcomma": false, | ||
"loopfunc": true, | ||
"multistr": true, | ||
"onecase": true, | ||
"regexdash": false, | ||
"scripturl": false, | ||
"smarttabs": false, | ||
"shadow": false, | ||
"sub": false, | ||
"supernew": false, | ||
"validthis": false, | ||
|
||
"nomen": false, | ||
"onevar": false, | ||
"white": true | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# level-atomics | ||
|
||
Atomic operators for leveldb | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
'use strict'; | ||
|
||
var isArray = require('util').isArray; | ||
var Lock = require('lock'); | ||
var async = require('async'); | ||
|
||
var kvOps = {}; | ||
|
||
function wrap(db) { | ||
// mix in the methods | ||
for (var k in kvOps) { | ||
db[k] = kvOps[k]; | ||
} | ||
|
||
db._lock = new Lock(); | ||
|
||
return db; | ||
} | ||
|
||
// kvOps.append = function (keys, fragment, callback) { | ||
|
||
// }; | ||
|
||
kvOps.counter = function (keys, delta, options, callback) { | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
|
||
var tasks = {}; | ||
|
||
_array(keys).forEach(function (key) { | ||
tasks[key] = __lockAndGet.bind(null, this, key, options, function __handle(value, callback) { | ||
// console.log('locked:', key); | ||
// if no value, use 0 as initial | ||
if (value === undefined) { | ||
value = 0; | ||
} | ||
|
||
var newValue = value + delta; | ||
|
||
this.put(key, newValue, options, function __handlePut(err) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
|
||
return callback(null, newValue); | ||
}); | ||
}.bind(this)); | ||
}.bind(this)); | ||
|
||
async.parallel(tasks, callback); | ||
}; | ||
|
||
// kvOps.get = function (keys, options, callback) { | ||
|
||
// }; | ||
|
||
kvOps.insert = function (tuples, options, callback) { | ||
|
||
}; | ||
|
||
// kvOps.prepend = function (keys, fragment, callback) { | ||
|
||
// }; | ||
|
||
kvOps.replace = function (tuples, options, callback) { | ||
|
||
}; | ||
|
||
// ----------------------------------------------------------------------------- | ||
|
||
function __lockAndGet(db, key, options, handler, callback) { | ||
// console.log('locking:', key); | ||
db._lock(key, function __handleLock(release) { | ||
// console.log('obtained lock:', key); | ||
db.get(key, options, function __handleGet(err, value) { | ||
// console.log('__handleGet', arguments); | ||
if (err) { | ||
if (!err.notFound) { | ||
return callback(err); | ||
} else { | ||
value = undefined; | ||
} | ||
} | ||
|
||
return handler(value, release(callback)); | ||
}); | ||
}); | ||
} | ||
|
||
function _array(x) { | ||
return isArray(x) ? x : [x]; | ||
} | ||
|
||
module.exports = wrap; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "node-level-atomics", | ||
"version": "1.0.0", | ||
"description": "Atomic operators for leveldb", | ||
|
||
"main": "index.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"scripts": { | ||
"test": "mocha", | ||
"test-cov": "istanbul cover --dir test/coverage _mocha && echo open test/coverage/lcov-report/index.html", | ||
"test-reload": "nodemon -w ./ -x \"npm t\"" | ||
}, | ||
"author": "Marco Oliveira", | ||
"keywords": [ | ||
"level", | ||
"leveldb", | ||
"level-db", | ||
"increment", | ||
"decrement", | ||
"counter", | ||
"count", | ||
"lock", | ||
"replace", | ||
"insert" | ||
], | ||
"license": "MIT" | ||
} |
Oops, something went wrong.