Make controller lifecycle methods async#145
Merged
Merged
Conversation
Mark the lifecycle methods on both controllers as async so their call
sites (all inside `.task { }`) can await them directly instead of relying
on implicit fire-and-forget, keeping the concurrency boundary explicit.
- StreamedMarkdownController: `start()` / `end()` are now async
- MarkdownController: `onAppear(markdown:)` / `onDisappear()` are now async
- Update `.task` call sites to `await`; wrap the sync `.onDisappear`
callbacks in a `Task`
The fire-and-forget interaction hooks and the sync `onChange(markdown:)`
remain synchronous, since their call sites are non-async UIKit/AppKit
delegates and SwiftUI action closures.
Refs #144
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 17e2748f-66c1-4deb-b557-df65a17c84f5
There was a problem hiding this comment.
Pull request overview
This PR updates controller lifecycle APIs to be async so SwiftUI view-layer .task {} call sites can await them directly, making the concurrency boundary explicit and consistent across DocumentView and StreamedMarkdownView.
Changes:
- Made
MarkdownController.onAppear(markdown:)/onDisappear()asyncand updatedDocumentViewtoawait/wrap calls appropriately. - Made
StreamedMarkdownController.start()/end()asyncand updatedStreamedMarkdownViewcall sites accordingly. - Introduced a debug
printinMarkdownController.onChange(markdown:)(should be removed before merge).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| Sources/MarkdownText/Utilities/MarkdownListener.swift | Converts MarkdownController lifecycle methods to async; currently includes an unintended debug log in onChange. |
| Sources/MarkdownText/UI/DocumentView.swift | Awaits controller lifecycle methods from .task and wraps async cleanup in .onDisappear. |
| Sources/MarkdownText/StreamedMarkdownView.swift | Awaits streamed controller lifecycle methods and wraps async cleanup in .onDisappear. |
A leftover `print("JUN: ...")` debug statement was accidentally included
in `MarkdownController.onChange(markdown:)`. Remove it so the library
does not spam stdout or leak content details in production.
Refs #144
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 17e2748f-66c1-4deb-b557-df65a17c84f5
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.
Summary
Mark the lifecycle methods on
StreamedMarkdownControllerandMarkdownControllerasasyncso their call sites — all of which run inside.task { }— canawaitthem directly instead of relying on implicit fire-and-forget. This keeps the concurrency boundary explicit at the view layer and aligns both controllers with the package's Swift-concurrency conventions.StreamedMarkdownController.start()/end()are nowasyncMarkdownController.onAppear(markdown:)/onDisappear()are nowasync.taskcall sites nowawait; the sync.onDisappearcallbacks wrap the call in aTaskThe fire-and-forget interaction hooks (
onTableCopyTap,onTableDownloadTap,onContextMenuAppear,onContextMenuTap,onImageTap) and the synconChange(markdown:)(which only yields into a continuation) intentionally remain synchronous — their call sites are non-async UIKit/AppKit delegate methods and SwiftUI action closures, so making them async would only push aTask { }wrapper out to every call site.Refs #144
Validation
make lint— 0 violationsmake test— all tests passmake build-sample— BUILD SUCCEEDEDOSS readiness