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

Synchronous vs Asynchronous #566

Closed
sm2017 opened this issue Jan 9, 2019 · 9 comments
Closed

Synchronous vs Asynchronous #566

sm2017 opened this issue Jan 9, 2019 · 9 comments

Comments

@sm2017
Copy link

sm2017 commented Jan 9, 2019

Synchronous

var jwt = require('jsonwebtoken');
var token = jwt.sign({ foo: 'bar' }, 'shhhhh');

Asynchronous

var token = jwt.sign({ foo: 'bar' }, 'shhhhh', function(err, token) {
  console.log(token);
);

I want to know , is it bad to use Synchronous way , in express js server? is there any benefit with Asynchronous mode? As I think there is no I/O and just CPU usage, So Asynchronous and Synchronous must b same, just syntax is different

@sm2017
Copy link
Author

sm2017 commented Jan 13, 2019

@ziluvatar , @MitMaro can you help me?

@sm2017
Copy link
Author

sm2017 commented Jan 15, 2019

Hello???????????

@sm2017
Copy link
Author

sm2017 commented Jan 17, 2019

:-((

@wjureczkaPracuj
Copy link

https://medium.com/@patrykcieszkowski/jwt-authentication-in-express-js-ee898b87a60 section Verifying the Token may help you

@sm2017
Copy link
Author

sm2017 commented Jan 17, 2019

@wjureczkaPracuj as I understand, in point of performance there is no different I use sync or async mode, and it is safe to use sync mode in server too

@ziluvatar
Copy link
Contributor

in point of performance there is no different I use sync or async mode, and it is safe to use sync mode in server too

Correct. Although if you use the sync way be sure you wrap it with try-catch.

@lonix1
Copy link

lonix1 commented Feb 11, 2019

If there is no perf difference, why does the library offer an async alternative?

@ziluvatar
Copy link
Contributor

ziluvatar commented Feb 15, 2019

TL;DR; To allow consumers load keys from filesystem or any other source of ReadStream without blocking event loop. Not to actually perform the signing.

I've been digging into git history and jws implementation to understand why the library provided the async functionality for signing:

Honestly, not sure if that streaming is a desired feature by consumers, we'd need to update the README to make it clear.

@lonix1
Copy link

lonix1 commented Feb 15, 2019

@ziluvatar That sounds like some serious coding archaeology... well done! 😉

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

No branches or pull requests

4 participants