A common activity is to perform some tasks, wait for the results and do some more work with those results.
Lets say you want to calculate the price of an item that is in US Dollars (USD) and
output it in Australian Dollars (AUD). We have
anItem that will return an
Observable that fetches the item price, and an
exchangeRate function that will fetch the current exchange rate for two currencies.
Using reactive operators, you could use the
zip function to achieve this:
Observable.zip( anItem:priceInUSD(), exchangeRate("USD", "AUD") ) :subscribe(function(price, rate) print "AUD Price: ", price * rate end)
The final subscription will only be executed once both the
a value. It will continue calling it while both keep producing values, but will complete if any of them
Using the Given statement it would look like this:
Given( anItem:priceInUSD(), exchangeRate("USD", "AUD"), ) :Now(function(price, rate) print "AUD Price: ", price * rate end)
For more information on using and creating statements, see the Statements documentation.