Skip to content

Commit e7cd4dc

Browse files
committed
UPD | docs
1 parent fd5a4ea commit e7cd4dc

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

docs/content/docs/intro/async-context.mdx

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,65 @@ manapi::async::run([]() -> manapi::future<> {
261261
});
262262
```
263263
264+
#### Lifetime Of Objects
265+
266+
If you want to pass some variables to an async function, you must understand how lifetime works for objects.
267+
268+
We have `some_func`:
269+
270+
```cpp
271+
manapi::future<> some_func (std::string &&a) {
272+
std::cout << "SOME FUNC " << a << "\n";
273+
co_await manapi::async::delay{1000};
274+
std::cout << "FIN " << a << "\n";
275+
}
276+
```
277+
278+
Bad example
279+
280+
```cpp
281+
manapi::future<void> task (nullptr);
282+
283+
{
284+
// ❌ Your object will be destroyed
285+
task = some_func (std::string ("hello world"));
286+
}
287+
288+
// ❌ SEGFAULT
289+
co_await task;
290+
```
291+
292+
But you can do this instead
293+
294+
```cpp
295+
manapi::future<void> task (nullptr);
296+
std::string str ("hello world");
297+
298+
{
299+
// ✅ It's okay
300+
task = some_func (std::move(str));
301+
}
302+
303+
// ✅ OK
304+
co_await task;
305+
```
306+
307+
#### Detached Task
308+
309+
<Callout title="Warning" type="warn">
310+
You cannot call an async function in a way that is both detached and awaitable simultaneously
311+
</Callout>
312+
313+
```cpp
314+
manapi::future<void> task = ...;
315+
316+
// Task is detached now
317+
task ();
318+
319+
// ❌ SEGFAULT
320+
co_await task;
321+
```
322+
264323
## Stopping Mechanism
265324
266325
To stop the current context, use the asynchronous ```stop()``` method in the ```manapi::async::context``` class:

docs/content/docs/intro/syslogs.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@ In release mode, messages with the ```LOG_TRACE_HARD``` level are removed.
2020
</Callout>
2121

2222
```cpp
23+
24+
// define the application logging name
25+
#define LOGNAME "app"
26+
2327
#include <manapihttp/ManapiInitTools.hpp> // manapi::init_tools::log_trace_init
2428
#include <manapihttp/ManapiDebug.hpp> // manapi_log_trace
2529

2630
int main(int argc, char *argv[]) {
2731
// System log initialization (not thread-safe)
2832
manapi::init_tools::log_trace_init(manapi::debug::LOG_TRACE_HIGH);
33+
// Disable logs by ManapiHttp
34+
manapi::init_tools::log_name_enable("manapihttp", false);
2935
// Print message (method is blocking and thread-safe)
3036
manapi_log_trace(manapi::debug::LOG_TRACE_HIGH, "Application has started!");
3137
}

0 commit comments

Comments
 (0)