Browse Source

Move timeout to server settings

Steven Silvester 8 years ago
parent
commit
6a0a265be1
1 changed files with 7 additions and 10 deletions
  1. 7 10
      packages/services/src/serverconnection.ts

+ 7 - 10
packages/services/src/serverconnection.ts

@@ -107,13 +107,6 @@ namespace ServerConnection {
      */
      */
     cache?: boolean;
     cache?: boolean;
 
 
-    /**
-     * The number of milliseconds a request can take before automatically
-     * being terminated.  A value of 0 (which is the default) means there is
-     * no timeout.
-     */
-    timeout?: number;
-
     /**
     /**
      * A mapping of request headers, used via `setRequestHeader`.
      * A mapping of request headers, used via `setRequestHeader`.
      */
      */
@@ -152,6 +145,11 @@ namespace ServerConnection {
      */
      */
     readonly password: string;
     readonly password: string;
 
 
+    /**
+     * The timeout associated with requests.  Defaults to `0`.
+     */
+    readonly timeout: number;
+
     /**
     /**
      * The optional token for ajax requests. Defaults to PageConfig `token`.
      * The optional token for ajax requests. Defaults to PageConfig `token`.
      */
      */
@@ -256,6 +254,7 @@ namespace Private {
       user: options.user || '',
       user: options.user || '',
       password: options.password || '',
       password: options.password || '',
       withCredentials: !!options.withCredentials,
       withCredentials: !!options.withCredentials,
+      timeout: options.timeout || 0,
       token: options.token || PageConfig.getOption('token'),
       token: options.token || PageConfig.getOption('token'),
       requestHeaders: { ...options.requestHeaders || {} },
       requestHeaders: { ...options.requestHeaders || {} },
       xhr: options.xhr || XMLHttpRequest,
       xhr: options.xhr || XMLHttpRequest,
@@ -274,9 +273,7 @@ namespace Private {
       xhr.setRequestHeader('Content-Type', 'application/json');
       xhr.setRequestHeader('Content-Type', 'application/json');
     }
     }
 
 
-    if (request.timeout !== void 0) {
-      xhr.timeout = request.timeout;
-    }
+    xhr.timeout = settings.timeout;
     if (settings.withCredentials) {
     if (settings.withCredentials) {
       xhr.withCredentials = true;
       xhr.withCredentials = true;
     }
     }