Skip to content

Commit

Permalink
Add Upgrade-Guide and Learn section to docs (#31)
Browse files Browse the repository at this point in the history
* Fix broken links in announcement banner

* Fix light/dark mode switch icons

* Fix MathJax script not found error

* Update links in announcement banner to use `base_url`

* Replace `Tutorials` with `Learn` section in docs

* Add Upgrade Guide for the v0.7 release

* Fix broken links to the Learn section

* Add legacy tutorials for reference during rebuild

* Update SECURITY.md
  • Loading branch information
mdapena authored Dec 30, 2024
1 parent 01ed0e4 commit 8ec5eb1
Show file tree
Hide file tree
Showing 17 changed files with 2,288 additions and 41 deletions.
8 changes: 4 additions & 4 deletions .github/SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Security Policy

If you think you have identified a security issue in a Pyventus project, please **do not open a public issue**. Instead, follow these steps to securely report the vulnerability:
If you think you have identified a security issue in Pyventus, please **do not open a public issue or discussion**. Instead, follow these steps to securely report the vulnerability:

1. Navigate to the "Security" tab of the repository.
2. Click on "Report a vulnerability" to submit a new report.
1. Navigate to the `Security` tab of the repository.
2. Click on `Report a vulnerability` to submit a new report.
3. Provide a detailed description of the vulnerability, including steps to reproduce if possible.
4. Include any additional information that would be helpful in understanding and addressing the issue.

Our team will carefully review your report and respond promptly. We appreciate you following this process so we can fix issues discreetly. Working together, we can help keep this project and its users secure.
By following this process, you will make sure that these types of issues are handled discreetly and efficiently, keeping both Pyventus and its community secure.

Thanks for your help!
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Finally, by using the <code>emit()</code> method of the event emitter instance,
</ol>

<p style="text-align: justify;">
&emsp;&emsp;Having gained a clear understanding of the workflow showcased in the <code>Hello, World!</code> example, you are now well-equipped to explore more intricate event-driven scenarios and fully harness the capabilities of Pyventus in your own projects. For a deep dive into the package's functionalities, you can refer to the tutorials and API sections.
&emsp;&emsp;Having gained a clear understanding of the workflow showcased in the <code>Hello, World!</code> example, you are now well-equipped to explore more intricate event-driven scenarios and fully harness the capabilities of Pyventus in your own projects. For a deep dive into the package's functionalities, you can refer to the API and Learn sections.
</p>

[//]: # "--------------------------------------------------------------------------------------------------------------"
Expand Down Expand Up @@ -257,7 +257,7 @@ Finally, and in order to initiate the execution of the observable, we called its
</ol>

<p style="text-align: justify;">
&emsp;&emsp;With a clear understanding of the workflow showcased in the <code>Simple Counter</code> example, you are now well-equipped to explore more intricate reactive scenarios and fully harness the capabilities of Pyventus in your own projects. For a deep dive into the package's functionalities, you can refer to the tutorials and API sections.
&emsp;&emsp;With a clear understanding of the workflow showcased in the <code>Simple Counter</code> example, you are now well-equipped to explore more intricate reactive scenarios and fully harness the capabilities of Pyventus in your own projects. For a deep dive into the package's functionalities, you can refer to the API and Learn sections.
</p>

[//]: # "--------------------------------------------------------------------------------------------------------------"
Expand Down
18 changes: 15 additions & 3 deletions docs/.overrides/announce.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
🚀 <b>It's here! <a href="{{ base_url ~ '/release-notes/#0.7.0'}}">Pyventus v0.7.0</a> is now live!</b>
Don't miss the latest updates, featuring <b><a href="{{ base_url ~ '/#a-simple-reactive-example'}}">reactive programming</a></b>,
major <b><a href="{{ base_url ~ '/release-notes/#0.7.0-optimized'}}">optimizations</a></b>, and more!
<b><a href="{{ base_url ~ '/release-notes/#0.7.0'}}">Pyventus v0.7</a> is now live!</b>
Don't miss the <b>latest updates</b>,
featuring <b><a href="{{ base_url ~ '/#a-simple-reactive-example'}}">reactive programming</a></b>,
major <b><a href="{{ base_url ~ '/release-notes/#0.7.0-optimized'}}">optimizations</a></b>, and more!
<div>
<small>
<b>
<i>
Upgrading an existing app? Check out the
<a href="{{ base_url ~ '/learn/upgrade_guide/'}}">Upgrade Guide</a>
for essential changes from Pyventus v0.6!
</i>
</b>
</small>
</div>
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ hide:
</style>

<p style="text-align: justify;" markdown>
&emsp;&emsp;Welcome to the Getting Started section! In this guide, you will learn how to install Pyventus, as well as enable any of its optional dependencies. For more detailed information on how to use this library, you can refer to the Pyventus [Tutorials](tutorials/index.md) or [API Reference](api/index.md).
&emsp;&emsp;Welcome to the Getting Started section! In this guide, you will learn how to install Pyventus, as well as enable any of its optional dependencies. For more detailed information on how to use this library, you can refer to the [API](api/index.md) and [Learn](learn/index.md) sections.
</p>

## Installation
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Finally, by using the <code>emit()</code> method of the event emitter instance,
</ol>

<p style="text-align: justify;">
&emsp;&emsp;Having gained a clear understanding of the workflow showcased in the <code>Hello, World!</code> example, you are now well-equipped to explore more intricate event-driven scenarios and fully harness the capabilities of Pyventus in your own projects. For a deep dive into the package's functionalities, you can refer to the tutorials and API sections.
&emsp;&emsp;Having gained a clear understanding of the workflow showcased in the <code>Hello, World!</code> example, you are now well-equipped to explore more intricate event-driven scenarios and fully harness the capabilities of Pyventus in your own projects. For a deep dive into the package's functionalities, you can refer to the API and Learn sections.
</p>

[//]: # "--------------------------------------------------------------------------------------------------------------"
Expand Down Expand Up @@ -276,7 +276,7 @@ Finally, and in order to initiate the execution of the observable, we called its
</ol>

<p style="text-align: justify;">
&emsp;&emsp;With a clear understanding of the workflow showcased in the <code>Simple Counter</code> example, you are now well-equipped to explore more intricate reactive scenarios and fully harness the capabilities of Pyventus in your own projects. For a deep dive into the package's functionalities, you can refer to the tutorials and API sections.
&emsp;&emsp;With a clear understanding of the workflow showcased in the <code>Simple Counter</code> example, you are now well-equipped to explore more intricate reactive scenarios and fully harness the capabilities of Pyventus in your own projects. For a deep dive into the package's functionalities, you can refer to the API and Learn sections.
</p>

[//]: # "--------------------------------------------------------------------------------------------------------------"
Expand Down
138 changes: 138 additions & 0 deletions docs/learn/events/emitters/asyncio/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
---
hide:
- feedback
---

# AsyncIO Event Emitter

!!! warning "🏗️ Work in Progress"

This section is currently being rebuilt.

<p style='text-align: justify;' markdown>
&emsp;&emsp;Now that we've covered the base `EventEmitter` interface, let's examine one of its official
implementations: the `AsyncIOEventEmitter`.
</p>

## What is it?

<p style='text-align: justify;' markdown>
&emsp;&emsp;The `AsyncIOEventEmitter` is a class that inherits from `EventEmitter` and uses the `AsyncIO`
framework to handle the execution of event emissions.
</p>

## How it works

<p style='text-align: justify;' markdown>
&emsp;&emsp;The `AsyncIOEventEmitter` handles the event emission differently depending on whether it is operating in
a synchronous or asynchronous execution context. In synchronous contexts, it will automatically start an event loop
to run handlers concurrently. In asynchronous contexts, it leverages any existing event loop. Let's explore the
AsyncIOEventEmitter's behavior in more detail:
</p>

### Sync context

<p style='text-align: justify;' markdown>
&emsp;&emsp;When running without an existing `AsyncIO` event loop, the `AsyncIOEventEmitter` automatically
starts a new loop using `asyncio.run()`. Within this loop, it executes the event emission. The
loop then waits for all scheduled tasks to finish before closing. This preserves synchronous
execution while still gaining the benefits of the concurrent execution.
</p>

### Async context

<p style='text-align: justify;' markdown>
&emsp;&emsp;In an asynchronous context where an event loop is already running, the event emission is scheduled and
processed on that existing loop.
</p>

!!! warning "AsyncIO Event Loop Behavior"

<p style='text-align: justify;' markdown>
If the event loop is closed before all callbacks complete, any remaining scheduled tasks will be canceled.
</p>

## Usage

<p style='text-align: justify;' markdown>
&emsp;&emsp;Using the `AsyncIOEventEmitter` is straightforward. To get started, simply create a new instance of
the class and call its `emit()` methods, as shown below:
</p>

=== "`Sync` context"

```Python title="Usage of the AsyncIOEventEmitter" linenums="1" hl_lines="14-16 19"
from pyventus import EventLinker, EventEmitter, AsyncIOEventEmitter


@EventLinker.on("StringEvent")
def sync_event_callback():
print("Sync event callback!")


@EventLinker.on("StringEvent")
async def async_event_callback():
print("Async event callback!")


def main():
event_emitter: EventEmitter = AsyncIOEventEmitter()
event_emitter.emit("StringEvent")


main()
```

=== "`Async` context"

```Python title="Usage of the AsyncIOEventEmitter" linenums="1" hl_lines="14-17 19"
import asyncio
from pyventus import EventLinker, EventEmitter, AsyncIOEventEmitter

@EventLinker.on("StringEvent")
def sync_event_callback():
print("Sync event callback!")


@EventLinker.on("StringEvent")
async def async_event_callback():
print("Async event callback!")


async def main():
event_emitter: EventEmitter = AsyncIOEventEmitter()
event_emitter.emit("StringEvent")
await asyncio.sleep(0.5) # (1)!

asyncio.run(main())
```

1. By awaiting the `asyncio.sleep(0.5)`, we ensure the existing event loop continues running long enough for all
scheduled tasks to finish processing before concluding. Without waiting, closing the loop prematurely could
cause unfinished tasks to be canceled.

## Recap

<p style='text-align: justify;' markdown>
We've explored the `AsyncIOEventEmitter` class in depth:
</p>

<ul style='text-align: justify;' markdown>

<li markdown>
The `AsyncIOEventEmitter` inherits from the `EventEmitter` class
</li>

<li markdown>
To use it, instantiate the class and call methods like `emit()`
</li>

</ul>

<p style='text-align: justify;' markdown>
&emsp;&emsp;By understanding these concepts, you can effectively utilize the `AsyncIOEventEmitter` to emit events
in both synchronous and asynchronous contexts, benefiting from the concurrency features provided by the `AsyncIO`
framework.
</p>

<br>
Loading

0 comments on commit 8ec5eb1

Please sign in to comment.