-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(examples): Create description for each crate in examples/* #3539
Changes from all commits
87f9acb
3c37877
1aba39f
2f0045c
2c8ea7d
0d1e00c
8cf4bc4
1b315dd
a5172a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,15 +16,18 @@ | |
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
//! The program demonstrates asynchronous execution and | ||
//! how to use macros `gstd::async_init`/`gstd::async_main`. | ||
//! This program demonstrates asynchronous execution and how to use macros `gstd::async_init` and | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add a bit more info on the role of async here, as from description it seems same stuff can be done without async. |
||
//! `gstd::async_main`. It uses async to be able to wait for replies to messages it sent during the execution without | ||
//! having to halt the execution and use `handle_reply`. | ||
//! | ||
//! `Init` method gets three addresses, sends "PING" messages | ||
//! to them and waits for at least two replies with any payload ("approvals"). | ||
//! `Init` is async and gets three addresses in the payload, sends "PING" messages to them and waits for | ||
//! at least two replies with any payload ("approvals"). | ||
//! | ||
//! `Handle` processes only "PING" messages. When `handle` gets such message | ||
//! it sends empty requests to the three addresses and waits for just one approval. | ||
//! If an approval is obtained the method replies with "PONG". | ||
//! `Handle` is async and processes only "PING" messages. When `handle` gets such message it sends empty | ||
//! requests to the three addresses and waits for just one approval. If an approval is obtained the | ||
//! method sends a [`reply()`] with "PONG". | ||
//! | ||
//! [`reply()`]: msg::reply | ||
|
||
use crate::InputArgs; | ||
use futures::future; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,15 @@ | |
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
//! This program demonstrates the use of an async recursive function using the [`async_recursion`] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Give more higher level explanations of the async execution flow. |
||
//! macro. | ||
//! | ||
//! `Init` method gets one address in the payload, which is saves. | ||
//! | ||
//! `Handle` is async and calls the recursive function with the payload as an i32 parameter `val`. | ||
//! The function then sends a message with payload "PING" and awaits reply, then calls itself with | ||
//! `val - reply.len()` while `val - reply.len() > 0`. | ||
|
||
use async_recursion::async_recursion; | ||
use gstd::{msg, prelude::*, ActorId}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,59 @@ | ||
// This file is part of Gear. | ||
|
||
// Copyright (C) 2022-2023 Gear Technologies Inc. | ||
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
//! This program demonstrates the use of [`gstd::msg`] syscalls from an async environment. | ||
//! | ||
//! `Handle` is async and gets a [`Kind`] in the payload, executing a syscall based on the `Kind`, | ||
//! and sending a message back to the source with the payload "PONG". | ||
//! | ||
//! [`Send`] uses the [`send_for_reply()`] syscall to send a message back to the source, containing | ||
//! the `kind` in the payload. | ||
//! | ||
//! [`SendWithGas(gas)`] uses the [`send_with_gas_for_reply()`] syscall to send a message back to | ||
//! the source, containing the `kind` in the payload, and `gas` as the gas limit. | ||
//! | ||
//! [`SendBytes`] uses the [`send_bytes_for_reply()`] syscall to send a message back to the source, | ||
//! containing the `kind` encoded as bytes in the payload. | ||
//! | ||
//! [`SendBytesWithGas(gas)`] uses the [`send_bytes_with_gas_for_reply()`] syscall to send a message | ||
//! back to the source, containing the `kind` encoded as bytes in the payload and `gas` as the gas | ||
//! limit. | ||
//! | ||
//! [`SendCommit`] uses the [`MessageHandle`], pushing the `kind` encoded as bytes and using | ||
//! [`commit_for_reply()`] to send the message back to the source. | ||
//! | ||
//! [`SendCommitWithGas(gas)`] uses the [`MessageHandle`], pushing the `kind` encoded as bytes and | ||
//! using [`commit_with_gas_for_reply()`] to send the message back to the source with `gas` as the | ||
//! gas limit. | ||
Comment on lines
+24
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to literally explain every step of the program. These steps are clear, btw. State main of this tester crate (look at the usage). |
||
//! | ||
//! [`Send`]: Kind::Send | ||
//! [`SendWithGas(gas)`]: Kind::SendWithGas | ||
//! [`SendBytes`]: Kind::SendBytes | ||
//! [`SendBytesWithGas(gas)`]: Kind::SendBytesWithGas | ||
//! [`SendCommit`]: Kind::SendCommit | ||
//! [`SendCommitWithGas(gas)`]: Kind::SendCommitWithGas | ||
//! [`send_for_reply()`]: msg::send_for_reply | ||
//! [`send_with_gas_for_reply()`]: msg::send_with_gas_for_reply | ||
//! [`send_bytes_for_reply()`]: msg::send_bytes_for_reply | ||
//! [`send_bytes_with_gas_for_reply()`]: msg::send_bytes_with_gas_for_reply | ||
//! [`commit_for_reply()`]: MessageHandle::commit_for_reply | ||
//! [`commit_with_gas_for_reply()`]: MessageHandle::commit_with_gas_for_reply | ||
|
||
use crate::Kind; | ||
use gstd::{ | ||
msg::{self, MessageHandle}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add some information about the execution. Docs should give some more description on async execution flow in this example.