A framework write in C++11 (compatible with up to C++17 standard) that similar with Flutter but without build GUI. Just for backend software. With object management, software architecture management and async runtime management.
Welcome to nullsafety world! Now framework provide nullsafety feature. ref for non-null refs of object and option for nullable refs of object.
-
ref, option and weakref for object management (implement base on std::shared_ptr, cross-platform, less buggy and nullsafety)
-
widget and context for software architecture management. (Widget tree layout and lifecycle just similar with Flutter. If you familiar with Flutter, there is nothing new for you to learn)
-
all async apis directly build upon context, init async tasks right after State::initState and dispose async resource when State::dispose (so that async work managed by framework). Ease code and less memory lack problem and less state-unknown conflict problem.
-
compatible with Windows/Linux/macOS and more. compatible with C++17/14/11. CMake build rule. (Linux/macOS support C++20 but Windows MSVC has a bug on std::string constructor that cause compile error when enable C++20 flag)
// StatelessWidget example
class MyWidget : public StatelessWidget {
ref<Widget> build(ref<BuildContext> context) override
{
// build your child widget without state
...
}
};
// StatefulWidget example
class MyWidget : public StatefulWidget {
ref<State<>> createState() override;
};
class _MyWidgetState : public State<MyWidget> {
ref<Widget> build(ref<BuildContext> context) override
{
// build your child widget with state
...
}
};
inline ref<State<>> MyWidget::createState() { return Object::create<_MyWidgetState>(); }
// run your widget as root widget
// framework will automatically unfold the widget tree
runApp(Object::create<MyWidget>());
- as if both parent and child are StatefulWidget
- as if the widget is StatefulWidget
This framework provides async task management. All async components showup in fundamental folder. The common async tasks already build in framework.
- Timer (Callback style async. Also see: Future::delay)
- File
- Http
Except Timer, all async components take advantage of Future and Stream to implement async.
If you not satisfy with build-in async api. This framework provides Completer for build Future and StreamController for build Stream to achieve async program.
All async api request one more argument than traditional async programming language. They always request ref<State<>> or ref<ThreadPool>, Because this framework is designed for multi-thread application. Async task must need to know which thread it should return to. For example:
class MyState : public State<MyWidget> {
using super = State<MyWidget>;
lateref<Timer> _timer;
void initState() override
{
super::initState();
_timer = Timer::delay(self() /* timer always request a reference of current State to build a timer object */,
Duration(1000), []{ ... });
}
};
-
test case and demo
https://github.com/JohnGu9/async_runtime_test