Skip to content

Commit

Permalink
add AsyncPrompt documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ProjektGopher committed Jul 19, 2024
1 parent ff22245 commit 62e04ac
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Docs/asynch-prompts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Asynchronous Prompts

In a standard Laravel Prompt, the looping mechanism blocks the main thread while waiting for keypresses. This limits our ability to trigger renders using an `event` based approach.

In `ArtisanBuild/CommunityPrompts/PatchedPrompt` we've extracted these looping mechanisms. This class will not be needed if [this compatibility PR](https://github.com/laravel/prompts/pull/154) can be re-opened and merged.

By extracting these looping mechanisms we're able to overwrite the implementations of these loops in `ArtisanBuild/CommunityPrompts/AsyncPrompt` using a [ReactPHP](https://reactphp.org/) event loop. This unlocks the ability for us to read the terminal, write to the terminal, dispatch http requests, etc, in a non-blocking way. By calling the `render()` method inside `callbacks` we can now do things like debounce http requests to search endpoints, output streamed http responses to the terminal one chunk at a time without blocking the user from entering new text, or even listening for real-time push notifications from a websocket.

0 comments on commit 62e04ac

Please sign in to comment.