# The Midio Engine

## Overview

Midio compiled to bytecode, meaning that before the node graph is executed, it is compiled to a list of instructions, which is then executed by the \[**Midio VM**]\(#The Midio VM). This makes the code run a lot faster than it would if we had to interpret the node graph during execution.

The Midio engine is a virtual machine that executes the bytecode produced by the compiler. It is responsible for hooking up all the native functionality that the code depends on, like all external functions, and services.

The bytecode is executed in Midio processes, of which several can run concurrently, executing different flows.

### Processes

A process represents an isolated environment for bytecode to be executed in. It contains its own call stack, and its own memory heap, and is not able to affect other processes directly.

Processes are created by supplying it a module to run. It can then be handed to the scheduler, which will eventually schedule it for execution.

A process can be in one of the following states:

* **Runnable** - The process is ready to be scheduled by the scheduler
* **DoneAndWaitingForCleanup** - The process is done executing, and is waiting for the engine to clean up its resources, like heap and stack.
* **Error** - The process has experienced an error, and is waiting for cleanup.
* **Paused** - The process is paused for debugging purposes
* **Stepping** - The process is in debugger state, and the middle of performing a single. The difference from being **Runnable** is that the process will enter the **Paused** state as soon as it hits an instruction corresponding to a node, like a `CallFunction` instruction.

### Services

> Services are not something the user directly interfaces with, but are accessed through various functions in the [standard library](/midio-docs/built-in-nodes/core-std.md).

Services are components that provide various capabilities to your programs, such as offering an HTTP server, scheduling flows at specific intervals, and more. These services are shared between processes and are instantiated automatically when a node that requires the service is used. This process is entirely transparent to the user, and the way you interact with services is through funtions whose implementation happen to use them.

> Currently, you cannot create your own service, but this will eventually be possible.

Some existing services include:

* **HttpServer**: Enables the creation of HTTP APIs. Some functions that use this service include `HttpEndpoint` and `HttpResponse`.
* **Scheduler**: Allows scheduling of flows to run at specific intervals. The `Timer` event uses this sevices.
* **Testing**: Offers a way for tests to report their results. Some nodes using this service includes the `Test` event and the various assertion functions, like: `AssertEqual`, `AssertTrue` and `AssertFalse`.
* **Ephemeral Store**: Provides an in-memory key-value store (non-persistent) for storing data between various flow executions. This service is accessed through the functions in the `EphemeralStore` module.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.midio.com/midio-docs/the-midio-engine.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
