|
@ -28,6 +28,7 @@ Persistent<FunctionTemplate> EventEmitter::constructor_template; |
|
|
|
|
|
|
|
|
/* Poor Man's coroutines */ |
|
|
/* Poor Man's coroutines */ |
|
|
static Promise *coroutine_top; |
|
|
static Promise *coroutine_top; |
|
|
|
|
|
static int coroutine_stack_size; |
|
|
|
|
|
|
|
|
void EventEmitter::Initialize(Local<FunctionTemplate> ctemplate) { |
|
|
void EventEmitter::Initialize(Local<FunctionTemplate> ctemplate) { |
|
|
HandleScope scope; |
|
|
HandleScope scope; |
|
@ -41,6 +42,7 @@ void EventEmitter::Initialize(Local<FunctionTemplate> ctemplate) { |
|
|
// All other prototype methods are defined in events.js
|
|
|
// All other prototype methods are defined in events.js
|
|
|
|
|
|
|
|
|
coroutine_top = NULL; |
|
|
coroutine_top = NULL; |
|
|
|
|
|
coroutine_stack_size = 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static bool ReallyEmit(Handle<Object> self, |
|
|
static bool ReallyEmit(Handle<Object> self, |
|
@ -176,6 +178,10 @@ void Promise::Block(void) { |
|
|
assert(prev_ == NULL); |
|
|
assert(prev_ == NULL); |
|
|
if (coroutine_top) prev_ = coroutine_top; |
|
|
if (coroutine_top) prev_ = coroutine_top; |
|
|
coroutine_top = this; |
|
|
coroutine_top = this; |
|
|
|
|
|
coroutine_stack_size++; |
|
|
|
|
|
if (coroutine_stack_size > 10) { |
|
|
|
|
|
fprintf(stderr, "(node) WARNING: promise.wait() is being called too often.\n"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
ev_loop(EV_DEFAULT_UC_ 0); |
|
|
ev_loop(EV_DEFAULT_UC_ 0); |
|
|
|
|
|
|
|
@ -187,6 +193,7 @@ void Promise::Destack() { |
|
|
ev_unloop(EV_DEFAULT_ EVUNLOOP_ONE); |
|
|
ev_unloop(EV_DEFAULT_ EVUNLOOP_ONE); |
|
|
coroutine_top = prev_; |
|
|
coroutine_top = prev_; |
|
|
prev_ = NULL; |
|
|
prev_ = NULL; |
|
|
|
|
|
coroutine_stack_size--; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Promise::Detach(void) { |
|
|
void Promise::Detach(void) { |
|
|