ui.util.rateLimit
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
यह फ़ंक्शन को रैप करता है, ताकि उसे हर इंटरवल में ज़्यादा से ज़्यादा एक बार कॉल किया जा सके. अगर रैपर फ़ंक्शन को एक से ज़्यादा बार कॉल किया जाता है, तो सिर्फ़ पहला कॉल पूरा होगा. साथ ही, इंटरवल खत्म होने तक बाद के किसी भी कॉल का कोई असर नहीं होगा. इसका इस्तेमाल यह पक्का करने के लिए किया जा सकता है कि महंगा फ़ंक्शन तुरंत लागू हो जाए, लेकिन बार-बार लागू न हो.
इस्तेमाल का उदाहरण: ui.Button पर क्लिक करने के लिए कॉलबैक फ़ंक्शन का इस्तेमाल किया जाता है, ताकि बटन पर गलती से दो बार क्लिक न हो और कॉलबैक फ़ंक्शन दो बार न चले.
यह फ़ंक्शन, दर के हिसाब से सीमित किया गया फ़ंक्शन दिखाता है.
इस्तेमाल | रिटर्न |
---|
ui.util.rateLimit(func, delay, scope) | फ़ंक्शन |
आर्ग्यूमेंट | टाइप | विवरण |
---|
func | फ़ंक्शन | कॉल करने के लिए फ़ंक्शन. |
delay | नंबर | फ़ंक्शन को कॉल और एक्ज़ीक्यूट करने के बाद, फ़ंक्शन को दोबारा कॉल करने से पहले लगने वाले मिलीसेकंड की संख्या. |
scope | ऑब्जेक्ट, ज़रूरी नहीं है | वह ऑब्जेक्ट जिसके स्कोप में फ़ंक्शन को कॉल करना है. |
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-07-26 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 2025-07-26 (UTC) को अपडेट किया गया."],[[["\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. |"]]