Skip to content

Auto disable - #4

Merged
alorma merged 5 commits into
mainfrom
auto_disabe
Jan 2, 2026
Merged

Auto disable#4
alorma merged 5 commits into
mainfrom
auto_disabe

Conversation

@alorma

@alorma alorma commented Jan 2, 2026

Copy link
Copy Markdown
Owner

Summary

This PR introduces the autoDisable parameter to the FireAndForget library, enabling automatic flag disabling on first access without requiring manual disable() calls.

Changes

Core Library Updates

FireAndForget.kt (core/src/commonMain/kotlin/com/alorma/fireandforget/FireAndForget.kt:7)

  • Added autoDisable: Boolean = false parameter to the FireAndForget constructor
  • When true, the flag automatically disables itself on first call to isEnabled()

FireAndForgetRunner.kt (core/src/commonMain/kotlin/com/alorma/fireandforget/FireAndForgetRunner.kt:4)

  • Refactored isEnabled() from abstract to concrete method with auto-disable logic
  • Added new protected abstract method checkEnabled() for runner implementations
  • isEnabled() now checks the flag state and automatically calls disable() if:
    • The flag is enabled AND
    • autoDisable is set to true

Implementation Updates

Updated all runner implementations to use the new checkEnabled() method:

  • SettingsFireAndForgetRunner (multiplatform-settings/src/commonMain/kotlin/com/alorma/fireandforget/mukltiplatform/settings/SettingsFireAndForgetRunner.kt)
  • InMemoryFireAndForgetRunner (samples/shared/src/commonMain/kotlin/com/alorma/fireandforget/shared/InMemoryFireAndForgetRunner.kt)

Documentation

README.md updates include:

  • Added autoDisable parameter documentation
  • New "Auto-Disable Feature" section with usage examples
  • Updated API reference to reflect the checkEnabled() pattern
  • Implementation note explaining why custom runners must override checkEnabled() instead of isEnabled()

Sample Code

  • Updated FireTwo.kt to demonstrate the autoDisable feature in action

Use Case

Perfect for truly "fire-and-forget" scenarios where there's no natural completion callback:

class QuickTip(runner: FireAndForgetRunner) : FireAndForget(
  fireAndForgetRunner = runner,
  name = "quick_tip",
  autoDisable = true  // Automatically disables after first isEnabled() call
)

// First call: returns true and automatically disables
if (quickTip.isEnabled()) {
  showTooltip("Here's a quick tip!")
  // No need to call quickTip.disable() - it's automatic!
}

// Subsequent calls: returns false
quickTip.isEnabled() // false

Architecture Decision

The isEnabled() method is now final in FireAndForgetRunner to ensure the auto-disable logic cannot be bypassed by custom implementations. All runner implementations must override checkEnabled() instead, which is called internally by isEnabled().

Testing

  • All existing tests pass with the new parameter (backward compatible with autoDisable = false default)
  • Android and Desktop sample apps updated to demonstrate the feature

@alorma
alorma merged commit 552ffea into main Jan 2, 2026
4 checks passed
@alorma
alorma deleted the auto_disabe branch January 2, 2026 23:36
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.

1 participant