From acd4bcbc40cc79096626dcdf6a75d318ad129dd2 Mon Sep 17 00:00:00 2001 From: johannst Date: Mon, 5 Oct 2020 23:03:15 +0200 Subject: added example to README --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/README.md b/README.md index f4702ac..39642d9 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,45 @@ Supported platforms are `Linux` running on - `x86_64` - `arm64` +### Example + +```cpp +// file: demo.cc +#include "lib/executor.h" +#include "lib/thread.h" +#include + +struct MyThread : public nMatcha::Thread { + virtual void threadFn() override { + puts("like"); + yield(); + puts("tea"); + } +}; + +int main() { + nMatcha::Executor e; + e.spawn(std::make_unique()); + e.spawn(nMatcha::FnThread::make([](nMatcha::Yielder& y) { + puts("I"); + y.yield(); + puts("green"); + })); + e.run(); + return 0; +} +``` + +This example `demo.cc` can be run as +```bash +> make -C lib && g++ -o demo demo.cc -I. lib/libmatcha.a && ./demo +... +I +like +green +tea +``` + ### Setup development environment This project provides a [`Dockerfile`](docker/Dockerfile) with all the required tools pre-installed. -- cgit v1.2.3