Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/test/browser/test_async_mainloop.c
4150 views
1
// Copyright 2015 The Emscripten Authors. All rights reserved.
2
// Emscripten is available under two separate licenses, the MIT license and the
3
// University of Illinois/NCSA Open Source License. Both these licenses can be
4
// found in the LICENSE file.
5
6
#include <stdio.h>
7
#include <emscripten.h>
8
#include <assert.h>
9
10
void finish(int result) {
11
assert(result == 121);
12
emscripten_force_exit(0);
13
}
14
15
int counter = 0;
16
int nesting = 0;
17
18
void iter() {
19
printf("frame: %d\n", ++counter);
20
21
// ensure we don't 'recurse' with the main loop sending us back in before the
22
// synchronous operation callback finishes the rest of this trace
23
assert(nesting == 0);
24
nesting++;
25
emscripten_sleep(500);
26
assert(nesting == 1);
27
nesting = 0;
28
29
if (counter == 10) {
30
finish(121); // if we got here without hitting any assertions, all is well
31
emscripten_cancel_main_loop();
32
}
33
}
34
35
int main() {
36
emscripten_set_main_loop(iter, 0, 0);
37
}
38
39