Skip to content

Commit

Permalink
fixup: try something
Browse files Browse the repository at this point in the history
  • Loading branch information
apapirovski committed Apr 25, 2018
1 parent 48e6289 commit f89600d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,22 @@ void TLSWrap::EncOut() {

NODE_COUNT_NET_BYTES_SENT(write_size_);

if (!res.async) {
// Simulate asynchronous finishing, TLS cannot handle this at the moment.
env()->isolate()->EnqueueMicrotask([](void* data) {
static_cast<TLSWrap*>(data)->OnStreamAfterWrite(nullptr, 0);
}, this);
}
if (!res.async)
SyncAfterWrite();
}

// Simulate asynchronous finishing, TLS cannot handle this at the moment.
void TLSWrap::SyncAfterWrite() {
env()->isolate()->EnqueueMicrotask([](void* data) {
TLSWrap* wrap = static_cast<TLSWrap*>(data);
wrap->MakeWeak(wrap);
wrap->OnStreamAfterWrite(nullptr, 0);
}, this);
ClearWeak();
// This is a cheap way for us to ensure that microtasks will get to run
// at some point in the near future.
if (env()->immediate_info()->count() == 0)
env()->SetImmediate([](Environment* env, void* data) {}, this);
}


Expand Down
2 changes: 2 additions & 0 deletions src/tls_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class TLSWrap : public AsyncWrap,
bool eof_;

private:
void SyncAfterWrite();

static void GetWriteQueueSize(
const v8::FunctionCallbackInfo<v8::Value>& info);
};
Expand Down

0 comments on commit f89600d

Please sign in to comment.