DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
  • Ecosystem
    • can-construct-super
    • can-define-stream
    • can-fixture
    • can-fixture-socket
    • can-jquery
    • can-stache-converters
    • can-stream
    • can-vdom
    • can-view-import
    • can-zone
      • types
        • ZoneSpec
        • makeZoneSpec
      • static
        • current
        • error
        • ignore
        • waitFor
      • prototype
        • addWait
        • data
        • removeWait
        • run
      • plugins
        • ./debug
        • ./timeout
          • TimeoutError
      • modules
        • ./register
    • steal-stache
  • Infrastructure
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Ecosystem
  • /
  • can-zone
  • /
  • ./timeout
  • / On this page
    • can-zone/timeout

      module
      • source

      timeout(ms)

      Creates a ZoneSpec that you can use as a plugin for your Zone in order to timeout after a certain length of time (as ms).

      If the Zone times out it's run promise will be rejected with a <a href="timeout.TimeoutError.html" title="A special type of Error that also includes the number of milliseconds that were waited before timing out. The error object is included with the timeout module: var timeout = require("can-zone/timeout");

      var TimeoutError = timeout.TimeoutError; // Maybe use this to check instanceof.">TimeoutError, a special error that also includes the number of milliseconds waited before timing out.

      var Zone = require("can-zone");
      var timeout = require("can-zone/timeout");
      
      var zone = new Zone({
          plugins: [ timeout(5000) ]
      });
      
      zone.run(function(){
          setTimeout(function(){
      
          }, 10000); // waiting over 5 sec
      })
      .catch(function(err){
          // Called because we exceeded the timeout.
      });
      

      Parameters

      1. ms {Number}:

        The number of milliseconds to wait before timing out the Zone.

      Returns

      {ZoneSpec}:

      A ZoneSpec that can be passed as a plugin.

      Use

      The timeout zone allows you to specify a timeout for your Zone. If the Zone promise doesn't resolve before timing out, the Zone promise will be rejected by the plugin.

      The timeout zone is a function that takes a timeout in milliseconds.

      The Promise will reject with a special type of Error, a TimeoutError.

      var Zone = require("can-zone");
      var timeout = require("can-zone/timeout");
      var TimeoutError = timeout.TimeoutError;
      
      var zone = new Zone({
          plugins: [
              timeout(2000)
          ]
      });
      
      zone.run(function(){
      
          setTimeout(function(){
      
          }, 5000);
      
      }).then(null, function(err){
      
          // err.timeout -> 2000
      
      });
      

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.