Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

versions

  • Loading branch information...
commit ac661c9f865b4eddd73a8508b2d0fe7cb0c3d639 1 parent b87233f
@lancejpollard authored
View
2  lib/design.io/listener/mac.js
@@ -16,7 +16,7 @@
command.stdout.setEncoding('utf8');
command.stdout.on('data', function(data) {
var path, _i, _len, _results;
- data = JSON.parse(data);
+ data = JSON.parse("[" + data.replace(/\]\[/g, ",").replace(/[\[\]]/g, "") + "]");
_results = [];
for (_i = 0, _len = data.length; _i < _len; _i++) {
path = data[_i];
View
32 lib/design.io/watcher.js
@@ -108,29 +108,43 @@
return Watcher.change(change.path, change.options, callback);
}, 1);
+ Watcher.timeout = 10 * 1000;
+
Watcher.change = function(path, options, callback) {
- var action, iterator, timestamp, watchers;
+ var action, duration, iterator, self, timestamp, watchers;
watchers = this.all();
action = options.action;
timestamp = options.timestamp;
+ self = this;
+ duration = this.timeout;
iterator = function(watcher, next) {
+ var timeout, timeoutError, watcherCallback;
if (watcher.match(path)) {
watcher.path = path;
watcher.action = action;
watcher.timestamp = timestamp;
+ watcherCallback = function(error) {
+ clearTimeout(timeout);
+ if (error) console.log(error.stack);
+ return process.nextTick(next);
+ };
+ timeoutError = function() {
+ return watcherCallback(new Error("Watcher for " + (watcher.patterns.toString()) + " timed out. Make sure you have and call a callback in each watcher method (e.g. update: function(path, callback))"));
+ };
+ timeout = setTimeout(timeoutError, duration);
try {
switch (watcher[action].length) {
+ case 0:
case 1:
- throw Error("You must specify a callback in your watcher");
- break;
+ watcher[action].call(watcher);
+ return watcherCallback();
case 2:
- return watcher[action].call(watcher, path, next);
+ return watcher[action].call(watcher, path, watcherCallback);
case 3:
- return watcher[action].call(watcher, path, options, next);
+ return watcher[action].call(watcher, path, options, watcherCallback);
}
} catch (error) {
- console.log(error.stack);
- return next();
+ return watcherCallback(error);
}
} else {
return next();
@@ -222,7 +236,9 @@
if (this.hasOwnProperty("server")) this.server.watcher = this;
}
- Watcher.prototype.initialize = function(path, callback) {};
+ Watcher.prototype.initialize = function(path, callback) {
+ return callback();
+ };
Watcher.prototype.create = function(path, callback) {
return this.update(path, callback);
View
2  package.json
@@ -1,6 +1,6 @@
{
"name": "design.io",
- "version": "0.2.5",
+ "version": "0.2.6",
"description": "Design and Test Your App in Real-Time from TextMate",
"homepage": "http://github.com/viatropos/design.io",
"main": "lib/design.io.js",
View
2  src/design.io/listener/mac.coffee
@@ -10,7 +10,7 @@ class Mac extends (require('../listener'))
command = spawn 'ruby', ["#{__dirname}/mac.rb"]
command.stdout.setEncoding('utf8')
command.stdout.on 'data', (data) ->
- data = JSON.parse(data)
+ data = JSON.parse("[" + data.replace(/\]\[/g, ",").replace(/[\[\]]/g, "") + "]")
# console.log(data.toString().trim())
for path in data
self.changed(path[0..-2], callback)
View
31 src/design.io/watcher.coffee
@@ -88,30 +88,48 @@ class Watcher
Watcher.change(change.path, change.options, callback)
, 1)
+ @timeout: 10 * 1000
+
@change: (path, options, callback) ->
watchers = @all()
action = options.action
timestamp = options.timestamp
+ self = @
+ duration = @timeout
iterator = (watcher, next) ->
if watcher.match(path)
+
watcher.path = path
watcher.action = action
watcher.timestamp = timestamp
+
+ watcherCallback = (error) ->
+ clearTimeout(timeout)
+ console.log(error.stack) if error
+ process.nextTick(next)
+
+ timeoutError = ->
+ watcherCallback(new Error("Watcher for #{watcher.patterns.toString()} timed out. Make sure you have and call a callback in each watcher method (e.g. update: function(path, callback))"))
+
+ timeout = setTimeout(timeoutError, duration)
try
switch watcher[action].length
- when 1 then throw Error("You must specify a callback in your watcher")
- when 2 then watcher[action].call(watcher, path, next)
- when 3 then watcher[action].call(watcher, path, options, next)
+ when 0, 1
+ watcher[action].call watcher
+ watcherCallback()
+ when 2
+ watcher[action].call watcher, path, watcherCallback
+ when 3
+ watcher[action].call watcher, path, options, watcherCallback
catch error
- console.log(error.stack)
- next()
+ watcherCallback(error)
# make async
# delete watcher.path
# delete watcher.action
# delete watcher.timestamp
-
+
#break unless success
else
next()
@@ -179,6 +197,7 @@ class Watcher
@server.watcher = @ if @hasOwnProperty("server")
initialize: (path, callback) ->
+ callback()
# Example:
#
Please sign in to comment.
Something went wrong with that request. Please try again.