File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 263
263
--- @param timeout ? number
264
264
--- @return any
265
265
function Promise .wait (self , timeout )
266
+ timeout = timeout or 5000
266
267
local is_done = false
267
268
local has_error = false
268
269
local result = nil
@@ -278,7 +279,7 @@ function Promise.wait(self, timeout)
278
279
is_done = true
279
280
end )
280
281
281
- vim .wait (timeout or 5000 , function ()
282
+ local success , code = vim .wait (timeout , function ()
282
283
return is_done
283
284
end , 1 )
284
285
@@ -288,7 +289,17 @@ function Promise.wait(self, timeout)
288
289
return error (value )
289
290
end
290
291
291
- return value
292
+ if success then
293
+ return value
294
+ end
295
+
296
+ if code == - 1 then
297
+ return error (' promise timeout of ' .. tostring (timeout ) .. ' ms reached' )
298
+ elseif code == - 2 then
299
+ return error (' promise interrupted' )
300
+ end
301
+
302
+ return error (' promise failed with unknown reason' )
292
303
end
293
304
294
305
--- Equivalents to JavaScript's Promise.all.
Original file line number Diff line number Diff line change
1
+ local Promise = require (' orgmode.utils.promise' )
2
+
3
+ describe (' Promise' , function ()
4
+ it (' should throw an error when wait exceeds its timeout' , function ()
5
+ -- Create a promise that will never resolve or reject
6
+ local promise = Promise .new (function () end )
7
+
8
+ -- We expect an error to occur here when the timeout is exceeded
9
+ assert .is .error (function ()
10
+ -- Provide a smaller timeout so our test doesn't wait 5 seconds
11
+ promise :wait (50 )
12
+ end )
13
+ end )
14
+ end )
You can’t perform that action at this time.
0 commit comments