diff --git a/README.md b/README.md index dde37dc..3bcdbae 100644 --- a/README.md +++ b/README.md @@ -91,10 +91,14 @@ server.get(route, (req, res) => { _Inserts a tracker into the vault._ +Returns: Result of update function (use await for async updates). + ### .trigger(key) _Manually runs a tracker._ +Returns: Result of update function (use await for async updates). + ### .prototype As `unvault` extends [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map), all of its functions are available: `clear()`, `delete(key)`, `entries()` and more! diff --git a/lib/index.js b/lib/index.js index 05532ec..80a1c4d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -6,9 +6,9 @@ class Unvault extends Map { * @param {function} update * @param {object} options */ - insert(key, interval, update, options) { + async insert(key, interval, update, options) { this.set(key, { interval, update, ...options }); - this.trigger(key, interval !== 0); + return this.trigger(key, interval !== 0); } /** @@ -37,6 +37,7 @@ class Unvault extends Map { this.trigger(key, automated); }, tracker.interval); } + return value; } } diff --git a/package.json b/package.json index 6b095de..ca59e27 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unvault", - "version": "0.3.0", + "version": "0.4.0", "description": "A minimal layer for node that allows results of time-consuming tasks to be stored.", "repository": "vaneenige/unvault", "main": "lib/index.js",