promise

Discord.js awaitReaction chained promise after message.react collect the reaction as promise isn't resolved

偶尔善良 提交于 2021-01-27 16:52:39
问题 I was playing around with the message.react function and the awaitReactions function and I noticed something that bother me. I was trying to determine if I should use a collector or the client.on('messageReactionAdd') (that is another question) for the following method: sending a message adding reactions to it doing something every time a reaction is added (for X seconds) So I made a simple example to start, with a filter which return true every time, and I noticed that the collector was

How can I make redux dispatch an action as well as return a promise?

时光毁灭记忆、已成空白 提交于 2021-01-27 14:10:40
问题 Here is my function in songAction.js export function createSong(title, url, token) { axios.defaults.headers.common['Authorization'] = token return function (dispatch) { axios.post('http://localhost:8080/api/song/create', { title, link: url }) .then((response) => { console.log('the response was', response) if(response.data.success){ dispatch({type: "CREATE_SONG_FULFILLED", payload: response.data.song}) } else { dispatch({type: "CREATE_SONG_REJECTED", payload: response.data}) } }) .catch((err)

What is the difference between returned Promise?

吃可爱长大的小学妹 提交于 2021-01-27 13:38:05
问题 There are two cases, both return Promise and are chained with the following then methods. But the result sequence is different. Some notes: Promise.resolve(value) -> returns immediately fulfilled Promise with the value. And in the then method when we return value again it returns fulfilled Promise with the value. Logically there shouldn't be any difference. Both are immediate... Thanks in advance... Promise.resolve(1) .then((v) => { console.log(v); return Promise.resolve(v + 1); }) .then((v)

How to force resolve a promise after certain duration in node.js? [duplicate]

房东的猫 提交于 2021-01-27 13:21:32
问题 This question already has answers here : NodeJS Timeout a Promise if failed to complete in time (7 answers) Closed last month . I am trying to download a large number images from their url(s) and then creating a PDF file out of them in Node.js. I'm using the image-downloader module to download the images in a promise chain and then once all promises are resolved, using another module, images-to-pdf, to trigger the creation of the pdf. The problem is that most of the promises get resolved

Are promises lazily evaluated?

吃可爱长大的小学妹 提交于 2021-01-27 12:19:43
问题 Is the code below guaranteed to output HERE ? var p = new Promise(() => console.log("HERE")) (That is, does var p = new Promise(fn) always execute fn if p.then(…) is never called to do something with the result?) More specifically, in the context of service workers, if I call Cache.delete() but never call .then() on the return value (or I throw away the return value), is the cache entry guaranteed to be deleted? 回答1: Yes, it is guaranteed. The specification of Promise has this step which will

passport.authenticate() using a Promise instead of a Custom Callback

寵の児 提交于 2021-01-27 12:14:07
问题 passport.authenticate() , how can I define a Promise instead of using a Custom Ballback ? How to used passport.authenticate() is referenced within here: http://www.passportjs.org/docs/authenticate/ Within this page, there is a section Custom Ballback : If the built-in options are not sufficient for handling an authentication request, a custom callback can be provided to allow the application to handle success or failure. app.get('/login', function(req, res, next) { passport.authenticate(

Is observable and promise compatible in rxjs?

穿精又带淫゛_ 提交于 2021-01-27 07:08:03
问题 In the official angular2 tutorial it contains the following code getHeroes(): Promise<Hero[]> { return Promise.resolve(HEROES); } ngOnInit(): void { this.route.params .switchMap((params: Params) => this.heroService.getHero(+params['id'])) .subscribe(hero => this.hero = hero); console.log(this.route.params); console.log(this.route.params .switchMap((params: Params) => this.heroService.getHero(+params['id']))); } Now we know that this.route.params returns an observable, while this.heroService

AWS Lambda ending early (without any explicit return or callback)

纵饮孤独 提交于 2021-01-26 09:49:21
问题 I'm having a bit of an issue with some node.js code I'm putting into AWS Lambda. I've got a couple of async calls that I need to make, and while the first is behaving like I expect, the lambda function is terminating before the second call is complete. The return is null, which makes me think that lambda is hitting its implicit callback, but I don't think it should be doing that while there is a promise that hasn't been resolved yet. Code: exports.handle = async function(event, context) { var

AWS Lambda ending early (without any explicit return or callback)

谁说胖子不能爱 提交于 2021-01-26 09:47:59
问题 I'm having a bit of an issue with some node.js code I'm putting into AWS Lambda. I've got a couple of async calls that I need to make, and while the first is behaving like I expect, the lambda function is terminating before the second call is complete. The return is null, which makes me think that lambda is hitting its implicit callback, but I don't think it should be doing that while there is a promise that hasn't been resolved yet. Code: exports.handle = async function(event, context) { var

JS: Executing events overlapping in time afteranother

半世苍凉 提交于 2021-01-25 04:05:20
问题 I receive events on-the-fly in the correct order in which I want to process them after another (as well on-the-fly - so don't "store" them first). The following example is not going to work as the function someEventOccured() could be called multiple times in a very close timespan. Thus, the execution of handleEvent would overlap in time (which I don't want). As I am writing to a file in handleEvent() I cannot have simultaneously execute the function and need to maintain the order... async