ui.util.rateLimit
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ห่อหุ้มฟังก์ชันเพื่อให้เรียกใช้ได้สูงสุด 1 ครั้งต่อช่วงเวลา หากมีการเรียกใช้ฟังก์ชัน Wrapper มากกว่า 1 ครั้ง ระบบจะดำเนินการกับการเรียกใช้ครั้งแรกเท่านั้น และการเรียกใช้ครั้งต่อๆ ไปจะไม่มีผลจนกว่าจะผ่านช่วงเวลาที่กำหนดไปแล้ว ซึ่งใช้เพื่อให้มั่นใจว่าฟังก์ชันที่ใช้ทรัพยากรมากจะทำงานทันที แต่จะไม่ทำงานซ้ำๆ
ตัวอย่างการใช้งาน: สำหรับการเรียกกลับเมื่อคลิก ui.Button เพื่อป้องกันไม่ให้มีการดับเบิลคลิกปุ่มโดยไม่ตั้งใจและไม่ให้มีการเรียกกลับ 2 ครั้ง
แสดงผลฟังก์ชันที่จำกัดอัตรา
การใช้งาน | การคืนสินค้า |
---|
ui.util.rateLimit(func, delay, scope) | ฟังก์ชัน |
อาร์กิวเมนต์ | ประเภท | รายละเอียด |
---|
func | ฟังก์ชัน | ฟังก์ชันที่จะเรียกใช้ |
delay | ตัวเลข | หลังจากเรียกและเรียกใช้ฟังก์ชันแล้ว จำนวนมิลลิวินาทีที่จะหน่วงเวลาก่อนอนุญาตให้เรียกใช้ฟังก์ชันเพิ่มเติม |
scope | ออบเจ็กต์ (ไม่บังคับ) | ออบเจ็กต์ในขอบเขตที่จะเรียกใช้ฟังก์ชัน |
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 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. |"]]