promise

Angular custom error handler not getting error type from promise

岁酱吖の 提交于 2021-02-07 18:47:18
问题 When thrown from a promise every Error my custom error handler is getting does loose its type import { HttpErrorResponse } from "@angular/common/http"; import { ErrorHandler, Injectable, Injector, NgZone } from "@angular/core"; import { MatSnackBar } from "@angular/material"; @Injectable() export class GlobalErrorHandler implements ErrorHandler { constructor(private injector: Injector) { } handleError(error: any): void { if (error instanceof HttpErrorResponse) // this needs to be triggered

Angular custom error handler not getting error type from promise

亡梦爱人 提交于 2021-02-07 18:47:16
问题 When thrown from a promise every Error my custom error handler is getting does loose its type import { HttpErrorResponse } from "@angular/common/http"; import { ErrorHandler, Injectable, Injector, NgZone } from "@angular/core"; import { MatSnackBar } from "@angular/material"; @Injectable() export class GlobalErrorHandler implements ErrorHandler { constructor(private injector: Injector) { } handleError(error: any): void { if (error instanceof HttpErrorResponse) // this needs to be triggered

Create a promise to handle a really long loop

£可爱£侵袭症+ 提交于 2021-02-07 18:37:35
问题 Supose that I have the following for loop, which would obviously block the event loop for a while: function doStuff() { let max = 100_000_000_000_000n; for (let i = 1n; i <= max; i = i + 1n) { if (i === max) { // Do stuff, like return a value to a function. return 'Some value.'; } } } Can I wrap that operation (the for loop) inside a Promise, so it does not block the "main thread"? Something like that: function doStuff() { let max = 100_000_000_000_000n; return new Promise((resolve) => { for

Scala Future/Promise fast-fail pipeline

风流意气都作罢 提交于 2021-02-07 13:58:16
问题 I want to launch two or more Future/Promises in parallel and fail even if one of the launched Future/Promise fails and dont want to wait for the rest to complete. What is the most idiomatic way to compose this pipeline in Scala. EDIT: more contextual information. I have to launch two external processes one writing to a fifo file and another reading from it. Say if the writer process fails; the reader thread might hang forever waiting for any input from the file. So I would want to launch both

How to get values from a promise with node.js without .then function

我只是一个虾纸丫 提交于 2021-02-07 11:24:21
问题 I have a problem with a promise using node.js. My code is below: var p1 = new Promise(function(resolve, reject) { // my function here }); p1.then(function(result){ // my result }); This code works but to get values from p1 I must use the .then method and my result values can be accessed just on p1.then . How do I access p1 values without .then ? Below are my expected results: var p1 = new Promise(function(resolve, reject) { // my function here }); var abc = NextFunction(p1); The p1 values

Can an ES6 JavaScript promise be resolved by anything else if it is not resolved by the executor?

岁酱吖の 提交于 2021-02-07 11:13:58
问题 If a promise is created this way: myPromise = new Promise(function(resolve, reject) {}); Can this promise be ever resolved by any way? Obviously, the executor is not resolving it in this case, so can the promise be ever resolved? I think if it is jQuery, it can be resolved by deferred.resolve() so that the related promise deferred.promise() is resolved. 回答1: No, the promise can only be resolved or rejected by the resolve and reject functions, respectively. If these functions aren't called nor

Can an ES6 JavaScript promise be resolved by anything else if it is not resolved by the executor?

允我心安 提交于 2021-02-07 11:12:35
问题 If a promise is created this way: myPromise = new Promise(function(resolve, reject) {}); Can this promise be ever resolved by any way? Obviously, the executor is not resolving it in this case, so can the promise be ever resolved? I think if it is jQuery, it can be resolved by deferred.resolve() so that the related promise deferred.promise() is resolved. 回答1: No, the promise can only be resolved or rejected by the resolve and reject functions, respectively. If these functions aren't called nor

Querying same document in parallel in the same API in mongoDB

可紊 提交于 2021-02-07 09:40:05
问题 I have a an API written in typescript and I try to run parallel queries for same document by using promise.allsettled however it performs worse and I guess they run sequentially. Is there a way to perform parallel queries on the same document in the same connection for mongoDB. here is the code: console.time("normal"); let normal = await ContentRepo.geBySkillIdWithSourceFiltered( [chosenSkillsArr[0].sid!], readContentIds, body.isVideoIncluded, true, true ); console.timeEnd("normal"); console

Querying same document in parallel in the same API in mongoDB

泪湿孤枕 提交于 2021-02-07 09:39:34
问题 I have a an API written in typescript and I try to run parallel queries for same document by using promise.allsettled however it performs worse and I guess they run sequentially. Is there a way to perform parallel queries on the same document in the same connection for mongoDB. here is the code: console.time("normal"); let normal = await ContentRepo.geBySkillIdWithSourceFiltered( [chosenSkillsArr[0].sid!], readContentIds, body.isVideoIncluded, true, true ); console.timeEnd("normal"); console

How does Promise in javascript work under the hood? My Promise implementation doesn't work the same

℡╲_俬逩灬. 提交于 2021-02-07 09:33:47
问题 I am a newbie to JS and I am trying to understand how Promise should work under the hood. Here is a custom implementation that looks reasonably good to me: class MyPromise { constructor(executor) { this._resolutionQueue = []; this._rejectionQueue = []; this._state = 'pending'; this._value; this._rejectionReason; try { executor(this._resolve.bind(this), this._reject.bind(this)); } catch (e) { this._reject(e); } } _runRejectionHandlers() { while(this._rejectionQueue.length > 0) { var rejection