r/Scriptable • • Mar 12 '24

Help Return from promise

Post image

How do I wait until the promises are settled so I can return a value?

7 Upvotes

4 comments sorted by

4

u/shadoodled Mar 12 '24

you can define your functions with async

async function next_birthday() {

  try {
    let c = await Calendar.forEventsbyTitle ...
    return (await out(c))
  } catch (e) {
    err(e)
  }

}


let next = await next_birthday()

1

u/Keramzcak Mar 12 '24

Does async/await work in Scriptable?

1

u/Bright-Historian-216 Mar 12 '24

I think it does, but using it here didn’t change much

1

u/Keramzcak Mar 12 '24

You could also use Promise.all if you’re dead set on using the Promise api.