createFolder() function is returning an empty array. I am not sure what I am doing wrong but it needs to return the items within project_array Answer This is a classic, what you are doing is resolving the promise with the empty array before your node fs async methods have resolved. Try this instead: In essence, wrap every fs. call in
Tag: promise
When should I use try catch instead of then catch?
The question is simple, but I haven’t found the answer anywhere. When should i use try catch? in the code below I use try catch to handle the return of a request: Would it be a good practice to use then(…).catch(…)? Answer The difference is in how you’re handing Promises. If you’re using await to handle the Promise then you
Difference between two ways of resolving a promise
I would like to understand the difference between the two code snippets, both resolving promises in different ways but receiving the same result (resolving after a second). Which one is the right way? Answer In this case, where you’re not resolving with a value, there is no difference. In situations where you need to resolve the promise with a value,
Uncaught (in promise) SyntaxError: Unexpected end of JSON input error
This is simply add to cart function. Also means insert field to database. All is fine when it comes to adding to the database, however there is this error everytime I click add to cart(But still adds to database though). Here is my fetch code, leading to calling my controller. I’m not sure what json data is being returned here,
Alternatives to Deferred (anti?-)pattern when awaiting for user interactions in Angular
I’m building a game using Angular which has the following mechanics: An Angular service checks the game state and requests a required user interaction. A mediator service creates this request and emits it to the relevant Angular component using a RxJS subject. A response to this request is awaited in this mediator service, game doesn’t go on until request is
Managing promises in RXJS observables
I’ve poked about SO and found many similar questions/answers but I may be missing something in my basic understanding on how to work with with this stack. I’m working on a react native project along with RXJS/obervables. At some point I doing file downloads, this part is not a problem. A combo of pre-existing axios-rxjs and react-native-file-system get me where
.toPromise() and lastValueFrom() in rxjs
I have this observable I call it with .toPromise() is deprecated, so I would like to change the call with lastValueFrom(): but I receive the following error: UPDATE: for now, resolved with: but is there a better solution? Answer Is there a better solution? Yes and no. In your case mergeMap(_ => EMPTY) will ensure that your observable completes without
How can I resolve or reject a promise based on a another promise?
anotherPromiseFunction() returns a promise. normally inside a .then() I can return a promise to make the then() wait for that promise to finish, but how do I do it when creating a promise? Am I supposed to do this: That seems wrong… Answer You likely do not need the new Promise. The cases for “module exists” and “processor exists” can
Discord.js v13 delete message after a certain amount of time
Up to discord.js v12, my bot would delete messages it posted like this : However, now that I updated discord.js modules to v13, the message is deleted instantly. Is there a new method to do that, or am I doing it wrong ? Answer Turns out that, as stated in the documentation here, msg.delete() does not accept options anymore, meaning
Using Promise in a for loop, all the .then came later is always be called untill all the first .then is finished running, why is that?
I am new to JavaScript and with the concept of Promise. And I am doing test. I created a promise and two for loop that runs Promise for 6 times in total, and I knows when they got executed by console.log() Here’s my code and here’s how the console be like: Why is the second .then and all the .finally