code: function executeApiCall(callback, needConnection) {
          needConnection = typeof needConnection !== 'undefined' ? needConnection : true;
          authenticate(function (error, result) {
              if (error || !result) {
                  callback(error, result);
                  return;
              }
              if (needConnection) {
                  isConnected(function (error, result) {
                      if (error || !result) {
                          console.error("[Deluge] WebUI not connected to a daemon");
                          return;
                      }
                      callback(error, result);
                  });
              } else {
                  callback(error, result);
              }
          });
      }
docs: Connect if not connected then execute the callback method
  @param callback