So last blog entry Do or do not. on the promises library, covered the basics of what promises can give us.
This entry will cover more around chaining of promises and how you can easily run your code in parallel
and still make sure they run in the right order, when needed.
Promises by definition has a method called [then]. What this method does, is that it will take the value of
the promise once it is fulfilled, and use that as input to a new function defined by us. The input to then is,
either a function to run when fulfilled or a function to run if rejected or both. Although not in the standard
there are more and more libraries implementing a method called [done]. It has the same input options as the [then]
method but it does not return a new promise. So only use this method when you do not care about the result
of the chain call. Since we are in Oracle I cannot name the method [then] since it is a reserved word,
so I had to add an _f to the name, so it becomes [then_f].
So here is the first example. We create a promise based on the function p_multiplier, that takes a number and multiplies
it by 2. We then say that if this promise is fulfilled we want to execute the function called p_multi_convert. This function
takes the previous promise result, and will return a text that will tell us if the output is less or more than 50.
declare test_promise promise; begin test_promise := promise('p_multiplier', 42); test_promise := test_promise.then_f('p_multi_convert'); promises_ninja.promise_wait(test_promise); dbms_output.put_line('Value of test_promise2 is: ' || test_promise.getanyvalue); end; /