How do I handle retry logic for unreliable external resources?

Using multiple parameters and multiple returns


The retry.call() function handles multiple arguments and multiple returns.

Multiple Arguments [top]

The retry.call() function supports multiple arguments, in the form: arg1, arg2,… argN.

Note: Arguments with other names will raise an error:

Screen Shot 2014-04-03 at 14.45.51

Multiple Returns [top]

Lua functions can return multiple values from a function, retry.call() supports this language feature:

Screen Shot 2014-03-04 at 16.34.29

Note: When an error occurs there will be only two returns, the first is the error message and the second (last) is the informational message:

Screen Shot 2014-03-04 at 17.24.59

Tip: The code that achieves the multiple returns is a bit subtle.

The returns from pcall() are assigned to a table “R”:

Screen Shot 2014-04-03 at 15.05.09

Which is is then unpacked when it is returned from retry.call()

Screen Shot 2014-03-04 at 16.47.24

Note: unpack() is a standard Lua function that returns the elements from a table.

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.