promise

Difference between return Error and throw Error

a 夏天 提交于 2020-08-22 05:08:32
问题 I found the following code in a project, that I do not understand.: get(key, store = null) { if (!key) { return new Error('There is no key to get!'); } let dbstore = this.localforage; if (store !== null) { dbstore = store; } return dbstore .getItem(key) .then(function(value) { return value; }) .catch(function(err) { return new Error('The key (' + key + ") isn't accessible: " + err); }); } Why return new Error('There is no key to get!'); instead of throw new Error('There is no key to get!'); ?

Difference between return Error and throw Error

馋奶兔 提交于 2020-08-22 05:08:28
问题 I found the following code in a project, that I do not understand.: get(key, store = null) { if (!key) { return new Error('There is no key to get!'); } let dbstore = this.localforage; if (store !== null) { dbstore = store; } return dbstore .getItem(key) .then(function(value) { return value; }) .catch(function(err) { return new Error('The key (' + key + ") isn't accessible: " + err); }); } Why return new Error('There is no key to get!'); instead of throw new Error('There is no key to get!'); ?

async.mapLimit with Promise

倾然丶 夕夏残阳落幕 提交于 2020-08-10 23:43:05
问题 I'm trying to use the async module (v3) and especially the async.mapLimit method to submit a limited number of parallel asnychronous requests. This works well with callbacks in the following (simplified) sample code: async = require('async'); async.mapLimit(['1','2','3','4','5'], 3, function(num, callback){ setTimeout(function(){ num = num * 2, console.log(num); callback(null, num); }, 4000); },function(err, results){ console.log(results); }); As result I get the single values and finally the

vue-router — Uncaught (in promise) Error: Redirected from “/login” to “/” via a navigation guard

大城市里の小女人 提交于 2020-08-06 07:53:53
问题 Why is vue-router giving me this error? To be clear, the login flow works as intended but I want to a) get rid of the errro and b) understand why the error is happening. Error: Uncaught (in promise) Error: Redirected from "/login" to "/" via a navigation guard. Login flow start logged out, but enter a URL that requires auth (i.e. anything besides "/login") get redirected to "/login" (as expected). login successfully get redirected to starting Url from step #1, except with the above error.

Disable promise transpilation using babel-preset-env?

萝らか妹 提交于 2020-08-05 19:21:36
问题 I'm using babel-preset-env (Babel 6) and I can't find out how to disable the "promise" transpilation. I tried to use: { "presets": [ [ "env", { "exclude": ["transform-async-to-generator", "es6.promise"] } ] ], "plugins": [ "transform-object-rest-spread", "transform-class-properties", [ "fast-async", { "spec": true, "compiler": { "promises": true, "generators": false } } ] ] } and, while it doesn't throws any errors (unlike it happens when an invalid option is passed), it still transpiles

Disable promise transpilation using babel-preset-env?

徘徊边缘 提交于 2020-08-05 19:21:03
问题 I'm using babel-preset-env (Babel 6) and I can't find out how to disable the "promise" transpilation. I tried to use: { "presets": [ [ "env", { "exclude": ["transform-async-to-generator", "es6.promise"] } ] ], "plugins": [ "transform-object-rest-spread", "transform-class-properties", [ "fast-async", { "spec": true, "compiler": { "promises": true, "generators": false } } ] ] } and, while it doesn't throws any errors (unlike it happens when an invalid option is passed), it still transpiles

What happens first: setTimeout 0 or await Promise.resolve?

妖精的绣舞 提交于 2020-07-29 12:15:06
问题 I'm seeing this behavior in Node and Chrome: setTimeout(()=>{ console.log('timeout') }, 0) Promise.resolve().then(()=>{ console.log('promise') }) console.log('sync') // output order: // sync // promise // timeout My question is, is this consistent behavior? I.e, according to spec, does a then or await on a memoized/already resolved promise always fire before setTimeout(fn, 0) ? I want to use this in something like the following, returning one thing if I have a memoized result in my promise

Multiple Client Requests in NodeJs

☆樱花仙子☆ 提交于 2020-07-22 21:36:31
问题 If i hit /route2 , i get reponse 15s later,but during that time /route1 gives response immediately. Shouldn't server wait for 15s and then give the response to /route1. I read https://medium.com/@cinish/nodejs-multiple-client-requests-694d6353218b but could not the idea. What i understood is as /route2 is hit console P1 then as there is setTimeout() ,put it in external thread,then console P2 then as setTimeout() ,put it in external thread.Now wait for setTimeouts() to finish. (At this time

Multiple Client Requests in NodeJs

旧街凉风 提交于 2020-07-22 21:33:47
问题 If i hit /route2 , i get reponse 15s later,but during that time /route1 gives response immediately. Shouldn't server wait for 15s and then give the response to /route1. I read https://medium.com/@cinish/nodejs-multiple-client-requests-694d6353218b but could not the idea. What i understood is as /route2 is hit console P1 then as there is setTimeout() ,put it in external thread,then console P2 then as setTimeout() ,put it in external thread.Now wait for setTimeouts() to finish. (At this time

Check for null & replace it with empty string for all properties in a object using jQuery and JavaScript

我只是一个虾纸丫 提交于 2020-07-22 09:45:58
问题 I have a JSON object, which includes other objects and list of objects. Have to write a function, which iterates through all properties of objects as well as object within object and list of objects and replace null with an empty string. As it is loop inside loop, I need to implement deferred so sequential processing. I tried many ways, but failed. Anyone please help. function ValidateObject(result) { var aObj = result.A; aObj = VerifyForNull(aoBJ); var bObj = result.B; bObj = VerifyForNull