Promisefy val

This commit is contained in:
sjones6
2017-08-30 21:04:14 -04:00
parent 3ec7d81f85
commit f92b9586c6
2 changed files with 30 additions and 0 deletions

10
lib/promise.js Normal file
View File

@@ -0,0 +1,10 @@
var Gun = Gun || require('../gun');
Gun.chain.promise = function(field) {
var gun = this;
return new Promise(function(resolve, reject) {
gun.get(field).val(function(node, key) {
resolve(node, key);
});
});
};

20
promise-test.js Normal file
View File

@@ -0,0 +1,20 @@
var Gun = require('./gun');
require('./lib/promise');
var gun = new Gun();
gun.get('mark').put({
name: 'mark'
})
async function getField(field) {
var node = await gun.promise(field);
console.log(node);
return node;
};
setTimeout(async () => {
var mark = await getField('mark');
console.log(mark);
process.exit();
}, 100);