Skip to content
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

Switch matrix-js-sdk to bluebird #490

Merged
merged 6 commits into from
Jul 12, 2017
Merged

Switch matrix-js-sdk to bluebird #490

merged 6 commits into from
Jul 12, 2017

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Jul 12, 2017

The reasons for this are twofold.

Firstly, the use of q has long been a thorn in our side. Reasons to prefer bluebird include:

  • much improved performance (allegedly)
  • better stack traces (allegedly)
  • Automatic logging of uncaught exceptions, even if you forget to call done.
  • Support for cancellation of pending promises.

Secondly, and more pressingly, I am starting to introduce (on a different branch) use of async and await, which is much nicer to work with than managing the promises directly, but introduces the problem that (by default) async functions return native Promises, whilst historical parts of the js-sdk return q promises, meaning that one is never sure whether or not to call done. With this change, everything will return a bluebird Promise, which means that you can call done (so backwards compatibility is maintained), but don't have to.

It's worth noting that, having done import Promise from 'bluebird', any shims generated for async functions by Babel's transform-async-to-generator end up as bluebird Promises.

Copy link
Member

@dbkr dbkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise lgtm

23 error Or if that isn't available, you can get their info via:
23 error npm owner ls matrix-js-sdk
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably didn't mean to commit this

@dbkr
Copy link
Member

dbkr commented Jul 12, 2017

oh, and apart from the conflict

@dbkr dbkr assigned richvdh and unassigned dbkr Jul 12, 2017
richvdh added 6 commits July 12, 2017 23:32
```
find src spec -name '*.js' |
   xargs perl -i -pe 'if (/require\(.q.\)/) { $_ = "import Promise from '\''bluebird'\'';\n"; }'

find src spec -name '*.js' |
   xargs perl -i -pe 'if (/import q/) { $_ = "import Promise from '\''bluebird'\'';\n"; }'
```
```
find src spec -name '*.js' |
    xargs perl -i -pe 's/\bq(\([^(]*\))/Promise.resolve$1/'
```
```
find src spec -name '*.js' |
    xargs perl -i -pe 's/q\.Promise/Promise/'
```
```
find src spec -name '*.js' |
    xargs perl -i -pe 's/q\.(all|defer|reject|delay|try)\(/Promise.$1(/'
```
Bluebird promises don't have an `inspect()` method, but do have an
`isFulfilled()` and a `value()` method, so use them instead.
you're supposed to call Promise() as a constructor rather than a static
function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants