Skip to content

Synchronous vs Asynchronous #566

Closed
Closed

Description

@sm2017

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

Activity

  1. sm2017 commented on Jan 13, 2019

    @sm2017
    Author

    @ziluvatar , @MitMaro can you help me?

  2. sm2017 commented on Jan 15, 2019

    @sm2017
    Author

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

  3. sm2017 commented on Jan 17, 2019

    @sm2017
    Author

    :-((

  4. wjureczkaPracuj commented on Jan 17, 2019

    @wjureczkaPracuj
  5. sm2017 commented on Jan 17, 2019

    @sm2017
    Author

    @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

  6. ziluvatar commented on Jan 18, 2019

    @ziluvatar
    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.

  7. lonix1 commented on Feb 11, 2019

    @lonix1

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

  8. ziluvatar commented on Feb 15, 2019

    @ziluvatar
    Contributor

    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.

  9. lonix1 commented on Feb 15, 2019

    @lonix1

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

  10. added a commit that references this issue on Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions