Wednesday, October 17, 2012

Coffee script `file removed` while using compile/watch switches with vim

I thought it was just my main Arch system, but I've recently been forced to use my clunky old laptop to develop and have found that there is a race condition in coffee-script when saving with vim on there too.

I fixed the problem with this simple patch (a hacky 100ms setTimeout to add a short pause), I was hoping the CPU on my laptop was slow enough that the logic would line up without the patch.  This was not the case.

Here's what I did since that patch link is now broken:

in command.coffee I have this:

# Watch a source CoffeeScript file using `fs.watch`, recompiling it every
# time the file is updated. May be used in combination with other options,
# such as `--lint` or `--print`.
watch = (source, base) ->

  prevStats = null
  compileTimeout = null

  watchErr = (e) ->
    if e.code is 'ENOENT'
      return if sources.indexOf(source) is -1
      try
        vimTimeout = wait 100, ->
          rewatch()
          compile()
      catch e
        removeSource source, base, yes
        compileJoin()

    else throw e



ALSO: This blog entry seems to have a good suggestion, I may try it myself!

When I brought the issue up in the coffee-script IRC channel a few months ago, there were some very defensive people (person?) saying the problem wasn't with coffee-script and the -cw switch works fine with vim.

This has not been the case for me.

I hope this helps some people, because I don't think I'm the only one who's experiencing this, or will experience this.

Please let me know if this issue gets patched, I submitted a pull request, but I deleted it due to lack of response and the embarrassingly nasty little hack (although similar hacks are used throughout the compiler to deal with race conditions!).

Anyway, much love to coffee-script for now, good luck fellow hackers.

No comments:

Post a Comment