add: wait for once, so data is returned on first get (#6)

* add: wait for once, so data is returned on first get

* Update then.js
This commit is contained in:
sirpy 2019-12-08 17:49:48 +02:00 committed by GitHub
parent 29ed57e955
commit 512d2c8c32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

7
sea.js
View File

@ -710,9 +710,10 @@
;USE(function(module){
var Gun = USE('./sea').Gun;
Gun.chain.then = function(cb){
Gun.chain.then = function(cb, opt = {}){
opt = {wait: 200, ...opt}
var gun = this, p = (new Promise(function(res, rej){
gun.once(res);
gun.once(res, opt);
}));
return cb? p.then(cb) : p;
}
@ -1336,4 +1337,4 @@
// TODO: Potential bug? If pub/priv key starts with `-`? IDK how possible.
})(USE, './index');
}());
}());

View File

@ -1,9 +1,10 @@
var Gun = require('./sea').Gun;
Gun.chain.then = function(cb){
Gun.chain.then = function(cb, opt = {}){
opt = {wait: 200, ...opt}
var gun = this, p = (new Promise(function(res, rej){
gun.once(res);
gun.once(res, opt);
}));
return cb? p.then(cb) : p;
}