Synchronous vs Asynchronous
See original GitHub issueSynchronous
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
Issue Analytics
- State:
- Created 5 years ago
- Reactions:14
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Asynchronous vs. Synchronous Programming - Mendix
Asynchronous is a non-blocking architecture, so the execution of one task isn't dependent on another. Tasks can run simultaneously. Synchronous ...
Read more >Synchronous Vs. Asynchronous Classes - TheBestSchools.org
Synchronous classes run in real time, with students and instructors attending together from different locations. Asynchronous classes run on ...
Read more >Synchronous vs. Asynchronous Learning - Ohio State Online
On the other hand, synchronous online learning means that students are required to log in and participate in class at a specific time...
Read more >Asynchronous vs synchronous execution. What is the ...
Synchronous basically means that you can only execute one thing at a time. Asynchronous means that you can execute multiple things ...
Read more >Difference synchronous vs asynchronous learning - Easy LMS
If synchronous learning takes place at the same time, asynchronous learning refers to the opposite. The instructor, the learner, and other ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:
jws
implemented streaming for sign/verify: https://github.com/brianloveswords/node-jws/commit/ad80a8ac9fdea2de59b607ea8f556451053af145jws
library provides streaming for payload and secret, that way you could load those from the file system or any source that provided a NodeJS stream interface, like we can see injws
: https://github.com/brianloveswords/node-jws/blob/ad80a8ac9fdea2de59b607ea8f556451053af145/test/jws.test.js#L132Honestly, not sure if that streaming is a desired feature by consumers, we’d need to update the README to make it clear.
If there is no perf difference, why does the library offer an async alternative?