Skip to content

Commit

Permalink
Expose browser-compatible nextTick for dependents (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers authored Apr 3, 2020
1 parent 60ec6cd commit c31a01c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ Support of other key and value types depends on the implementation as well as it

## Private API For Implementors

Each of these methods will receive exactly the number and order of arguments described. Optional arguments will receive sensible defaults. All callbacks are error-first and must be asynchronous. If an operation within your implementation is synchronous, be sure to invoke the callback on a next tick using `process.nextTick(callback, ..)`, `setImmediate` or some other means of micro- or macrotask scheduling.

This comment was marked as off-topic.

Copy link
@juliasouzah836

juliasouzah836 Feb 2, 2021

API

Each of these methods will receive exactly the number and order of arguments described. Optional arguments will receive sensible defaults. All callbacks are error-first and must be asynchronous.

If an operation within your implementation is synchronous, be sure to invoke the callback on a next tick using `process.nextTick` or some other means of microtask scheduling. For convenience, the prototypes of `AbstractLevelDOWN`, `AbstractIterator` and `AbstractChainedBatch` include a `_nextTick` method that is compatible with node and browsers.

### `db = AbstractLevelDOWN([manifest])`

Expand Down
5 changes: 5 additions & 0 deletions abstract-chained-batch.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var nextTick = require('./next-tick')

function AbstractChainedBatch (db) {
if (typeof db !== 'object' || db === null) {
throw new TypeError('First argument must be an abstract-leveldown compliant store')
Expand Down Expand Up @@ -78,4 +80,7 @@ AbstractChainedBatch.prototype._write = function (options, callback) {
this.db._batch(this._operations, options, callback)
}

// Expose browser-compatible nextTick for dependents
AbstractChainedBatch.prototype._nextTick = nextTick

module.exports = AbstractChainedBatch
4 changes: 4 additions & 0 deletions abstract-iterator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var nextTick = require('./next-tick')

function AbstractIterator (db) {
if (typeof db !== 'object' || db === null) {
throw new TypeError('First argument must be an abstract-leveldown compliant store')
Expand Down Expand Up @@ -70,4 +71,7 @@ AbstractIterator.prototype._end = function (callback) {
nextTick(callback)
}

// Expose browser-compatible nextTick for dependents
AbstractIterator.prototype._nextTick = nextTick

module.exports = AbstractIterator
3 changes: 3 additions & 0 deletions abstract-leveldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,7 @@ AbstractLevelDOWN.prototype._checkValue = function (value) {
}
}

// Expose browser-compatible nextTick for dependents
AbstractLevelDOWN.prototype._nextTick = nextTick

module.exports = AbstractLevelDOWN
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"main": "index.js",
"browser": {
"./next-tick.js": "./next-tick.browser.js"
"./next-tick.js": "./next-tick-browser.js"
},
"scripts": {
"test": "standard && hallmark && nyc node test/self.js",
Expand Down

0 comments on commit c31a01c

Please sign in to comment.