You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+55-3Lines changed: 55 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3127,7 +3127,7 @@ module.exports = {
3127
3127
3128
3128
The `jwt.sign()` method takes a payload and the secret key defined in `config.js` as parameters. It creates a unique string of characters representing the payload. In our case, the payload is an object containing only the id of the user.
@@ -3140,7 +3140,7 @@ The `jwt.sign()` method takes a payload and the secret key defined in `config.js
3140
3140
Microservices are a style of **service-oriented architecture** (SOA) where the app is structured on an assembly of interconnected services. With microservices, the application architecture is built with lightweight protocols. The services are finely seeded in the architecture. Microservices disintegrate the app into smaller services and enable improved modularity.
A promise is an object that represents the return value or the thrown exception that the function may eventually provide. A promise can also be used as a proxy for a remote object to overcome latency.
3226
+
3227
+
Promise is relatively an easy implementation for asynchronous operation. The promise object returned from the function represents an operation which is not completed yet, but it guarantees to the caller of the operation that the operation will be completed in future.
3228
+
3229
+
Promise has the following states:
3230
+
3231
+
***Pending** - asynchronous operation is not yet completed.
3232
+
***Fulfilled** - asynchronous operation is completed successfully.
3233
+
***Rejected** - asynchronous operation is terminated with an error.
3234
+
***Settled** - asynchronous operation is either fulfilled or rejected.
3235
+
***Callback** - function is executed if the promise is executed with value.
3236
+
***Errback** - function is executed if the promise is rejected.
3237
+
3238
+
**Moving to Promises from Callback**
3239
+
3240
+
On the first pass, promises can mitigate the **Pyramid of Doom**: the situation where code marches to the right faster than it marches forward.
3241
+
3242
+
```js
3243
+
step1(function (value1) {
3244
+
step2(value1, function(value2) {
3245
+
step3(value2, function(value3) {
3246
+
step4(value3, function(value4) {
3247
+
// Do something with value4
3248
+
});
3249
+
});
3250
+
});
3251
+
});
3252
+
```
3253
+
3254
+
With a promise library, it can flatten the pyramid.
0 commit comments