File: simple.js

package info (click to toggle)
0ad 0.28.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 182,352 kB
  • sloc: cpp: 201,989; javascript: 19,730; ansic: 15,057; python: 6,597; sh: 2,046; perl: 1,232; xml: 543; java: 533; makefile: 105
file content (30 lines) | stat: -rw-r--r-- 460 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
let test = 0;

function incrementTest()
{
	test += 1;
}

async function waitAndIncrement(promise)
{
	await promise;
	incrementTest();
}

{
	let resolve;
	const promise = new Promise(res => {
		incrementTest();
		resolve = res;
	});
	waitAndIncrement(promise);
	TS_ASSERT_EQUALS(test, 1);
	resolve();
	// At this point, waitAndIncrement is still not run, but is now free to run.
	TS_ASSERT_EQUALS(test, 1);
}

function endTest()
{
	TS_ASSERT_EQUALS(test, 2);
}