-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
17 changed files
with
2,288 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
  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> | ||
  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> | ||
  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> | ||
  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> | ||
  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> | ||
  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> | ||
  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> |
Oops, something went wrong.