类 SingleFlight<K,V>

java.lang.Object
cn.kingyen.singleflight.core.SingleFlight<K,V>
类型参数:
K - key type
V - value type

public class SingleFlight<K,V> extends Object
SingleFlight is a utility class for access suppression。
作者:
KingYen.
  • 字段详细资料

  • 构造器详细资料

    • SingleFlight

      public SingleFlight()
  • 方法详细资料

    • doOnce

      public V doOnce(K key, Supplier<V> fn)
      Perform an operation, and if an operation with the same key is in progress, wait for it to complete and return the result
      参数:
      key - operating key
      fn - the actual operation performed
      返回:
      result of operation
      抛出:
      RuntimeException - the exception occurs during operation execution
    • doOnceFuture

      public CompletableFuture<V> doOnceFuture(K key, Supplier<V> fn)
      Execute an operation asynchronously, and if an operation with the same key is in progress, wait for it to complete and return the result
      参数:
      key - operating key
      fn - the actual operation performed
      返回:
      CompletableFuture containing the result of the operation
    • forget

      public boolean forget(K key)
      Forcibly delete a key and cancel all waiting operations
      参数:
      key - the key to delete
      返回:
      Return true if key exists and is deleted, false otherwise
    • pendingCount

      public int pendingCount()
      Gets the number of operations currently in progress
      返回:
      number of ongoing operations