-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add promises #81
base: master
Are you sure you want to change the base?
Add promises #81
Conversation
First things first, looks like we need to get the test suite running on Travis again. |
The grunt fix here was merged as 25bfc26. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, you probably want to reject promises in the those functions, rather than call notify
.
Also, this could use a rebase.
@@ -572,7 +574,7 @@ | |||
if (this.REQUIRE_ENCRYPTION) { | |||
this.storedMgs.push({msg: msg, meta: meta}) | |||
this.sendQueryMsg() | |||
return | |||
return promise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This promise
is never rejected or fulfilled, similarly all the cases below where the functions return early.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was by purpose, to resolve a Promise only if there were some data to send. But yes in this case sendQueryMsg
should return a promise and also notify
should return an rejected promise. Will update the pr accordingly.
@@ -583,45 +585,53 @@ | |||
case CONST.MSGSTATE_FINISHED: | |||
this.storedMgs.push({msg: msg, meta: meta}) | |||
this.notify('Message cannot be sent at this time.', 'warn') | |||
return | |||
return promise | |||
case CONST.MSGSTATE_ENCRYPTED: | |||
msg = this.prepareMsg(msg) | |||
break | |||
default: | |||
throw new Error('Unknown message state.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably want to reject here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwing an exception is the same as rejecting.
|
||
switch (msg.cls) { | ||
case 'error': | ||
this.notify(msg.msg) | ||
return | ||
return promise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return promise.reject(msg.msg)
, no?
I just encountered that I have to add promises to a lot more functions, like |
Ok, there may be some hints in #75 which promisifies some portion of the code.
Yes, adding to the test suite would be beneficial. |
@sualko Concerning a polyfill, you can try es6-promise. |
Before I continue, we have to decide when The aim of promises in this case (at least for me) is to get a relation between a plaintext and encrypted message, which is ensured in the current pr. |
I did just some quick tests, but I think it needs some more exhaustive ones.