Chain promises sequentially
masterPromises can be chained to perform asynchronous actions one after another. If a callback in a .next() call returns a new promise, the subsequent .next() in the chain will wait for that returned promise to resolve or reject.
This avoids the 'callback hell' of nested functions.
read('first.txt'):next(function(s)
print('File file:', s)
return read('second.txt')
end):next(function(s)
print('Second file:', s)
end):next(nil, function(err)
-- error while reading first or second file
print('Error', err)
end)