-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyncLib.js
More file actions
40 lines (31 loc) · 949 Bytes
/
syncLib.js
File metadata and controls
40 lines (31 loc) · 949 Bytes
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
31
32
33
34
35
36
37
38
39
40
// simulation library
function fnSyncLib(params, onSuccess, onError) {
function fnTry(fn) {
try {
return fn();
} catch (ex) {
console.log(ex.message + "\r\n\r\n" + ex.stack);
fnOnError(ex);
}
}
function fnOnError(error) {
console.log("fnSyncLib error: " + error.message);
onError(error);
}
function fnSimulateRemoteCall() {
var startdate = new Date().getTime();
//hang on for a while
sleepFor(5000);
var endDate = new Date().getTime();
console.log(startdate);
console.log(endDate);
var response = "It took me 5 seconds";
onSuccess(response);
}
function sleepFor(sleepDuration) {
var now = new Date().getTime();
while (new Date().getTime() < now + sleepDuration) { /* do nothing */ }
}
// initialize function here
fnTry(fnSimulateRemoteCall);
}