Skip to content

Commit

Permalink
Adjust the hierarchy of chapter Deferred Execution (#18075)
Browse files Browse the repository at this point in the history
  • Loading branch information
coliss86 authored Aug 16, 2022
1 parent c834608 commit 837a57b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions docs/custom_quantum_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,11 @@ And you're done. The RGB layer indication will only work if you want it to. And

The `val` is the value of the data that you want to write to EEPROM. And the `eeconfig_read_*` function return a 32 bit (DWORD) value from the EEPROM.

### Deferred Execution :id=deferred-execution
# Deferred Execution :id=deferred-execution

QMK has the ability to execute a callback after a specified period of time, rather than having to manually manage timers. To enable this functionality, set `DEFERRED_EXEC_ENABLE = yes` in rules.mk.

#### Deferred executor callbacks
## Deferred executor callbacks

All _deferred executor callbacks_ have a common function signature and look like:

Expand All @@ -430,7 +430,7 @@ The return value is the number of milliseconds to use if the function should be
?> Note that the returned delay will be applied to the intended trigger time, not the time of callback invocation. This allows for generally consistent timing even in the face of occasional late execution.
#### Deferred executor registration
## Deferred executor registration
Once a callback has been defined, it can be scheduled using the following API:
Expand All @@ -444,15 +444,15 @@ The third parameter is the `cb_arg` that gets passed to the callback at the poin

The return value is a `deferred_token` that can consequently be used to cancel the deferred executor callback before it's invoked. If a failure occurs, the returned value will be `INVALID_DEFERRED_TOKEN`. Usually this will be as a result of supplying `0` to the delay, or a `NULL` for the callback. The other failure case is if there are too many deferred executions "in flight" -- this can be increased by changing the limit, described below.

#### Extending a deferred execution
## Extending a deferred execution

The `deferred_token` returned by `defer_exec()` can be used to extend a the duration a pending execution waits before it gets invoked:
```c
// This will re-delay my_token's future execution such that it is invoked 800ms after the current time
extend_deferred_exec(my_token, 800);
```
#### Cancelling a deferred execution
## Cancelling a deferred execution
The `deferred_token` returned by `defer_exec()` can be used to cancel a pending execution before it gets invoked:
```c
Expand All @@ -462,7 +462,7 @@ cancel_deferred_exec(my_token);

Once a token has been canceled, it should be considered invalid. Reusing the same token is not supported.

#### Deferred callback limits
## Deferred callback limits

There are a maximum number of deferred callbacks that can be scheduled, controlled by the value of the define `MAX_DEFERRED_EXECUTORS`.

Expand Down

0 comments on commit 837a57b

Please sign in to comment.