summaryrefslogtreecommitdiffstats
path: root/tests/auto/qtipc/lackey/scripts/consumer.js
blob: 4d12dcac1af38c80d93bc2f1bae95557b3309535 (plain)
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
41
function QVERIFY(x, debugInfo) {
    if (!(x)) {
        print(debugInfo);
        throw(debugInfo);
    }
}

var consumer = new ScriptSharedMemory;
consumer.setKey("market");

//print("consumer starting");
var tries = 0;;
while(!consumer.attach()) {
    if (tries == 5000) {
        var message = "consumer exiting, waiting too long";
        print(message);
        throw(message);
    }
    ++tries;
    consumer.sleep(1);
}
//print("consumer attached");


var i = 0;
while(true) {
    QVERIFY(consumer.lock(), "lock");
    if (consumer.get(0) == 'Q') {
        consumer.set(0, ++i);
        //print ("consumer sets" + i);
    }
    if (consumer.get(0) == 'E') {
        QVERIFY(consumer.unlock(), "unlock");
        break;
    }
    QVERIFY(consumer.unlock(), "unlock");
    consumer.sleep(10);
}

//print("consumer detaching");
QVERIFY(consumer.detach());