// Copyright 2009 Ryan Dahl #ifndef SRC_EVENTS_H_ #define SRC_EVENTS_H_ #include #include namespace node { class EventEmitter : public ObjectWrap { public: static void Initialize(v8::Local ctemplate); static v8::Persistent constructor_template; bool Emit(const char *event, int argc, v8::Handle argv[]); protected: static v8::Handle Emit(const v8::Arguments& args); EventEmitter() : ObjectWrap () { } }; class Promise : public EventEmitter { public: static void Initialize(v8::Handle target); static v8::Persistent constructor_template; static Promise* Create(void); bool EmitSuccess(int argc, v8::Handle argv[]); bool EmitError(int argc, v8::Handle argv[]); void Block(); v8::Handle Handle() { return handle_; } protected: static v8::Handle New(const v8::Arguments& args); static v8::Handle Block(const v8::Arguments& args); static v8::Handle EmitSuccess(const v8::Arguments& args); static v8::Handle EmitError(const v8::Arguments& args); virtual void Detach(void); bool has_fired_; bool blocking_; Promise *prev_; /* for the prev in the Poor Man's coroutine stack */ void Destack(); Promise() : EventEmitter() { has_fired_ = false; blocking_ = false; prev_ = NULL; } }; } // namespace node #endif // SRC_EVENTS_H_