Skip to content
This repository has been archived by the owner on Feb 27, 2022. It is now read-only.

Update for nove v0.6.x and later compatibility #3

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions README
@@ -1,10 +1,10 @@
This is about the simplest reduction you can get for using eio_custom.
This is about the simplest reduction you can get for using uv_queue_work.

To run:

node-waf configure build && node test.js
npm install && node test.js

Or, you can link or install it with npm. Note that it has hardly anything
in the package.json, either.

npm link && npm test async-simple
npm install && npm test async-simple
10 changes: 10 additions & 0 deletions binding.gyp
@@ -0,0 +1,10 @@
{
'targets': [
{
'target_name': 'nas',
'sources': [
'nas.cc',
]
}
]
}
23 changes: 12 additions & 11 deletions nas.cc
Expand Up @@ -10,13 +10,14 @@ using namespace node;
using namespace v8;

static Handle<Value> DoSomethingAsync (const Arguments&);
static int DoSomething (eio_req *);
static int DoSomething_After (eio_req *);
static void DoSomething (uv_work_t *);
static void DoSomething_After (uv_work_t *);
extern "C" void init (Handle<Object>);

struct simple_request {
int x;
int y;
int result;
Persistent<Function> cb;
// maybe it matters to put the char[] last? not sure.
char name[1];
Expand All @@ -41,27 +42,27 @@ static Handle<Value> DoSomethingAsync (const Arguments& args) {
sr->x = x;
sr->y = y;

eio_custom(DoSomething, EIO_PRI_DEFAULT, DoSomething_After, sr);
ev_ref(EV_DEFAULT_UC);
uv_work_t *_req = new uv_work_t;
_req->data = sr;
uv_queue_work(uv_default_loop(), _req, DoSomething, DoSomething_After);

return Undefined();
}

// this function happens on the thread pool
// doing v8 things in here will make bad happen.
static int DoSomething (eio_req *req) {
static void DoSomething (uv_work_t *req) {
struct simple_request * sr = (struct simple_request *)req->data;
sleep(2); // just to make it less pointless to be async.
req->result = sr->x + sr->y;
return 0;
sr->result = sr->x + sr->y;
}

static int DoSomething_After (eio_req *req) {
static void DoSomething_After (uv_work_t *req) {
HandleScope scope;
ev_unref(EV_DEFAULT_UC);
struct simple_request * sr = (struct simple_request *)req->data;
Local<Value> argv[3];
argv[0] = Local<Value>::New(Null());
argv[1] = Integer::New(req->result);
argv[1] = Integer::New(sr->result);
argv[2] = String::New(sr->name);
TryCatch try_catch;
sr->cb->Call(Context::GetCurrent()->Global(), 3, argv);
Expand All @@ -70,7 +71,7 @@ static int DoSomething_After (eio_req *req) {
}
sr->cb.Dispose();
free(sr);
return 0;
delete req;
}

extern "C" void init (Handle<Object> target) {
Expand Down
5 changes: 3 additions & 2 deletions package.json
@@ -1,7 +1,8 @@
{ "name" : "async-simple"
, "description" : "An eio_custom example program"
, "description" : "An uv_queue_work example program"
, "version" : "1.0.0"
, "author" : "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)"
, "main" : "build/default/nas.node"
, "main" : "build/Release/nas.node"
, "scripts" : { "test" : "node test.js" }
, "engines" : { "node" : ">= 0.5.6" }
}
2 changes: 1 addition & 1 deletion test.js
@@ -1,4 +1,4 @@
var nas = require("./build/default/nas")
var nas = require("./build/Release/nas")
, start = Date.now()

console.log("js "+(Date.now() - start), "before hello")
Expand Down
17 changes: 0 additions & 17 deletions wscript

This file was deleted.