Package 

Class CloseOnce

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    
    public final class CloseOnce
     implements AutoCloseable
                        

    Utility to make AutoCloseable idempotent. Compose via delegation: class Foo(...) : AutoCloseable by CloseOnce({ ... }). Thread-safe, performing a no-op after the first close.

    • Constructor Summary

      Constructors 
      Constructor Description
      CloseOnce(Function0<Unit> onClose)
    • Method Summary

      Modifier and Type Method Description
      Unit close()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CloseOnce

        CloseOnce(Function0<Unit> onClose)
        Parameters:
        onClose - The function to invoke on the first call to close.