futureAssigned()

The futureAssigned() function is provided to check whether a Future Type variable is assigned or not (i.e. has a nil or 'null value).

Future types are available in Oxygene only, but futureAssigned() can in practice be called from C# and Swift, as well.

Syntax:

method futureAssigned(expression): Boolean;
bool futureAssigned(expression);
func futureAssigned(_ expression) -> Bool
bool futureAssigned(expression);

In contrast to the regular assigned() function, futureAssigned() will not evaluate the future, or wait for it to be evaluated, but simply check if any future is referenced – if so, that future value might still turn out to be nil.

In essence:

  • futureAssigned() checks for the existence of a future.
  • assigned() checks the actual future value of the variable.

For example:

property value: future String read nil; // declared somewhere

...
var x: future String := async nil;
var y: future String := async "Slow to Calculate";
var z: future String {:= nil};

if assigned(x) then
  // waits for the future to calculate, if necessary, and the checks if its nil or has a value.
  // which will be nil, so this block will not run
  ...
if assigned(y) then
  // waits for the future to calculate, if necessary, and the checks if its nil or has a value
  // which will be "Slow to Calculate", so this block will run
  ...
if assigned(z) then
  // has no future to wait for, so it will be false
  // this block will not run
  ...

if futureAssigned(x) then // check if x contains any future at all. it does.
  // this runs
  ...
if futureAssigned(y) then // check if y contains any future at all. it does.
  // this runs
  ...
if futureAssigned(z) then // check if y contains any future at all. it does not.
  // this will not run
  ...

to do: translate to all 4 languages

See Also