// 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__13929_13933 = 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__13930_13934 = null;var count__13931_13935 = 0;var i__13932_13936 = 0;while(true){
if((i__13932_13936 < count__13931_13935))
{var q_13937 = cljs.core._nth.call(null,chunk__13930_13934,i__13932_13936);lt.object.raise.call(null,this$,new cljs.core.Keyword(null,"send!","send!",1123226891),q_13937);
{
var G__13938 = seq__13929_13933;
var G__13939 = chunk__13930_13934;
var G__13940 = count__13931_13935;
var G__13941 = (i__13932_13936 + 1);
seq__13929_13933 = G__13938;
chunk__13930_13934 = G__13939;
count__13931_13935 = G__13940;
i__13932_13936 = G__13941;
continue;
}
} else
{var temp__4092__auto___13942 = cljs.core.seq.call(null,seq__13929_13933);if(temp__4092__auto___13942)
{var seq__13929_13943__$1 = temp__4092__auto___13942;if(cljs.core.chunked_seq_QMARK_.call(null,seq__13929_13943__$1))
{var c__4262__auto___13944 = cljs.core.chunk_first.call(null,seq__13929_13943__$1);{
var G__13945 = cljs.core.chunk_rest.call(null,seq__13929_13943__$1);
var G__13946 = c__4262__auto___13944;
var G__13947 = cljs.core.count.call(null,c__4262__auto___13944);
var G__13948 = 0;
seq__13929_13933 = G__13945;
chunk__13930_13934 = G__13946;
count__13931_13935 = G__13947;
i__13932_13936 = G__13948;
continue;
}
} else
{var q_13949 = cljs.core.first.call(null,seq__13929_13943__$1);lt.object.raise.call(null,this$,new cljs.core.Keyword(null,"send!","send!",1123226891),q_13949);
{
var G__13950 = cljs.core.next.call(null,seq__13929_13943__$1);
var G__13951 = null;
var G__13952 = 0;
var G__13953 = 0;
seq__13929_13933 = G__13950;
chunk__13930_13934 = G__13951;
count__13931_13935 = G__13952;
i__13932_13936 = G__13953;
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__13954__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__13954 = 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__13954__delegate.call(this,obj,args);};
G__13954.cljs$lang$maxFixedArity = 1;
G__13954.cljs$lang$applyTo = (function (arglist__13955){
var obj = cljs.core.first(arglist__13955);
var args = cljs.core.rest(arglist__13955);
return G__13954__delegate(obj,args);
});
G__13954.cljs$core$IFn$_invoke$arity$variadic = G__13954__delegate;
return G__13954;
})()
;
});
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));
