rzimmerman / kal

A powerful, easy-to-use, and easy-to-read programming language for the future.
http://rzimmerman.github.io/kal
MIT License
394 stars 18 forks source link

errors with try catch callbacks #69

Closed rzimmerman closed 11 years ago

rzimmerman commented 11 years ago

This code tries to call k$cb0 after the try/catch block:

app.get '/:file_name', (req, res) ->
  # this route always returns plain text
  res.setHeader 'Content-Type', 'text/plain'
  # get the file name from the request
  file_name = req.params.file_name
  # try to read the file, use the catch clause if it doesn't exist
  try
    # check if it's a text file
    if file_name.match /.*\.txt/
      # for a text file, asynchronously read the contents
      wait for return_text from fs.readFile file_name
    else
      # for a non-text file, asynchronously read the file size
      wait for file_stats from fs.stat file_name
      return_text = 'File of size '+ file_stats.size
    res.send return_text
  catch
    # if any function above calls back with an error, return a 404
    res.send 404, 'File not found'