-
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 5 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,17 @@ | |
// 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`. | ||
//! | ||
//! `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 [`msg`] syscalls from an async environment. | ||||||
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.
Suggested change
|
||||||
//! | ||||||
//! `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}, | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,27 @@ | |
// 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 use of an async `handle` entry point using the `gstd::async_main` | ||
//! macro. | ||
//! | ||
//! `Init` method gets an address of a program in the payload, which should accept "PING" messages | ||
//! and reply with "PONG". | ||
//! | ||
//! `Handle` is async and gets a [`Command`] in the payload, executes a certain action based on it, | ||
//! and send a [`reply()`] with a payload containing the id of the current message. There are two commands | ||
//! that can be executed: [`Common`] and [`Mutex`]. | ||
//! | ||
//! [`Common`] sends three async messages to the ping program, with the payload "PING", | ||
//! awaits the reply and asserts that the reply is "PONG". | ||
//! | ||
//! [`Mutex`] asynchronously locks the mutex, awaiting it, sends a message back to the | ||
//! source of the current message, containing the current message id in the payload, and then | ||
//! it sends a ping message, awaiting the reply and asserting that the reply is "PONG". | ||
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. it's not clear what this wasms does, what's the purpose of that. |
||
//! | ||
//! [`Common`]: Command::Common | ||
//! [`Mutex`]: Command::Mutex | ||
//! [`reply()`]: msg::reply | ||
|
||
use crate::Command; | ||
use gstd::{msg, prelude::*, sync::Mutex, ActorId}; | ||
|
||
|
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.