whisker.callback¶
whisker/callback.py
Copyright © 2011-2020 Rudolf Cardinal (rudolf@pobox.com).
This file is part of the Whisker Python client library.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Classes to implement callbacks via the Whisker API.
-
class
whisker.callback.
CallbackDefinition
(event: str, callback: Callable[..., Any], args: List[Any] = None, kwargs: Dict[str, Any] = None, target_n_calls: int = 0, swallow_event: bool = False)[source]¶ Event callback handler. Distinct from any particular network/threading model, so all can use it.
Parameters: - event – Whisker event name
- callback – user-supplied callback function
- args – positional arguments to
callback
- kwargs – keyword arguments to
callback
- target_n_calls –
0
to keep calling indefinitely, os a positive integer to make that many calls (upon receiving the relevant event) but then to forget about the callback and mark it as defunct - swallow_event – make the API swallow the event, so it’s not seen by our client task?
-
class
whisker.callback.
CallbackHandler
[source]¶ Implements callbacks based on Whisker events.
-
add
(target_n_calls: int, event: str, callback: Callable[..., Any], args: List[Any] = None, kwargs: Dict[str, Any] = None, swallow_event: bool = True) → None[source]¶ Adds a callback to the handler.
See
CallbackDefinition
.
-
add_persistent
(event: str, callback: Callable[..., Any], args: List[Any] = None, kwargs: Dict[str, Any] = None, swallow_event: bool = True) → None[source]¶ Adds a persistent callback for the specified event.
-
add_single
(event: str, callback: Callable[..., Any], args: List[Any] = None, kwargs: Dict[str, Any] = None, swallow_event: bool = True) → None[source]¶ Adds a single-shot callback for the specified event.
-