-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample11.js
More file actions
55 lines (41 loc) · 1.19 KB
/
Copy pathexample11.js
File metadata and controls
55 lines (41 loc) · 1.19 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
console.log(`
POT JS Example 11: error handling
Check source and terminal.
`)
require("./lib/pot-node")(1)
; (async () => {
await pot.ready()
kvs = new pot.Kvs()
// .catch
console.log(" ► chained .catch()")
pot.setFail(true)
await kvs.put("hello", "node")
.catch(e=>console.log(" ⟶ caught in chained .catch: " + e))
// cancel()
console.log(" ► cancel")
pot.setHang(true)
put = kvs.put("hello", "node") // cancel() works only when .catch() is not chained to put() itself
put.catch(e=>console.log(" ⟶ caught in cancel .catch: " + e))
put.cancel()
// timout
console.log(" ► timeout")
pot.setHang(true)
timeout = 10 // ms
put = kvs.put("hello", "node", timeout)
put.catch(e=>console.log(" ⟶ caught in timeout .catch: " + e))
// try-catch
console.log(" ► try-catch block")
pot.setFail(true)
try {
await kvs.put("hello", "node")
} catch(e) {
console.log(" ⟶ caught in try-catch block: " + e)
}
// sync call
console.log(" ► sync call")
pot.setFail(true)
e = kvs.putSync("hello", "node") // sync calls don't throw but return errors
if(e) {
console.log(" ⟶ returned from sync call: " + e)
}
})()