Skip to content

Commit

Permalink
Merge pull request #44 from jpmorganchase/transferable-update
Browse files Browse the repository at this point in the history
Update API to use transferable when available
  • Loading branch information
texodus authored Feb 13, 2018
2 parents 72cfdc6 + 47e7854 commit c8c725e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
42 changes: 32 additions & 10 deletions packages/perspective/src/js/perspective.parallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,17 @@ function table(worker, data, options) {
data: data,
options: options
}
if (this._worker.initialized.value) {
let post = () => {
if (this._worker.transferable && data instanceof ArrayBuffer) {
this._worker.postMessage(msg, [data]);
} else {
this._worker.postMessage(msg);
}
};
if (this._worker.initialized.value) {
post();
} else {
this._worker.messages.push(() => {
if (this._worker.transferable && data instanceof ArrayBuffer) {
this._worker.postMessage(msg, [data]);
} else {
this._worker.postMessage(msg);
}
});
this._worker.messages.push(post);
}
}

Expand All @@ -145,10 +142,35 @@ table.prototype.schema = async_queue('schema', 'table_method');

table.prototype.size = async_queue('size', 'table_method');

table.prototype.update = async_queue('update', 'table_method');

table.prototype.columns = async_queue('columns', 'table_method');


table.prototype.update = function(data) {
return new Promise( (resolve, reject) => {
this._worker.handlers[++this._worker.msg_id] = {resolve, reject};
var msg = {
id: this._worker.msg_id,
name: this._name,
cmd: 'table_method',
method: 'update',
args: [data],
};
let post = () => {
if (this._worker.transferable && data instanceof ArrayBuffer) {
this._worker.postMessage(msg, [data]);
} else {
this._worker.postMessage(msg);
}
};
if (this._worker.initialized.value) {
post();
} else {
this._worker.messages.push(post);
}
});
}


table.prototype.execute = function (f) {
var msg = {
cmd: 'table_execute',
Expand Down
2 changes: 1 addition & 1 deletion packages/perspective/test/js/constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ module.exports = (perspective) => {
});

it("Arrow constructor", async function () {
var table = perspective.table(arrow);
var table = perspective.table(arrow.slice());
var view = table.view();
let result = await view.to_json();
expect(arrow_result).toEqual(result);
Expand Down
10 changes: 5 additions & 5 deletions packages/perspective/test/js/updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ module.exports = (perspective) => {
});

it("Arrow `update()`s", async function () {
var table = perspective.table(arrow);
table.update(arrow);
var table = perspective.table(arrow.slice());
table.update(arrow.slice());
var view = table.view();
let result = await view.to_json();
expect(arrow_result.concat(arrow_result)).toEqual(result);
Expand Down Expand Up @@ -166,21 +166,21 @@ module.exports = (perspective) => {
});

it("Arrow with {index: 'i64'} (int)", async function () {
var table = perspective.table(arrow, {index: 'i64'});
var table = perspective.table(arrow.slice(), {index: 'i64'});
var view = table.view();
let result = await view.to_json();
expect(arrow_result).toEqual(result);
});

it("Arrow with {index: 'char'} (char)", async function () {
var table = perspective.table(arrow, {index: 'char'});
var table = perspective.table(arrow.slice(), {index: 'char'});
var view = table.view();
let result = await view.to_json();
expect(arrow_indexed_result).toEqual(result);
});

it("Arrow with {index: 'dict'} (dict)", async function () {
var table = perspective.table(arrow, {index: 'dict'});
var table = perspective.table(arrow.slice(), {index: 'dict'});
var view = table.view();
let result = await view.to_json();
expect(arrow_indexed_result).toEqual(result);
Expand Down

0 comments on commit c8c725e

Please sign in to comment.