-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip writing empty (chained) batch and make callbacks asynchronous
- Loading branch information
Showing
2 changed files
with
62 additions
and
13 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
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,50 @@ | ||
// TODO: move to abstract-leveldown | ||
|
||
const test = require('tape') | ||
const testCommon = require('./common') | ||
|
||
test('test empty batch#write is asynchronous', function (t) { | ||
t.plan(4) | ||
|
||
const db = testCommon.factory() | ||
|
||
db.open(function (err) { | ||
t.ifError(err, 'no error from open()') | ||
|
||
let sync = true | ||
|
||
db.batch().write(function (err) { | ||
t.ifError(err, 'no error from write()') | ||
t.is(sync, false, 'callback is asynchronous') | ||
|
||
db.close(function (err) { | ||
t.ifError(err, 'no error from close()') | ||
}) | ||
}) | ||
|
||
sync = false | ||
}) | ||
}) | ||
|
||
test('test empty batch([]) is asynchronous', function (t) { | ||
t.plan(4) | ||
|
||
const db = testCommon.factory() | ||
|
||
db.open(function (err) { | ||
t.ifError(err, 'no error from open()') | ||
|
||
let sync = true | ||
|
||
db.batch([], function (err) { | ||
t.ifError(err, 'no error from batch()') | ||
t.is(sync, false, 'callback is asynchronous') | ||
|
||
db.close(function (err) { | ||
t.ifError(err, 'no error from close()') | ||
}) | ||
}) | ||
|
||
sync = false | ||
}) | ||
}) |