Skip to content

Commit 95239d0

Browse files
Copilotfregante
andcommitted
Add wait helper documentation to README
Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
1 parent 3c07716 commit 95239d0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

readme.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,30 @@ if (pageDetect.isOrganizationProfile()) {
6767
}
6868
```
6969

70+
### Async detections with `wait`
71+
72+
The `wait` helper function allows you to wait for a detection to become true by repeatedly checking it on each animation frame. This is useful for DOM-based detections that need to wait for elements to appear before the document is fully loaded.
73+
74+
```js
75+
import {wait, isOrganizationProfile} from 'github-url-detection';
76+
77+
async function init() {
78+
// Wait for the detection to return true or for the document to be complete
79+
if (!await wait(isOrganizationProfile)) {
80+
return; // Not an organization profile
81+
}
82+
83+
// The page is now confirmed to be an organization profile
84+
console.log('On organization profile!');
85+
}
86+
```
87+
88+
The `wait` function:
89+
- Repeatedly calls the detection function on each animation frame
90+
- Stops when the detection returns `true` or when `document.readyState` is `'complete'`
91+
- Returns the final result of the detection
92+
- Works with any detection function that returns a boolean
93+
7094
## Related
7195

7296
- [github-reserved-names](https://github.com/Mottie/github-reserved-names) - Get a list, or check if a user or organization name is reserved by GitHub.

0 commit comments

Comments
 (0)