Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add async/await style syntax #92

Open
uliwitness opened this issue Sep 5, 2017 · 4 comments
Open

Add async/await style syntax #92

uliwitness opened this issue Sep 5, 2017 · 4 comments

Comments

@uliwitness
Copy link
Owner

pause caller [until end of handler] -- until is like defer, call pause again to dequeue the defer
resume caller

@uliwitness
Copy link
Owner Author

We already allow pausing handlers internally (see implementation of "go" command for stacks on web servers).

@uliwitness
Copy link
Owner Author

Idea of async/await is that you could e.g. implement a download command as put contentsAtURL( "foo:///bar/baz") into var where contentsAtURL() would pause the current handler and resume it when the asynchronous download command calls our when done code.

We need some syntax to allow this. E.g.:

on contentsAtURL theURL
  global gMyDownload
  download "theURL" to gMyDownload
  when done
    resume caller
  end download
  pause caller
  return gMyDownload
end contentsAtURL

Which kicks off the asynchronous operation, then pauses the caller (i.e. saves the script's state and stops it), and when the download finishes, it calls resume caller which causes the script to be started again, resuming right after "pause caller".

But the syntax seems too nerdy. Is there a more natural way to express this?

@uliwitness
Copy link
Owner Author

Also: What if the asynchronous operation is not as simple as this download command? Do we need a "token" that we can hand to someone else so they can call "resume" with it? What do we call this? the pauseID of this handler? Technically it's a future, but that's too nerdy a term. Find something that humans understand.

Are queue tickets a good metaphor?

on contentsAtURL theURL
  global gMyDownload
  put the queueTicket into myTicket
  download "theURL" to gMyDownload
  when done
    resume ticket myTicket
  end download
  pause until ticket myTicket
  return gMyDownload
end contentsAtURL

@uliwitness
Copy link
Owner Author

uliwitness commented May 19, 2020

Maybe we could use the wait command for this? The old-style wait 5 seconds would block, so needs to be implemented in a non-blocking way anyway, and that would use the same mechanism go already uses to allow to access stacks over the network without blocking Stacksmith itself.

So wait for <duration> or wait for ticket <ticketID>?

But then resume makes no sense anymore. complete ticket <ticketID>? punch ticket <ticketID> ? mark ticket <ticketID> as done?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant