mrowlsss @mrowlsss

what the fuck

mrowlsss @mrowlsss

I’m still working on wasteof.money for snap(.berkeley), but because I know how to use the wasteof api, I have came to the realization that I now have to create a mod with custom blocks (which i am very skilled at)

Nov 11, 2023, 1:21 PM
3
Nov 11, 2023, 2:23 PM
24
View all Parent

comments

Highlighted comment

Does Snap handle promises?

Yes

use async/await (preferred)

ok

return the promise without the res part

wait how

return fetch("https://api.wasteof.money/session", requestOptions).then(response => response.text)

But async/await is still the better option.

It’s returning [object Promise], can you send me some code with async/await?

async/await would do the same thing, it's just syntactic sugar for promises. Snap doesn't seem to support promises, then.

You’re returning a promise there, that’s told to get the text when its done. You’d have to put the alert inside the then statement, so it only gets called when the promise is actually done. There’s a lot of callback hell involved with dealing with promises as they are. async/await solves a lot of that. I’d recommend reading more about promises to understand what they are and how they work: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises

wait rq can you give me an example of using async/await with this?

const token = await (await fetch(...)).text;

And the function it's wrapped in has to be async, e.g.

// my favorite
const func = async () => {}
// or
const func = async function() {}
// or
async function func() {}

i tried

            const token = await (await fetch("https://api.wasteof.money/session", requestOptions).text;
     		alert(token);

and it isnt working, am i doing something wrong?

See more replies