Permalink
Browse files

Flow fully deprecated from public api

  • Loading branch information...
1 parent d8658d0 commit 9c7aaf0b920e29269dc2d983c1e40deef7803e7a @cloudshift committed Mar 12, 2012
View
@@ -12,9 +12,36 @@ import cloudshift.Http;
#end
import cloudshift.Session;
-import cloudshift.Flow;
-typedef Chan<T> = Pipe<T>;
+typedef TMeta = {
+ var ch:String;
+ var op:String;
+ var um:Dynamic; /* user meta data */
+}
+
+typedef Pkt<T> = {
+ var s:String; // session ID
+ var p:T; // payload
+ var m:TMeta; // meta
+}
+
+interface Chan<T> {
+ // internal use only
+ var _fill:Dynamic->String->Dynamic->Void;
+ function _defaultFill<T>(o:Dynamic,chanID:String,meta:Dynamic):Void;
+
+ // public
+ function pub(o:T,?meta:Dynamic):Void;
+ function sub(cb:T->Void,?info:Dynamic):Void->Void;
+ function subPkt(cb:Pkt<T>->Void,?info:Dynamic):Void->Void;
+ function filter(cb:T->Null<T>):Void->Void;
+ function filterPkt(cb:Pkt<T>->Null<Pkt<T>>):Void->Void;
+ function pid():String;
+ function subs():Array<Dynamic>;
+ function removeAllSubs():Void;
+ function route<P>(chan:Chan<P>,?map:T->P):Void->Void;
+ function peek(cb:EOperation->Void):Void;
+}
interface ChannelProvider {
function channel<T>(chanID:String):Outcome<String,Chan<T>>;
View
@@ -17,17 +17,17 @@ enum Either<A, B> {
Right(v: B);
}
-enum EOperation {
- Add(info:Option<Dynamic>);
- Del(info:Option<Dynamic>);
-}
-
enum ELogLevel {
I(s:String);
W(s:String);
E(s:String);
}
+enum EOperation {
+ Add(info:Option<Dynamic>);
+ Del(info:Option<Dynamic>);
+}
+
interface Observable<T> {
var preNotify:T->Dynamic;
function notify(o:T):Void;
@@ -38,10 +38,8 @@ interface Observable<T> {
}
interface Future<T> {
- var sequence:Int;
function resolve(t: T): Future<T>;
function deliver(f: T -> Void): Future<T>;
- function deliverMe(f:Future<T>-> Void): Future<T>;
function isCanceled(): Bool;
function ifCanceled(f: Void -> Void): Future<T>;
function allowCancelOnlyIf(f: Void -> Bool): Future<T>;
@@ -66,10 +64,18 @@ enum EPartState<E> {
Except(e:Dynamic);
}
+typedef PartInfo = {
+ var name:String;
+ var ver:String;
+ var auth:String;
+}
+
// (S) start param object, (B) bad return type, (G) good return type, (E) event enum
interface Part_<S,B,G,E> {
var _events:Observable<EPartState<E>>;
var partID(default,null):String;
+ var state:EPartState<E>;
+ var info:PartInfo;
function start(d:S,?oc:Outcome<B,G>):Outcome<B,G>;
function stop(d:Dynamic):Outcome<String,Dynamic>;
function observe(cb:E->Void,?info:Dynamic):Void->Void;
@@ -90,6 +96,22 @@ typedef AnyPart = Part<Dynamic,Dynamic,Dynamic,Dynamic>;
class Core {
public static var CSROOT = "/__cs/";
+
+ public static function
+ init() {
+ logInit();
+ #if nodejs
+ Sys.events().observe(function(e) {
+ switch(e) {
+ case ProcessUncaughtException(exc):
+ trace(exc);
+ trace(haxe.Stack.exceptionStack());
+ case ProcessExit:
+ case SigInt(sig):
+ }
+ });
+ #end
+ }
public static inline function
future<T>():Future<T> {
@@ -102,13 +124,8 @@ class Core {
}
public static function
- part<S,B,G,E>(parent:Dynamic):Part_<S,B,G,E> {
- return new cloudshift.core.PartBaseImpl(parent);
- }
-
- public static function
- waitFor(toJoin:Array<Future<Dynamic>>):Future<Array<Dynamic>> {
- return cloudshift.core.FutureImpl.waitFor(toJoin);
+ part<S,B,G,E>(parent:Dynamic,?info:PartInfo):Part_<S,B,G,E> {
+ return new cloudshift.core.PartBaseImpl(parent,info);
}
public static function cancelledFuture() {
@@ -126,7 +143,7 @@ class Core {
}
inline static public function
- logTo(?fileName:String) {
+ logInit(?fileName:String) {
LogImpl.init(fileName);
}
@@ -191,7 +208,44 @@ class Core {
});
return oc;
}
-
+
+ public static
+ function waitFor(toJoin:Array<Future<Dynamic>>):Future<Array<Dynamic>> {
+ var
+ count = toJoin.length,
+ fut = Core.future();
+
+ toJoin.foreach(function(xprm:Future<Dynamic>) {
+ if(!Std.is(xprm,Future)) {
+ throw "not a future:"+xprm;
+ }
+
+ xprm.deliver(function(r:Dynamic) {
+ count--;
+ if (count == 0) {
+ fut.resolve(toJoin.map(function(el) {
+ return el.value().get();
+ }));
+ }
+ });
+ });
+ return fut;
+ }
+
+ public static function
+ listParts() {
+ cloudshift.core.PartBaseImpl.runningParts.foreach(function(p) {
+ if (p.info() != null) {
+ trace(p.info());
+ }
+ });
+ }
+
+ public static function
+ assert( cond : Bool, ?pos : haxe.PosInfos ) {
+ if( !cond )
+ Core.error("Assert failed in "+pos.className+"::"+pos.methodName,pos);
+ }
}
View
@@ -640,6 +640,17 @@ class PartX {
part.part_._events.observe(cb);
}
+ public static function
+ state<S,B,G,E>(part:Part<S,B,G,E>):EPartState<E> {
+ return part.part_.state;
+ }
+
+ public static function
+ info<S,B,G,E>(part:Part<S,B,G,E>) {
+ return part.part_.info;
+ }
+
+
}
class OutcomeX {
@@ -1,10 +1,11 @@
-package cloudshift.flow;
+package cloudshift.channel;
import cloudshift.Core;
import cloudshift.Session;
-import cloudshift.Flow;
-import cloudshift.flow.InternalApi;
+import cloudshift.Channel;
+import cloudshift.channel.Flow;
+import cloudshift.channel.InternalApi;
class ClientSinkImpl extends SinkImpl {
@@ -23,15 +24,15 @@ class ClientSinkImpl extends SinkImpl {
}
override function
- removePipe<T>(pipe:Pipe<T>) {
- super.removePipe(pipe);
+ removeChan<T>(pipe:Chan<T>) {
+ super.removeChan(pipe);
reqUnsub(_sessID,pipe,function(cb) {
Core.info("ok unsubbed:"+pipe.pid());
});
}
override function
- reqUnsub(sessId,pipe:Pipe<Dynamic>,cb:Either<String,String>->Void) {
+ reqUnsub(sessId,pipe:Chan<Dynamic>,cb:Either<String,String>->Void) {
_conduit[0].leave(pipe.pid()).deliver(cb);
}
}
@@ -1,26 +1,16 @@
-package cloudshift;
+package cloudshift.channel;
import cloudshift.Core;
using cloudshift.Mixin;
import cloudshift.Session;
+import cloudshift.Channel;
#if nodejs
import cloudshift.Http;
-import cloudshift.flow.InternalApi;
+import cloudshift.channel.InternalApi;
#end
-typedef TMeta = {
- var ch:String;
- var op:String;
- var um:Dynamic; /* user meta data */
-}
-
-typedef Pkt<T> = {
- var s:String; // session ID
- var p:T; // payload
- var m:TMeta; // meta
-}
typedef ConduitClientStart = {
var host:String;
@@ -49,36 +39,19 @@ interface Conduit implements Part<Dynamic,String,Conduit,ConduitEvent> {
}
enum SinkEvent {
- Authorize(sessID:String,pipe:Pipe<Dynamic>,cb:Either<String,String>->Void);
+ Authorize(sessID:String,chan:Chan<Dynamic>,cb:Either<String,String>->Void);
ConnectionClose(sessID:String);
}
interface Sink implements Part<Conduit,String,Sink,SinkEvent> {
- function pipe<T>(chanID:String):Pipe<T>;
+ function chan<T>(chanID:String):Chan<T>;
function addConduit(conduit:Conduit):Void ;
- function pipeFromId(chanID:String):Option<Pipe<Dynamic>>;
- function authorize<T>(pipe:Pipe<T>):Outcome<String,Pipe<T>>;
- function removePipe<T>(p:Pipe<T>):Void;
- function direct<T>(sessID:String):Pipe<T>;
+ function chanFromId(chanID:String):Option<Chan<Dynamic>>;
+ function authorize<T>(chan:Chan<T>):Outcome<String,Chan<T>>;
+ function removeChan<T>(p:Chan<T>):Void;
+ function direct<T>(sessID:String):Chan<T>;
}
-interface Pipe<T> {
- // internal use only
- var _fill:Dynamic->String->Dynamic->Void;
- function _defaultFill<T>(o:Dynamic,chanID:String,meta:Dynamic):Void;
-
- // public
- function fill(o:T,?meta:Dynamic):Void;
- function drain(cb:T->Void,?info:Dynamic):Void->Void;
- function drainPkt(cb:Pkt<T>->Void,?info:Dynamic):Void->Void;
- function filter(cb:T->Null<T>):Void->Void;
- function filterPkt(cb:Pkt<T>->Null<Pkt<T>>):Void->Void;
- function pid():String;
- function drains():Array<Dynamic>;
- function removeAllDrains():Void;
- function divert<P>(chan:Pipe<P>,?map:T->P):Void->Void;
- function peek(cb:EOperation->Void):Void;
-}
/*
typedef QuickFlow = {
@@ -96,12 +69,12 @@ class Flow {
public static function
sink(sessionMgr:SessionMgr):Sink {
- return new cloudshift.flow.ServerSinkImpl(sessionMgr);
+ return new cloudshift.channel.ServerSinkImpl(sessionMgr);
}
public static function
pushConduit(sessionMgr:SessionMgr):Conduit {
- var pl = new cloudshift.flow.PushListenerImpl(sessionMgr);
+ var pl = new cloudshift.channel.PushListenerImpl(sessionMgr);
sessionMgr.http().handler(new EReg(Flow.PUSH,""),pl.postHandler);
return pl;
}
@@ -110,7 +83,7 @@ class Flow {
/*
public static function
quickFlow() {
- return new cloudshift.flow.QuickFlowImpl();
+ return new cloudshift.channel.QuickFlowImpl();
}
*/
@@ -120,18 +93,18 @@ class Flow {
public static function
pushConduit():Conduit {
trace("inst PushClientImpl");
- return new cloudshift.flow.PushClientImpl();
+ return new cloudshift.channel.PushClientImpl();
}
public static function
sink(sessID:String):Sink {
- return new cloudshift.flow.ClientSinkImpl(sessID);
+ return new cloudshift.channel.ClientSinkImpl(sessID);
}
#end
public static function
- pipeID(pkt:Pkt<Dynamic>) {
+ chanID(pkt:Pkt<Dynamic>) {
return pkt.m.ch;
}
@@ -1,8 +1,8 @@
-package cloudshift.flow;
+package cloudshift.channel;
import cloudshift.Core;
-import cloudshift.Flow;
+import cloudshift.channel.Flow;
interface MessageQ {
function append(pkt:Dynamic):Void;
@@ -1,7 +1,7 @@
-package cloudshift.flow;
-import cloudshift.Flow;
-import cloudshift.flow.InternalApi;
+package cloudshift.channel;
+import cloudshift.channel.Flow;
+import cloudshift.channel.InternalApi;
using cloudshift.Mixin;
Oops, something went wrong.

0 comments on commit 9c7aaf0

Please sign in to comment.