kbrgl / svelte-french-toast

🍞🥂 Buttery smooth toast notifications for Svelte
https://svelte-french-toast.vercel.app/
MIT License
809 stars 28 forks source link

Know result of promise #31

Closed jorri11 closed 1 year ago

jorri11 commented 1 year ago

Is there a way to know the result of toast.promise()?

li6in9muyou commented 1 year ago

Can you clarify your question please?

The promise you passed in is returned back from toast.promise(...), see source below.

https://github.com/kbrgl/svelte-french-toast/blob/8cc73ee80ac5bfeb592e97d28f4c99b25f96aa29/src/lib/core/toast.ts#L52-L81

You can try it out in this REPL

kbrgl commented 1 year ago

Thanks for the demo @li6in9muyou!

To clarify further, once a promise is fulfilled, awaiting it a second time should have no effect: https://blog.scottlogic.com/2021/01/07/await-twice.html.

So if you do await toast.promise(p, ...), it's roughly the same as doing await p, except Svelte French Toast adds some side effects.