netbox: introduce fiber-async API
Now any netbox call blocks a caller-fiber until a result is read from a socket, or time is out. To use it asynchronously it is necessary to create a fiber per request. Sometimes it is unwanted - for example if RPS is very high (for example, about 100k), and latency is about 1 second. Or when it is neccessary to send multiple requests in parallel and then collect responses (map-reduce). The patch introduces a new option for all netbox requests: is_async. With this option any called netbox method returns immediately (but still yields for a moment) a 'future' object. By a future object a user can check if the request is finalized, get a result or error, wait for a timeout, discard a response. Example of is_async usage: future = conn:call(func, {params}, {..., is_async = true}) -- Do some work ... if not future.is_ready() then result, err = future:wait_result(timeout) end -- Or: result, error = future:result() A future:result() and :wait_result() returns either an error or a response in the same format, as the sync versions of the called methods. Part of #3107
Please register or sign in to comment