Async Tasks demo screen - #8
Draft
simonhamp wants to merge 1 commit into
Draft
Conversation
Exercises the AsyncTask API end to end: finished(), failed(), several tasks in flight at once, shared() delivery via a named event, and the static-closure guard. A tap counter sits at the top of the screen as the load-bearing proof — it keeps counting while tasks run, so the UI thread is visibly never blocked. Tests use AsyncTask::fake(), which runs work inline and synchronously. The on-device delays are zeroed via a helper so the suite doesn't sleep. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a demo screen for the
AsyncTaskAPI, reachable from the launcher at/async-tasks.What it covers
Five cards, one per part of the API:
finished()— a slow task on a background PHP thread; result lands back on the component, with elapsed ms.failed()— a task that throws, surfaced as anAsyncTaskExceptioncarrying the original message and class.shared()— result delivered as a named event via#[On]instead of a screen-scoped callback. Navigate away mid-flight and back: a plainfinished()would drop the result, this one still arrives.$this-bound work closure is rejected at dispatch time, in the handler where you can see it, rather than failing silently in a background log.The tap counter at the top of the screen is the load-bearing bit: hammer it while tasks are running and it keeps counting, so the UI thread is visibly never blocked.
Tests
AsyncTask::fake()runs dispatched work inline and synchronously, sofinished()/failed()fire during the test with no background threads. The on-device delays exist to make the async behaviour watchable; aninstant()helper zeroes them so the suite doesn't sleep.8 tests, 62 assertions, all passing.
Depends on
The
AsyncTaskAPI,AsyncTask::fake()andNative\Mobile\Testing\Nativeall land in thecomponent-async-apibranch ofnativephp/mobile. This will not build againstdev-mainuntil that ships — pointingnativephp/mobileat a local checkout of that branch is how it was developed and verified. No composer changes are included here, deliberately.🤖 Generated with Claude Code