-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move laravel/prompts to require-dev, suggest install, bump version * require illuminate/collections * require react/event-loop * sort composer packages * Add Override attirbutes to AsyncConsoleOutput * remove PatchedPrompt, extend and Override Prompt class * track trailing newlines in AsyncConsoleOutput * Fix code styling * drop php 8.1 support * add warning to docs --------- Co-authored-by: ProjektGopher <[email protected]>
- Loading branch information
1 parent
7c1c37f
commit 01cb1d0
Showing
6 changed files
with
56 additions
and
531 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
# 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. | ||
> [!WARNING] | ||
> Using this `AsyncPrompt` class will **modify** the `blocking` mode on `STDIN`, which can have _unexpected_ consequences when switching back to a standard `Prompt`. | ||
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. | ||
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. | ||
|
||
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. | ||
By **overwriting** these looping mechanisms 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.