 React = require 'react'
 BS = require 'react-bootstrap'
+_ = require 'underscore'
 RefreshButton = require './refresh-button'
 
 module.exports = React.createClass
   displayName: 'AsyncButton'
+
+  getInitialState: ->
+    isTimedout: false
+
+  componentDidUpdate: ->
+    {isWaiting, timeout} = @props
+    {isTimedout} = @state
+
+    if isWaiting and not isTimedout
+      _.delay =>
+        @checkForTimeout()
+      , timeout
+
+  checkForTimeout: ->
+    {isWaiting} = @props
+    @setState(isTimedout: true) if isWaiting
 
   propTypes:
     isWaiting: React.PropTypes.bool.isRequired

      text = children

    <BS.Button {...@props}
      className={[stateClass, className]}
      disabled={disabled}
      >
        {spinner}

    failedState: React.PropTypes.func
    failedProps: React.PropTypes.object
    doneText: React.PropTypes.any
    timeout: React.PropTypes.number

  getDefaultProps: ->
    isDone: false
