How to run asynchronous operations in JSFunction blocks

You might want to use the JSFunction block to do useful things such as network requests that Snap! can't natively do. The problem is that some of these operations are time-consuming meaning that the function for them is asynchronous, meaning that even when the JSFunction ends the function might not be completed. To solve this problem we need to make Snap! wait until our operation is really finished. We can use one of the following methods:

1. Pushing contexts
2. Using the `wait until` block

The pushing contexts method is basically creating new procedures (correct me if I'm wrong) which can make Snap! slow. The idea behind using the wait until block is that we can return a function from the JSFunction block that is initially set to a falsy value and we can resolve with that value once the operation is finished. Here's an example with promises:
(assume that this is inside a JSFunction block with a parameter url and we're assigning it to a variable named response)

let result = null;
fetch(url).then(res => res.text()).then(txt => {
  result = txt;
});
return () => result;

[scratchblocks]
wait until (response) ::control
report (response) :: control
[/scratchblocks]

Did you mean response rather than result in that JS chunk?