#promize a message

1 messages · Page 1 of 1 (latest)

teal hinge
tepid citrus
#

i dont see a point to promisifying a promise

teal hinge
#

you'll see in a few seconds

tepid citrus
#

okay

teal hinge
#

but i'm new on promise async await

#

i may do shit

#

but i don't know how to do else than my way :/

tepid citrus
#

just explain why you need to promisify a promise

teal hinge
#

yup

#

Ok

#

I have a piece of code in that file who are using a token stored in a database

tepid citrus
#

uhuh

teal hinge
#

The problem is that I need to refresh this token

tepid citrus
#

yeah

teal hinge
#

and only user can do it (thanks to faceit :/)

tepid citrus
#

yeah i still dont get you

teal hinge
#

the bot in that way need to ask for the new token

tepid citrus
#

awaitMessage returns a promise after the user chats

teal hinge
#

yes like this

tepid citrus
#

yeah so why do you need to promisify it

teal hinge
#

but i need to return this

tepid citrus
#

i dont see a need for that

#

you can just use async await or return the resolved data from the promise of the "other function"

teal hinge
#

to get it here

tepid citrus
#

do you know how promises work?

teal hinge
tepid citrus
#

you seem to be putting everything into a promise

#

even promises

teal hinge
#

I will rephrase

#

I need to return the result of the dbquery

tepid citrus
#

mhmm

#

i assume that returns a promise

#

of your result

teal hinge
#

you see where my problem is ? x)

tepid citrus
#

no

teal hinge
#

uh

tepid citrus
#

you literally

#

resolve the promise

#

it will wait for the promise to finish

#

before executing the code

#
// pseudo-code
function fn returns promise;

var data = await fn(); // await resolves the promise, so no code after this line will run until the promise is resolved
teal hinge
#

serious ?!

tepid citrus
#

yes

#

thats how promises work

teal hinge
#

I need to make that as a promise ?

tepid citrus
#

when you resolve the promise

#

no omg

teal hinge
#

so it will return "undifined" in this case

tepid citrus
#

i do not understand

#

why

#

you need to make everything a promise

#

async function fn() returns a promise too

#

no need to use new Promise

#

and you can use await

#

please learn what promises are, without this knowledge i really have no clue how to help you

teal hinge
#

Am i wrong ?

#

I ussualy work with threads on c# so I know that part

tepid citrus
#

c# is not js

teal hinge
#

I know

tepid citrus
#

promises are not threads

teal hinge
#

but the bacground work is the same

teal hinge
tepid citrus
#

omg i really

#

i have no clue how to get this through to you

#

that you dont promisify a promise

teal hinge
tepid citrus
#

they dont even need threads

teal hinge
#

in that way the main script can get the response of the promise

#

that's what i need

tepid citrus
#

then just resolve the promise from awaitMessages?

#

ok i really

#

dont know how to help you

#

im sorry for wasting your time

#

and my own time

#

i hope you find the solution somewhere but i have no clue how to help anymore

teal hinge
#

I will run the code without the promize

teal hinge
tepid citrus
#

please dont ping me

#

thank you