Skip to content

Commit

Permalink
hive-common: Add hive.common.functools.once
Browse files Browse the repository at this point in the history
  • Loading branch information
gbenson committed Sep 24, 2024
1 parent b57885f commit 09473ab
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libs/common/hive/common/functools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from itertools import count


def once(func):
"""Decorator that ensures func runs only once.
"""
counter = count()
def wrapper(*args, **kwargs):
if next(counter) != 0:
return None
return func(*args, **kwargs)
return wrapper

0 comments on commit 09473ab

Please sign in to comment.