Skip to content

Commit 3bef667

Browse files
committed
Rework debouncer
1 parent 77ef32f commit 3bef667

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

docs/source/examples/Widget Events.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,14 @@
391391
" execution until after `wait` seconds\n",
392392
" have elapsed since the last time it was invoked. \"\"\"\n",
393393
" def decorator(fn):\n",
394+
" timer = None\n",
394395
" def debounced(*args, **kwargs):\n",
396+
" nonlocal timer\n",
395397
" def call_it():\n",
396398
" fn(*args, **kwargs)\n",
397-
" try:\n",
398-
" debounced.t.cancel()\n",
399-
" except(AttributeError):\n",
400-
" pass\n",
401-
" debounced.t = Timer(wait, call_it)\n",
399+
" if timer is not None:\n",
400+
" timer.cancel()\n",
401+
" timer = Timer(wait, call_it)\n",
402402
" return debounced\n",
403403
" return decorator"
404404
]

0 commit comments

Comments
 (0)