implement whisper stop watch; add callback so sendMessage become async

This commit is contained in:
Iuri Matias 2017-01-26 06:31:29 -05:00
parent 2928694b76
commit 9d2f9c3054
2 changed files with 30 additions and 34 deletions

View File

@ -45,7 +45,8 @@ var EmbarkJS =
/* 0 */
/***/ function(module, exports, __webpack_require__) {
var Promise = __webpack_require__(1);
/*jshint esversion: 6 */
var Promise = __webpack_require__(1); // jshint ignore: line
//var Ipfs = require('./ipfs.js');
var EmbarkJS = {
@ -282,6 +283,7 @@ var EmbarkJS =
var identity = options.identity || this.identity || web3.shh.newIdentity();
var ttl = options.ttl || 100;
var priority = options.priority || 1000;
var _topics;
if (topics === undefined) {
throw new Error("missing option: topic");
@ -296,7 +298,6 @@ var EmbarkJS =
_topics = [web3.fromAscii(topics)];
} else {
// TODO: replace with es6 + babel;
var _topics = [];
for (var i = 0; i < topics.length; i++) {
_topics.push(web3.fromAscii(topics[i]));
}
@ -313,17 +314,17 @@ var EmbarkJS =
priority: priority
};
return web3.shh.post(message);
return web3.shh.post(message, function() {});
};
EmbarkJS.Messages.Whisper.listenTo = function(options) {
var topics = options.topic || options.topics;
var _topics = [];
if (typeof topics === 'string') {
_topics = [topics];
} else {
// TODO: replace with es6 + babel;
var _topics = [];
for (var i = 0; i < topics.length; i++) {
_topics.push(topics[i]);
}
@ -346,6 +347,10 @@ var EmbarkJS =
return err;
};
messageEvents.prototype.stop = function() {
this.filter.stopWatching();
};
var promise = new messageEvents();
var filter = web3.shh.filter(filterOptions, function(err, result) {
@ -364,6 +369,8 @@ var EmbarkJS =
}
});
promise.filter = filter;
return promise;
};
@ -471,7 +478,7 @@ var EmbarkJS =
*
*/
/**
* bluebird build version 3.4.6
* bluebird build version 3.4.7
* Features enabled: core, race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, using, timers, filter, any, each
*/
!function(e){if(true)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Promise=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof _dereq_=="function"&&_dereq_;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof _dereq_=="function"&&_dereq_;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
@ -626,11 +633,6 @@ var EmbarkJS =
};
}
Async.prototype.invokeFirst = function (fn, receiver, arg) {
this._normalQueue.unshift(fn, receiver, arg);
this._queueTick();
};
Async.prototype._drainQueue = function(queue) {
while (queue.length() > 0) {
var fn = queue.shift();
@ -1410,6 +1412,7 @@ var EmbarkJS =
Promise.prototype._fireEvent = defaultFireEvent;
}
}
return Promise;
};
function defaultFireEvent() { return false; }
@ -1680,7 +1683,7 @@ var EmbarkJS =
break;
}
}
if (i > 0) {
if (i > 0 && error.name != "SyntaxError") {
stack = stack.slice(i);
}
return stack;
@ -1693,7 +1696,7 @@ var EmbarkJS =
? stackFramesAsArray(error) : [" (No stack trace)"];
return {
message: message,
stack: cleanStack(stack)
stack: error.name == "SyntaxError" ? stack : cleanStack(stack)
};
}
@ -3911,7 +3914,7 @@ var EmbarkJS =
_dereq_("./join")(
Promise, PromiseArray, tryConvertToPromise, INTERNAL, async, getDomain);
Promise.Promise = Promise;
Promise.version = "3.4.6";
Promise.version = "3.4.7";
_dereq_('./map.js')(Promise, PromiseArray, apiRejection, tryConvertToPromise, INTERNAL, debug);
_dereq_('./call_get.js')(Promise);
_dereq_('./using.js')(Promise, apiRejection, tryConvertToPromise, createContext, INTERNAL, debug);
@ -4601,23 +4604,6 @@ var EmbarkJS =
this._length = length + 1;
};
Queue.prototype._unshiftOne = function(value) {
var capacity = this._capacity;
this._checkCapacity(this.length() + 1);
var front = this._front;
var i = (((( front - 1 ) &
( capacity - 1) ) ^ capacity ) - capacity );
this[i] = value;
this._front = i;
this._length = this.length() + 1;
};
Queue.prototype.unshift = function(fn, receiver, arg) {
this._unshiftOne(arg);
this._unshiftOne(receiver);
this._unshiftOne(fn);
};
Queue.prototype.push = function (fn, receiver, arg) {
var length = this.length() + 3;
if (this._willBeOverCapacity(length)) {
@ -5978,8 +5964,11 @@ var EmbarkJS =
var isNode = typeof process !== "undefined" &&
classString(process).toLowerCase() === "[object process]";
function env(key, def) {
return isNode ? process.env[key] : def;
var hasEnvVariables = typeof process !== "undefined" &&
typeof process.env !== "undefined";
function env(key) {
return hasEnvVariables ? process.env[key] : undefined;
}
function getNativePromise() {
@ -6027,6 +6016,7 @@ var EmbarkJS =
hasDevTools: typeof chrome !== "undefined" && chrome &&
typeof chrome.loadTimes === "function",
isNode: isNode,
hasEnvVariables: hasEnvVariables,
env: env,
global: globalObject,
getNativePromise: getNativePromise,

View File

@ -267,12 +267,12 @@ EmbarkJS.Messages.Whisper.sendMessage = function(options) {
priority: priority
};
return web3.shh.post(message);
return web3.shh.post(message, function() {});
};
EmbarkJS.Messages.Whisper.listenTo = function(options) {
var topics = options.topic || options.topics;
var _topics;
var _topics = [];
if (typeof topics === 'string') {
_topics = [topics];
@ -300,6 +300,10 @@ EmbarkJS.Messages.Whisper.listenTo = function(options) {
return err;
};
messageEvents.prototype.stop = function() {
this.filter.stopWatching();
};
var promise = new messageEvents();
var filter = web3.shh.filter(filterOptions, function(err, result) {
@ -318,6 +322,8 @@ EmbarkJS.Messages.Whisper.listenTo = function(options) {
}
});
promise.filter = filter;
return promise;
};