plsql promises - promise complete solution

Finally. I got the 2 last methods completed. promise.all and promise.race is finished. So now the plsql promises library is feature complete. promise.all method takes a list of promises, built with the help of the promises_ninja package, and once the entire list of promises is fulfilled the top promise is set to fulfilled. Here is an example:

-- Test all method
declare
test_promise promise := promise();
a_promise1 promise;
a_promise2 promise;
a_promise3 promise;
all_promises promises_ninja.promise_list_type;
begin
  a_promise1 := promise('p_multiplier', 10);
  promises_ninja.build_promise_list(all_promises, a_promise1);
  a_promise2 := promise('p_multiplier', 20);
  promises_ninja.build_promise_list(all_promises, a_promise2);
  a_promise3 := promise('p_multiplier', 30);
  promises_ninja.build_promise_list(all_promises, a_promise3);
  test_promise.all_p(promises_ninja.convert_promise_list(all_promises));
  dbms_lock.sleep(5);
  test_promise.check_and_set_value();
  dbms_output.put_line('State is: ' || test_promise.state);
end;
/

The output is the list of the promises with the fulfilled values. So you can loop through the output and display individual values like this:

declare
test_promise promise := promise();
a_promise1 promise;
a_promise2 promise;
a_promise3 promise;
all_promises promises_ninja.promise_list_type;
promise_list_o promises_list_obj;
promise_val promise;
begin
  a_promise1 := promise('p_multiplier', 10);
  promises_ninja.build_promise_list(all_promises, a_promise1);
  a_promise2 := promise('p_multiplier', 20);
  promises_ninja.build_promise_list(all_promises, a_promise2);
  a_promise3 := promise('p_multiplier', 30);
  promises_ninja.build_promise_list(all_promises, a_promise3);
  test_promise.all_p(promises_ninja.convert_promise_list(all_promises));
  dbms_lock.sleep(5);
  test_promise.check_and_set_value();
  dbms_output.put_line('State is: ' || test_promise.state);
  if test_promise.val.getObject(promise_list_o) = dbms_types.success then
    -- We converted the object successfully
    for i in 1..promise_list_o.promise_list.count loop
      if promise_list_o.promise_list(i).getObject(promise_val) = dbms_types.success then
        -- We have an individual promise output value
        dbms_output.put_line('Value of promise is: ' || promise_val.getanyvalue);
      end if;
    end loop;
  end if;
end;
/

Same code and technique can be used for the race method. The only difference is that the output in the race call is a normal promise and not a list of promises, as only the first promise to complete is returned.