mirror of
https://github.com/logos-storage/nim-libplum.git
synced 2026-06-07 09:40:01 +00:00
Add documentation about onStateChange usage
This commit is contained in:
parent
f66c6114f9
commit
c9a976fe6e
9
api.md
9
api.md
@ -98,13 +98,20 @@ Returns a `MappingResult` containing the mapping `id` (needed for `destroyMappin
|
||||
|
||||
Returns an error if no NAT device is found, the mapping fails, or the timeout expires.
|
||||
|
||||
> **Warning:** `onStateChange` runs on libplum's internal C thread, not the
|
||||
> chronos event loop. Do not call chronos APIs or touch non-thread-safe state
|
||||
> from it; restrict it to thread-safe operations (e.g. `Atomic`, a channel).
|
||||
|
||||
### destroyMapping
|
||||
|
||||
```nim
|
||||
proc destroyMapping*(id: cint)
|
||||
```
|
||||
|
||||
Removes a mapping. Must be called exactly once after a successful `createMapping`.
|
||||
Removes a mapping. Must be called exactly once after a successful `createMapping`,
|
||||
otherwise the mapping's internal handle is leaked for the lifetime of the process.
|
||||
Calling it again, or with an unknown `id`, is a safe no-op. `cleanup` also releases
|
||||
any mappings still active.
|
||||
|
||||
### hasMapping
|
||||
|
||||
|
||||
@ -59,6 +59,9 @@ type
|
||||
mapping*: PlumMapping
|
||||
|
||||
PlumStateCallback* = proc(state: PlumState, mapping: PlumMapping) {.callback.}
|
||||
## Invoked on mapping state changes after the initial result. Runs on
|
||||
## libplum's internal C thread, not the chronos loop: only touch
|
||||
## thread-safe state from it (e.g. Atomic), never chronos APIs.
|
||||
|
||||
MappingHandle = ref object
|
||||
signal: ThreadSignalPtr
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user