// Compiled by ClojureScript 0.0-2138
goog.provide('lt.objs.thread');
goog.require('cljs.core');
goog.require('lt.objs.files');
goog.require('lt.objs.platform');
goog.require('cljs.reader');
goog.require('lt.objs.platform');
goog.require('lt.objs.files');
goog.require('lt.object');
goog.require('cljs.reader');
goog.require('lt.object');
goog.require('lt.objs.console');
goog.require('lt.objs.console');
lt.objs.thread.cp = require("child_process");
lt.objs.thread.__BEH__try_send = (function __BEH__try_send(this$,msg){if(cljs.core.not.call(null,new cljs.core.Keyword(null,"connected","connected",4729661051).cljs$core$IFn$_invoke$arity$1(cljs.core.deref.call(null,this$))))
{return lt.object.raise.call(null,this$,new cljs.core.Keyword(null,"queue!","queue!",4360174754),msg);
} else
{return lt.object.raise.call(null,this$,new cljs.core.Keyword(null,"send!","send!",1123226891),msg);
}
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.thread","try-send","lt.objs.thread/try-send",1561926143),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.thread.__BEH__try_send,new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"try-send!","try-send!",4325864057),null], null), null));
lt.objs.thread.__BEH__queue_BANG_ = (function __BEH__queue_BANG_(this$,msg){return lt.object.update_BANG_.call(null,this$,new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"queue","queue",1121848451)], null),cljs.core.conj,msg);
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.thread","queue!","lt.objs.thread/queue!",1667114793),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.thread.__BEH__queue_BANG_,new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"queue!","queue!",4360174754),null], null), null));
lt.objs.thread.__BEH__send_BANG_ = (function __BEH__send_BANG_(this$,msg){return new cljs.core.Keyword(null,"worker","worker",4526786288).cljs$core$IFn$_invoke$arity$1(cljs.core.deref.call(null,this$)).send(cljs.core.clj__GT_js.call(null,msg));
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.thread","send!","lt.objs.thread/send!",2752302802),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.thread.__BEH__send_BANG_,new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"send!","send!",1123226891),null], null), null));
lt.objs.thread.__BEH__connect = (function __BEH__connect(this$){var seq__14415_14419 = cljs.core.seq.call(null,new cljs.core.Keyword(null,"queue","queue",1121848451).cljs$core$IFn$_invoke$arity$1(cljs.core.deref.call(null,this$)));var chunk__14416_14420 = null;var count__14417_14421 = 0;var i__14418_14422 = 0;while(true){
if((i__14418_14422 < count__14417_14421))
{var q_14423 = cljs.core._nth.call(null,chunk__14416_14420,i__14418_14422);lt.object.raise.call(null,this$,new cljs.core.Keyword(null,"send!","send!",1123226891),q_14423);
{
var G__14424 = seq__14415_14419;
var G__14425 = chunk__14416_14420;
var G__14426 = count__14417_14421;
var G__14427 = (i__14418_14422 + 1);
seq__14415_14419 = G__14424;
chunk__14416_14420 = G__14425;
count__14417_14421 = G__14426;
i__14418_14422 = G__14427;
continue;
}
} else
{var temp__4092__auto___14428 = cljs.core.seq.call(null,seq__14415_14419);if(temp__4092__auto___14428)
{var seq__14415_14429__$1 = temp__4092__auto___14428;if(cljs.core.chunked_seq_QMARK_.call(null,seq__14415_14429__$1))
{var c__4262__auto___14430 = cljs.core.chunk_first.call(null,seq__14415_14429__$1);{
var G__14431 = cljs.core.chunk_rest.call(null,seq__14415_14429__$1);
var G__14432 = c__4262__auto___14430;
var G__14433 = cljs.core.count.call(null,c__4262__auto___14430);
var G__14434 = 0;
seq__14415_14419 = G__14431;
chunk__14416_14420 = G__14432;
count__14417_14421 = G__14433;
i__14418_14422 = G__14434;
continue;
}
} else
{var q_14435 = cljs.core.first.call(null,seq__14415_14429__$1);lt.object.raise.call(null,this$,new cljs.core.Keyword(null,"send!","send!",1123226891),q_14435);
{
var G__14436 = cljs.core.next.call(null,seq__14415_14429__$1);
var G__14437 = null;
var G__14438 = 0;
var G__14439 = 0;
seq__14415_14419 = G__14436;
chunk__14416_14420 = G__14437;
count__14417_14421 = G__14438;
i__14418_14422 = G__14439;
continue;
}
}
} else
{}
}
break;
}
return lt.object.merge_BANG_.call(null,this$,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"connected","connected",4729661051),true,new cljs.core.Keyword(null,"queue","queue",1121848451),cljs.core.PersistentVector.EMPTY], null));
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.thread","connect","lt.objs.thread/connect",4665947759),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.thread.__BEH__connect,new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"connect","connect",1965255772),null], null), null));
lt.objs.thread.__BEH__message = (function __BEH__message(this$,m){var temp__4092__auto__ = lt.object.by_id.call(null,m.obj);if(cljs.core.truth_(temp__4092__auto__))
{var obj = temp__4092__auto__;return lt.object.raise.call(null,obj,((!((m.msg instanceof cljs.core.Keyword)))?cljs.core.keyword.call(null,m.msg):m.msg),((cljs.core._EQ_.call(null,"clj",m.format))?cljs.reader.read_string.call(null,m.res):m.res));
} else
{return null;
}
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.thread","message","lt.objs.thread/message",4662440292),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.thread.__BEH__message,new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"message","message",1968829305),null], null), null));
lt.objs.thread.__BEH__kill_BANG_ = (function __BEH__kill_BANG_(this$){return new cljs.core.Keyword(null,"worker","worker",4526786288).cljs$core$IFn$_invoke$arity$1(cljs.core.deref.call(null,this$)).kill();
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.thread","kill!","lt.objs.thread/kill!",2826681832),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.thread.__BEH__kill_BANG_,new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"kill!","kill!",1115956213),null], null), null));
lt.objs.thread.__BEH__shutdown_worker_on_close = (function __BEH__shutdown_worker_on_close(app){return lt.object.raise.call(null,lt.objs.thread.worker,new cljs.core.Keyword(null,"kill!","kill!",1115956213));
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.thread","shutdown-worker-on-close","lt.objs.thread/shutdown-worker-on-close",2634641895),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.thread.__BEH__shutdown_worker_on_close,new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"closed","closed",3951351006),null], null), null));
lt.object.object_STAR_.call(null,new cljs.core.Keyword("lt.objs.thread","worker-thread","lt.objs.thread/worker-thread",1400507698),new cljs.core.Keyword(null,"tags","tags",1017456523),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"worker-thread","worker-thread",3011956395),null], null), null),new cljs.core.Keyword(null,"queue","queue",1121848451),cljs.core.PersistentVector.EMPTY,new cljs.core.Keyword(null,"init","init",1017141378),(function (this$){var worker = lt.objs.thread.cp.fork(lt.objs.files.lt_home.call(null,"/core/node_modules/lighttable/background/threadworker.js"),cljs.core.clj__GT_js.call(null,new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, ["--harmony"], null)),cljs.core.clj__GT_js.call(null,new cljs.core.PersistentArrayMap(null, 4, [new cljs.core.Keyword(null,"execPath","execPath",3055801288),process.execPath,new cljs.core.Keyword(null,"silent","silent",4406544327),true,new cljs.core.Keyword(null,"env","env",1014004831),new cljs.core.PersistentArrayMap(null, 1, ["ATOM_SHELL_INTERNAL_RUN_AS_NODE",1], null),new cljs.core.Keyword(null,"cwd","cwd",1014003170),lt.objs.files.cwd], null)));worker.stdout.on("data",(function (data){return lt.objs.console.loc_log.call(null,new cljs.core.PersistentArrayMap(null, 3, [new cljs.core.Keyword(null,"file","file",1017047278),"thread",new cljs.core.Keyword(null,"line","line",1017226086),"stdout",new cljs.core.Keyword(null,"content","content",1965434859),[cljs.core.str(data)].join('')], null));
}));
worker.stderr.on("data",(function (data){return lt.objs.console.loc_log.call(null,new cljs.core.PersistentArrayMap(null, 4, [new cljs.core.Keyword(null,"file","file",1017047278),"thread",new cljs.core.Keyword(null,"line","line",1017226086),"stderr",new cljs.core.Keyword(null,"content","content",1965434859),[cljs.core.str(data)].join(''),new cljs.core.Keyword(null,"class","class",1108647146),"error"], null));
}));
worker.on("message",(function (m){return lt.object.raise.call(null,this$,new cljs.core.Keyword(null,"message","message",1968829305),m);
}));
worker.send(cljs.core.clj__GT_js.call(null,new cljs.core.PersistentArrayMap(null, 3, [new cljs.core.Keyword(null,"msg","msg",1014012659),"init",new cljs.core.Keyword(null,"obj","obj",1014014057),lt.object.__GT_id.call(null,this$),new cljs.core.Keyword(null,"ltpath","ltpath",4216414495),lt.objs.files.lt_home.call(null)], null)));
lt.object.merge_BANG_.call(null,this$,new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"worker","worker",4526786288),worker], null));
return null;
}));
lt.objs.thread.send = (function send(msg){return lt.object.raise.call(null,lt.objs.thread.worker,new cljs.core.Keyword(null,"try-send!","try-send!",4325864057),msg);
});
lt.objs.thread.thread_STAR_ = (function thread_STAR_(func){var func_str = [cljs.core.str(""),cljs.core.str(func)].join('');var n = cljs.core.gensym.call(null,"theadfunc");lt.objs.thread.send.call(null,new cljs.core.PersistentArrayMap(null, 3, [new cljs.core.Keyword(null,"msg","msg",1014012659),"register",new cljs.core.Keyword(null,"name","name",1017277949),n,new cljs.core.Keyword(null,"func","func",1017058870),func_str], null));
return (function() { 
var G__14440__delegate = function (obj,args){return lt.objs.thread.send.call(null,new cljs.core.PersistentArrayMap(null, 4, [new cljs.core.Keyword(null,"msg","msg",1014012659),"call",new cljs.core.Keyword(null,"name","name",1017277949),n,new cljs.core.Keyword(null,"obj","obj",1014014057),lt.object.__GT_id.call(null,obj),new cljs.core.Keyword(null,"params","params",4313443576),cljs.core.map.call(null,cljs.core.pr_str,args)], null));
};
var G__14440 = function (obj,var_args){
var args = null;if (arguments.length > 1) {
  args = cljs.core.array_seq(Array.prototype.slice.call(arguments, 1),0);} 
return G__14440__delegate.call(this,obj,args);};
G__14440.cljs$lang$maxFixedArity = 1;
G__14440.cljs$lang$applyTo = (function (arglist__14441){
var obj = cljs.core.first(arglist__14441);
var args = cljs.core.rest(arglist__14441);
return G__14440__delegate(obj,args);
});
G__14440.cljs$core$IFn$_invoke$arity$variadic = G__14440__delegate;
return G__14440;
})()
;
});
lt.object.tag_behaviors.call(null,new cljs.core.Keyword(null,"worker-thread","worker-thread",3011956395),new cljs.core.PersistentVector(null, 6, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword("lt.objs.thread","kill!","lt.objs.thread/kill!",2826681832),new cljs.core.Keyword("lt.objs.thread","connect","lt.objs.thread/connect",4665947759),new cljs.core.Keyword("lt.objs.thread","send!","lt.objs.thread/send!",2752302802),new cljs.core.Keyword("lt.objs.thread","queue!","lt.objs.thread/queue!",1667114793),new cljs.core.Keyword("lt.objs.thread","try-send","lt.objs.thread/try-send",1561926143),new cljs.core.Keyword("lt.objs.thread","message","lt.objs.thread/message",4662440292)], null));
lt.objs.thread.worker = lt.object.create.call(null,new cljs.core.Keyword("lt.objs.thread","worker-thread","lt.objs.thread/worker-thread",1400507698));
