 exec = require 'executive'
 fs   = require 'fs'
 path = require 'path'
+
+debounce = (fn, wait = 500) ->
+  last = (new Date) - wait
+  ->
+    now = new Date
+
+    # Return if we haven't waited long enough
+    return if wait > (now - last)
+
+    fn.apply null, arguments
+    last = now
 
 writeFile = (dst, content) ->
   fs.writeFile dst, content, 'utf8', (err) ->


  compilers:
    css: -> false
    coffee: compileCoffee
    pug:    compileCoffee
    styl:   compileStylus


    writeFile dst + '.map', JSON.stringify style.sourcemap
  true

coffeeCompiler = debounce compileCoffee
stylusCompiler = debounce compileStylus

module.exports =
  port: 4242

