then.js 430 B

12345678910111213141516
  1. var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
  2. Gun.chain.promise = function(cb) {
  3. var gun = this, cb = cb || function(ctx) { return ctx };
  4. return (new Promise(function(res, rej) {
  5. gun.once(function(data, key){
  6. res({put: data, get: key, gun: this});
  7. });
  8. })).then(cb);
  9. };
  10. Gun.chain.then = function(cb) {
  11. return this.promise(function(res){
  12. return cb? cb(res.put) : res.put;
  13. });
  14. };