hololinked.client.abstractions.ConsumedThingEvent
Client side event subscription abstraction. Subclass from here to implement protocol specific event subscription.
Source code in repo/hololinked/hololinked/client/abstractions.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 | |
Functions
__init__
__init__(resource: EventAffordance | PropertyAffordance, logger: BoundLogger, owner_inst: Any) -> None
Initialize a consumed thing event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
EventAffordance | PropertyAffordance
|
dataclass object representing the event or an observable property |
required |
|
BoundLogger
|
logger instance |
required |
|
Any
|
the parent object that owns this event |
required |
Source code in repo/hololinked/hololinked/client/abstractions.py
subscribe
subscribe(callbacks: list[Callable] | Callable, asynch: bool = False, concurrent: bool = False, deserialize: bool = True) -> None
Subscribe to the event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[Callable] | Callable
|
callback or list of callbacks to add |
required |
|
bool
|
whether to start an async(-io task) event listener instead of a threaded listener |
False
|
|
bool
|
|
False
|
|
bool
|
if |
True
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if no form is found for the event subscription |
Source code in repo/hololinked/hololinked/client/abstractions.py
unsubscribe
listen
listen(form: Form, callbacks: list[Callable], concurrent: bool = True, deserialize: bool = True) -> None
Listen to events and call the callbacks in threaded mode.
This method needs to be invoked by the subscribe() method. Use async_listen() for asyncio mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Form
|
form to use for event subscription |
required |
|
list[Callable]
|
list of callbacks to call on event |
required |
|
bool
|
whether to run each callback concurrently in a separate thread |
True
|
|
bool
|
whether to deserialize the event payload before passing to callbacks |
True
|
Source code in repo/hololinked/hololinked/client/abstractions.py
async_listen
async
async_listen(form: Form, callbacks: list[Callable], concurrent: bool = True, deserialize: bool = True) -> None
Listen to events and call the callbacks.
This method needs to be invoked by the subscribe() method in asyncio mode. Use listen() for threaded mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Form
|
form to use for event subscription |
required |
|
list[Callable]
|
list of callbacks to call on event |
required |
|
bool
|
whether to run each callback concurrently as separate tasks |
True
|
|
bool
|
whether to deserialize the event payload before passing to callbacks |
True
|
Source code in repo/hololinked/hololinked/client/abstractions.py
schedule_callbacks
Schedule the callbacks to be called with the event data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[Callable]
|
list of callbacks to call |
required |
|
Any
|
event data to pass to the callbacks |
required |
|
bool
|
whether to run each callback in a separate thread concurrently |
False
|
Source code in repo/hololinked/hololinked/client/abstractions.py
async_schedule_callbacks
async
Async schedule the callbacks to be called with the event data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list of callbacks to call |
required | |
|
Any
|
event data to pass to the callbacks |
required |
|
bool
|
whether to run each callback in a separate asyncio task concurrently |
False
|
Source code in repo/hololinked/hololinked/client/abstractions.py
add_callbacks
Add callbacks to the event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[Callable] | Callable
|
callback or list of callbacks to add |
required |