13
13
14
14
``` lua
15
15
self .client .request (' workspace/executeCommand' , cmd_info , function (err , res )
16
- if err then
17
- log .error (command .. ' failed! arguments: ' , arguments , ' error: ' , err )
18
- else
19
- log .debug (command .. ' success! response: ' , res )
20
- end
16
+ if err then
17
+ log .error (command .. ' failed! arguments: ' , arguments , ' error: ' , err )
18
+ else
19
+ log .debug (command .. ' success! response: ' , res )
20
+ end
21
21
end , buffer )
22
22
```
23
23
@@ -33,14 +33,14 @@ Assume following is the asynchronous API
33
33
34
34
``` lua
35
35
local function lsp_request (callback )
36
- local timer = vim .loop .new_timer ()
36
+ local timer = vim .loop .new_timer ()
37
37
38
- assert (timer )
38
+ assert (timer )
39
39
40
- timer :start (2000 , 0 , function ()
41
- -- First parameter is the error
42
- callback (' something went wrong' , nil )
43
- end )
40
+ timer :start (2000 , 0 , function ()
41
+ -- First parameter is the error
42
+ callback (' something went wrong' , nil )
43
+ end )
44
44
end
45
45
```
46
46
@@ -52,7 +52,7 @@ This is how you can call this asynchronous API without a callback
52
52
local M = require (' sync' )
53
53
54
54
M .sync (function ()
55
- local response = M .wait_handle_error (M .wrap (lsp_request )())
55
+ local response = M .wait_handle_error (M .wrap (lsp_request )())
56
56
end ).run ()
57
57
```
58
58
@@ -62,9 +62,9 @@ Result:
62
62
Error executing luv callback:
63
63
test6.lua:43: unhandled error test6.lua:105: something went wrong
64
64
stack traceback:
65
- [C]: in function 'error'
66
- test6.lua:43: in function 'callback'
67
- test6.lua:130: in function <test6.lua:129>
65
+ [C]: in function 'error'
66
+ test6.lua:43: in function 'callback'
67
+ test6.lua:130: in function <test6.lua:129>
68
68
```
69
69
70
70
### When error handler is defined
@@ -73,12 +73,12 @@ stack traceback:
73
73
local M = require (' sync' )
74
74
75
75
local main = M .sync (function ()
76
- local response = M .wait_handle_error (M .wrap (lsp_request )())
76
+ local response = M .wait_handle_error (M .wrap (lsp_request )())
77
77
end )
78
- .catch (function (err )
79
- print (' error occurred ' , err )
80
- end )
81
- .run ()
78
+ .catch (function (err )
79
+ print (' error occurred ' , err )
80
+ end )
81
+ .run ()
82
82
```
83
83
84
84
Result:
@@ -93,16 +93,16 @@ error occured test6.lua:105: something went wrong
93
93
local M = require (' sync' )
94
94
95
95
local nested = M .sync (function ()
96
- local response = M .wait_handle_error (M .wrap (lsp_request )())
96
+ local response = M .wait_handle_error (M .wrap (lsp_request )())
97
97
end )
98
98
99
99
M .sync (function ()
100
- M .wait_handle_error (nested .run )
100
+ M .wait_handle_error (nested .run )
101
101
end )
102
- .catch (function (err )
103
- print (' parent error handler ' .. err )
104
- end )
105
- .run ()
102
+ .catch (function (err )
103
+ print (' parent error handler ' .. err )
104
+ end )
105
+ .run ()
106
106
```
107
107
108
108
Result:
0 commit comments