Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update API to use transferable when available #44

Merged
merged 3 commits into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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