Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document async mode with an example #218

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions docs/faq.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# FAQ

(1). `Prologue` supports two HTTP server: `httpbeast` and `asynchttpserver`. If you are in Linux or MacOS, use `--threads:on` to enable the multi-threads HTTP server. If you are in windows, `threads` should not be used. You can use `-d:usestd` to switch to `asynchttpserver` in Linux or MacOS.
## Threads

(2). If you want to benchmark `prologue` or release you programs, make sure set `settings.debug` = false.
`Prologue` supports two HTTP server: `httpbeast` and `asynchttpserver`. If you are in Linux or MacOS, use `--threads:on` to enable the multi-threads HTTP server. If you are in windows, `threads` should not be used. You can use `-d:usestd` to switch to `asynchttpserver` in Linux or MacOS.

## Benchmarking and debug

If you want to benchmark `prologue` or release you programs, make sure set `settings.debug` = false.

```nim
let
Expand All @@ -27,7 +31,9 @@ staticDir=/static
secretKey=Pr435ol67ogue
```

(3). There are two ways to disable logging messages:
## Disable logging

There are two ways to disable logging messages:

- set `settings.debug` = false
- set a startup event
Expand All @@ -44,7 +50,7 @@ var
app = newApp(settings = settings, startup = @[event])
```

(4). Avoid using a function name which is same to the module name.
## Avoid using a function name which is same to the module name.

`src/index.nim`

Expand All @@ -53,5 +59,25 @@ proc index(ctx: Context) {.async.} =
...
```

(5). Use the full path of JS, CSS files. For instance in your HTML file use `templates/some.js` instead of
`some.js`.
## Use the full path of JS, CSS files.

For instance in your HTML file use `templates/some.js` instead of `some.js`.

## Run in async mode

The server can run in async mode, this is useful to perform other tasks beside
accepting connections.

```nim
import prologue

proc handler(ctx: Context) {.async.} =
resp "Hello world"

let settings = newSettings(port = Port(8000))
let app = newApp(settings)
app.all("/*$", handler)
waitFor app.runAsync()

```