Skip to content

Commit

Permalink
docs: update relevant docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Undertone0809 committed Jun 15, 2023
1 parent 10af06b commit c760406
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
46 changes: 45 additions & 1 deletion docs/publisher_dispatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,48 @@ if __name__ == '__main__':
main()
```

It should be noted that the order of the three elements `args[0]`, `args[1]`, and `args[2]` in the above example is not uniquely determined, which depends on the execution time of the subscriber's callback function. However, in most cases, we cannot judge which subscriber callback function ends first, so `broadcast-service` development specifications recommend that when using this function, let the return value types of the subscriber callback functions be consistent as much as possible to reduce the cost of additional data judgment.
It should be noted that the order of the three elements `args[0]`, `args[1]`, and `args[2]` in the above example is not uniquely determined, which depends on the execution time of the subscriber's callback function. However, in most cases, we cannot judge which subscriber callback function ends first, so `broadcast-service` development specifications recommend that when using this function, let the return value types of the subscriber callback functions be consistent as much as possible to reduce the cost of additional data judgment.

## Passing different parameters when publishing a topic multiple times

If you want to pass different parameters when publishing a topic multiple times. The following example show how to do.

```python
from broadcast_service import broadcast_service


@broadcast_service.on_listen("test_split_parameter")
def query_from_google(**kwargs):
print(kwargs['split_parameter'])


keywords = ["What is NLP?", "Apple", "Tomorrow temperature"]
broadcast_service.config(
num_of_executions=3,
split_parameters=keywords
).publish("test_split_parameter")
```

For stability, we provide a specification. You must use `**kwargs`, `kwargs['split_parameter']` to receive parameters.

**output**
```text
What is NLP?
Apple
Tomorrow temperature
```

The above example and the following notation are equivalent.

```python
from broadcast_service import broadcast_service

@broadcast_service.on_listen("test_split_parameter")
def query_from_google(**kwargs):
print(kwargs['split_parameter'])

keywords = ["What is NLP?", "Apple", "Tomorrow temperature"]
broadcast_service.publish("test_split_parameter", {"split_parameter": keywords[0]})
broadcast_service.publish("test_split_parameter", {"split_parameter": keywords[1]})
broadcast_service.publish("test_split_parameter", {"split_parameter": keywords[2]})
```
7 changes: 6 additions & 1 deletion docs/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ Please update the latest version. The old version is shit.
```bash
pip install --upgrade broadcast-service
```
## v2.1.0 2023-06-15

#### feat
1. Add split_parameters for config(). [#docs](publisher_dispatch?id=passing-different-parameters-when-publishing-a-topic-multiple-times)

## v2.0.0 2023-06-14

#### feat
1. Add publisher dispatch config. It can publish topic with a complex mode.
1. Add publisher dispatch config. It can publish topic with a complex mode. [#12](https://github.com/Undertone0809/broadcast-service/pull/12)
- provide publisher callback
- provide the return value of subscriber callbacks
- provide multiple call publish at once
Expand Down

0 comments on commit c760406

Please sign in to comment.