ui.util.rateLimit
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
تابعی را می پیچد تا اجازه دهد حداکثر یک بار در هر بازه فراخوانی شود. اگر تابع wrapper بیش از یک بار فراخوانی شود، فقط اولین فراخوانی انجام می شود و هیچ فراخوانی بعدی تا زمانی که بازه زمانی سپری نشده باشد اثری نخواهد داشت. این را می توان برای اطمینان از اجرای عملکردی که هزینه آن گران است، بلافاصله اجرا می شود اما به طور مکرر اجرا نمی شود استفاده شود.
مثال استفاده: برای پاسخ به تماس با کلیک بر روی یک دکمه رابط کاربری، به منظور جلوگیری از دوبار کلیک کردن تصادفی روی دکمه و اجرای دوبار پاسخ تماس.
تابع نرخ محدود را برمیگرداند.
استفاده | برمی گرداند | ui.util.rateLimit(func, delay, scope ) | تابع |
استدلال | تایپ کنید | جزئیات | func | تابع | تابع برای تماس. |
delay | شماره | پس از فراخوانی و اجرای تابع، تعداد میلی ثانیه هایی که باید قبل از فراخوانی اضافی تابع به تاخیر بیفتند. |
scope | شیء، اختیاری | شیئی که در محدوده آن تابع فراخوانی می شود. |
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eLimits a function's execution to at most once per specified interval, preventing rapid, repeated calls.\u003c/p\u003e\n"],["\u003cp\u003eUseful for optimizing expensive functions or preventing unintended double-click actions, such as on UI buttons.\u003c/p\u003e\n"],["\u003cp\u003eReturns a rate-limited version of the original function, accepting the function, delay, and optional scope as parameters.\u003c/p\u003e\n"],["\u003cp\u003eUtilizes a delay mechanism to ensure subsequent calls are ignored until the interval has elapsed, guaranteeing controlled execution.\u003c/p\u003e\n"]]],[],null,["# ui.util.rateLimit\n\n\u003cbr /\u003e\n\nWraps a function to allow it to be called, at most, once per interval. If the wrapper function is called more than once, only the first call will go through, and no subsequent invocations will have an effect until the interval has elapsed. This can be used to ensure a function that is expensive to run executes immediately but doesn't execute repeatedly.\n\n\u003cbr /\u003e\n\nExample use: For the callback to a click on a ui.Button, in order to prevent the button from being accidentally double-clicked and the callback running twice.\n\nReturns the rate-limited function.\n\n| Usage | Returns |\n|---------------------------------------------|----------|\n| `ui.util.rateLimit(func, delay, `*scope*`)` | Function |\n\n| Argument | Type | Details |\n|----------|------------------|------------------------------------------------------------------------------------------------------------------------------------------|\n| `func` | Function | Function to call. |\n| `delay` | Number | After the function is called and executed, the number of milliseconds to delay before allowing an additional invocation of the function. |\n| `scope` | Object, optional | Object in whose scope to call the function. |"]]