Last active
December 24, 2018 10:53
-
-
Save pbabics/1020698fd1c9e52858b5b737956d5af5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef int (*CALLABLE) (void); | |
CALLABLE async_functions[] = { | |
xyz, | |
yzx, | |
zxy, | |
}; | |
int async_delays[] = {0, 0, 0}; | |
void loop() { | |
int min_time = 1 << 31, | |
min_index = -1; | |
for (int i = 0; i < sizeof(async_functions) / sizeof(*async_functions); ++i) { | |
if (min_time > async_delays[i]) { | |
min_time = async_delays[i]; | |
min_index = i; | |
} | |
if (min_time == 0) | |
break; | |
} | |
delay(min_time); | |
if (min_time > 0) | |
for (int i = 0; i < sizeof(async_functions) / sizeof(*async_functions); ++i) | |
async_delays[i] = max(0, async_delays[i] - min_time); | |
async_delays[min_index] = async_functions[min_index](); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment