Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #82 - Add timeout option #88

Merged
merged 4 commits into from
Nov 26, 2024
Merged

Fixes #82 - Add timeout option #88

merged 4 commits into from
Nov 26, 2024

Conversation

uzairfarooq
Copy link
Owner

@uzairfarooq uzairfarooq commented Nov 25, 2024

This PR adds a new timeout option to both arrive and leave events that automatically unbinds the event and calls the callback with null after the specified number of milliseconds if no matching elements are found/removed.

This is useful for cases where you want to stop watching for elements after a certain time period.

Usage

// Will call callback with null after 2 seconds if no matching element is found
document.arrive(".dynamic-content", { timeout: 2000 }, function(elem) {
    if (elem === null) {
        console.log("Element not found within timeout");
        return;
    }
    console.log("Element found:", elem);
});

Related Issues

Closes #82

@uzairfarooq uzairfarooq self-assigned this Nov 25, 2024
@uzairfarooq uzairfarooq linked an issue Nov 25, 2024 that may be closed by this pull request
@uzairfarooq uzairfarooq merged commit bf9d2b6 into master Nov 26, 2024
@uzairfarooq uzairfarooq deleted the timeout branch November 26, 2024 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature suggestion: Add timeout
1 participant