Skip to content

Commit

Permalink
🐛fixed completed task not started
Browse files Browse the repository at this point in the history
⚒️update README
  • Loading branch information
Lord-Turmoil committed Dec 1, 2024
1 parent 54c3a55 commit a89617d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
> Before you move on, ensure you have CMake and your C++ compiler supports C++ 17.🫡
> [!WARNING]
> If you build **minet-core** with Debug configuration on Ubuntu 20.04, you may get linker error saying missing `libtsan_preinit.o`. Check [(TSAN) /usr/bin/ld can't find libtsan_preinit.o](https://stackoverflow.com/questions/77858687/tsan-usr-bin-ld-cant-find-libtsan-preinit-o) for solutions.
> If you build **minet-core** with TSan (Thread Sanitizer) on Ubuntu 20.04, you may get linker error saying missing `libtsan_preinit.o`. Check [(TSAN) /usr/bin/ld can't find libtsan_preinit.o](https://stackoverflow.com/questions/77858687/tsan-usr-bin-ld-cant-find-libtsan-preinit-o) for solutions.
## Prepare the Repository

Expand Down Expand Up @@ -60,9 +60,9 @@ int main()
{
WebHostBuilder::Create()
->UseAppSettings()
->Get("/ping", RequestHandler<>::Bind(
->Get("/ping", RequestHandler::Bind(
[](const TextRequest& request, TextResponse& response) {
response.Text().append("pong");
response.Text().assign("pong");
}))
->Build()
->Run();
Expand Down Expand Up @@ -114,17 +114,26 @@ Request handler is where you write the server logic. It takes the request and re
using RequestHandlerFn = std::function<void(const TRequest&, TResponse&)>;
```

To create a request handler, you need to use `RequestHandler<TRequest, TResponse>::Bind()`. By default, it will use `TextRequest` and `TextResponse`. Then, you can register endpoints like this.
**minet-core** provides a convenient way to create request handlers by using predefined templates. For plain text request and response, you can use `RequestHandler` directly. For JSON request and response, you can use `RestfulHandler`. If request and response types are different, you can use `CustomHandler` instead. Below are their definitions.

```cpp
void ping(const TextRequest& request, TextResponse& response);
void echo(const TextRequest& request, JsonResponse& response);
using RequestHandler = RequestHandlerImpl<TextRequest, TextResponse>;
using RestfulHandler = RequestHandlerImpl<JsonRequest, JsonResponse>;
template <typename TRequest, typename TResponse>
using CustomHandler = RequestHandlerImpl<TRequest, TResponse>;
```

```cpp
void text(const TextRequest& request, TextResponse& response);
void json(const JsonRequest& request, JsonResponse& response);
void custom(const TextRequest& request, JsonResponse& response);

// create WebHostBuilder

builder
->Get("/ping", RequestHandler<>::Bind(ping))
->Post("/echo", RequestHandler<TextRequest, JsonResponse>::Bind(echo));
->Get("/text", RequestHandler::Bind(text))
->Post("/json", RestfulHandler::Bind(json))
->Post("/custom", CustomHandler::Bind(custom));
```
See, isn't it easy?😉
Expand Down
4 changes: 2 additions & 2 deletions src/threading/Task.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ template <typename TRoutine> Ref<Task> Task::Create(TRoutine&& routine)

inline Ref<Task> Task::Completed()
{
return CreateRef<Task>([] {}, Private());
return CreateRef<Task>([] {}, Private())->StartAsync();
}

inline Ref<Task> Task::StartAsync()
Expand Down Expand Up @@ -170,7 +170,7 @@ Ref<ValueTask<TResult>> ValueTask<TResult>::Create(TRoutine&& routine)

template <typename TResult> Ref<ValueTask<TResult>> ValueTask<TResult>::Completed(const TResult& result)
{
return CreateRef<ValueTask>([result] { return result; }, Private());
return CreateRef<ValueTask>([result] { return result; }, Private())->StartAsync();
}

template <typename TResult> Ref<ValueTask<TResult>> ValueTask<TResult>::StartAsync()
Expand Down

0 comments on commit a89617d

Please sign in to comment.