Skip to content

Commit

Permalink
Merge pull request #26 from citrusleaf/async-error-callback
Browse files Browse the repository at this point in the history
Async error callback
  • Loading branch information
jhecking committed Apr 26, 2016
2 parents 99550f5 + ea590dc commit ca85c3c
Show file tree
Hide file tree
Showing 22 changed files with 146 additions and 227 deletions.
3 changes: 1 addition & 2 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
],
'sources': [
'src/main/aerospike.cc',
'src/main/async_listener.cc',
'src/main/client.cc',
'src/main/query.cc',
'src/main/scan.cc',
'src/main/async.cc',
'src/main/client/apply_async.cc',
'src/main/client/batch_exists.cc',
'src/main/client/batch_get.cc',
Expand Down Expand Up @@ -61,7 +61,6 @@
'src/main/enums/scanPriority.cc',
'src/main/enums/job_status.cc',
'src/main/enums/udf_languages.cc',
'src/main/util/async.cc',
'src/main/util/conversions.cc',
'src/main/util/log.cc'
],
Expand Down
80 changes: 35 additions & 45 deletions src/include/async.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
* Copyright 2013-2016 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,32 +16,30 @@

#pragma once

extern "C" {
#include <aerospike/aerospike.h>
#include <aerospike/aerospike_batch.h>
#include <aerospike/as_event.h>
}

#include <nan.h>
#include <node.h>
#include <citrusleaf/cf_queue.h>

/*******************************************************************************
* STRUCTURES
********************************************************************************/
// This structure is used by query and scan async handles.
// To process the records from the callback and pass it to nodejs
typedef struct AsyncCallbackData {
Nan::Persistent<Function> data_cb;
Nan::Persistent<Function> error_cb;
Nan::Persistent<Function> end_cb;
cf_queue * result_q;
int max_q_size;
LogInfo * log;
int signal_interval;
uv_async_t async_handle;
}AsyncCallbackData;
#include "client.h"

typedef struct CallbackData {
AerospikeClient * client;
Nan::Persistent<Function> callback;
void* data;
} CallbackData;

/**
* Creates a new as_error struct with status code set to AEROSPIKE_ERR_OK.
*/
Local<Object> err_ok();

/*******************************************************************************
* FUNCTIONS
******************************************************************************/
/**
* Setup an asynchronous invocation of a function.
* Setup an asynchronous invocation of a function using libuv worker threads.
*/
Local<Value> async_invoke(
ResolveArgs(args),
Expand All @@ -50,33 +48,25 @@ Local<Value> async_invoke(
void (* respond)(uv_work_t * req, int status)
);

void async_init( uv_async_t * async, void (*async_callback)(ResolveAsyncCallbackArgs));

void async_send( uv_async_t * async);

void async_close(uv_async_t* async);

void uv_initialize_loop();

void uv_finish_loop_execution();

/**
* Asynchronously invoke callback function with the given error.
*/
void invoke_error_callback(as_error* error, CallbackData* data);

// Anyone using async infrastructure have to implement the following three
// functions.
// 1. Callback to be called when an async signal is sent.
// 2. Function to populate the data coming from C, into the queue.
// 3. Function to populate the data from the queue and send it to nodejs application.
// implements the as_async_record_listener interface
void async_record_listener(as_error* err, as_record* record, void* udata, as_event_loop* event_loop);

// currently scan and queue uses this infrastructure and has the custom implementation
// for all the three functions.
// And here is the example.
// Callback that's invoked when an async signal is sent.
//void async_callback( ResolveAsyncCallbackArgs);
// implements the as_async_write_listener interface
void async_write_listener(as_error* err, void* udata, as_event_loop* event_loop);

// Push the result from C callback into a queue.
//bool async_queue_populate(const as_val * val, AsyncCallbackData* data);
// implements the as_async_value_listener interface
void async_value_listener(as_error* err, as_val* value, void* udata, as_event_loop* event_loop);

// Process each element in the queue and call the nodejs callback with the processed data.
//void async_queue_process( AsyncCallbackData * data);
// implements the as_async_batch_listener interface
void async_batch_listener(as_error* err, as_batch_read_records* records, void* udata, as_event_loop* event_loop);

// implements the as_async_scan_listener interface
bool async_scan_listener(as_error* err, as_record* record, void* udata, as_event_loop* event_loop);

// implements the as_async_query_record_listener interface
bool async_query_record_listener(as_error* err, as_record* record, void* udata, as_event_loop* event_loop);
54 changes: 0 additions & 54 deletions src/include/async_listener.h

This file was deleted.

0 comments on commit ca85c3c

Please sign in to comment.