Q:

return when asynchronous task has completed

I'd need a function to wait until the asynchronous task has completed and then return.
In my example, I'm getting undefined returned from the "execute" method:
var result = myClass.execute(obj);  //undefined

How can I get the actual result returned?
return declare(null, {
        constructor: function (obj) {
            this.mapServiceUrl = obj.mapServiceUrl;
            this.geometry_json = obj.geometry_json || undefined;
            this.where = obj.where || "1=1";
        },

        execute: function () {
            var queryTask = new QueryTask(this.mapServiceUrl),
                query = new Query()
            ;

            query.returnGeometry = true;
            query.outFields = ["RDUWI"];

            if (this.geometry_json) {
                query.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;
                query.geometry = Polygon(this.geometry_json);
            };

            query.where = this.where;
            var deferred = queryTask.execute(query);
            deferred.then(function (featureSet) {
                return featureSet;
            });
        }
    });

A:

What you want is the c# await keyword, which does not exist in javascript:

The await operator is applied to a task in an asynchronous method to
  suspend the execution of the method until the awaited task completes.
  The task represents ongoing work. The asynchronous method in which
  await is used must be modified by the async keyword. Such a method,
  defined by using the async modifier, and usually containing one or
  more await expressions, is referred to as an async method.

The closest you can get to making this type of code transparent is to use when.  Docs state:

dojo/when is designed to make it easier to merge coding of synchronous
  and asynchronous threads. Accepts promises but also transparently
  handles non-promises. If no callbacks are provided returns a promise,
  regardless of the initial value. Also, foreign promises are converted.
If callbacks are provided and the initial value is not a promise, the
  callback is executed immediately with no error handling. Returns a
  promise if the initial value is a promise, or the result of the
  callback otherwise.

