Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Implement progress callback so node domains are able to notify the Brackets before they finish #10761

Merged
merged 2 commits into from
Jun 12, 2015
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
6 changes: 6 additions & 0 deletions src/utils/NodeConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ define(function (require, exports, module) {
delete this._pendingCommandDeferreds[m.message.id];
}
break;
case "commandProgress":
responseDeferred = this._pendingCommandDeferreds[m.message.id];
if (responseDeferred) {
responseDeferred.notifyWith(this, [m.message.message]);
}
break;
case "commandError":
responseDeferred = this._pendingCommandDeferreds[m.message.id];
if (responseDeferred) {
Expand Down
27 changes: 27 additions & 0 deletions test/spec/NodeConnection-test-files/TestCommandsTwo.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@
});
}

/**
* @private
* Handler for test.reverseAsyncWithProgress command. Reverses the specified string
* and then returns the result asynconously, but launches progress event before that.
* @param {string} s String to reverse.
* @param {Function} cb Callback function of the form cb(err, response)
* @param {Function} pcb Progress callback function of the form pcb(message)
*/
function cmdTestReverseAsyncWithProgress(s, cb, pcb) {
var result = s.split("").reverse().join("");
process.nextTick(function () {
pcb("progress");
process.nextTick(function () {
cb(null, result);
});
});
}

/**
* Initializes the test domain with an additional test command.
* @param {DomainManager} DomainManager The DomainManager for the server
Expand All @@ -66,6 +84,15 @@
[{name: "s", type: "string"}],
[{name: "reversedString", type: "string"}]
);
_domainManager.registerCommand(
"test",
"reverseAsyncWithProgress",
cmdTestReverseAsyncWithProgress,
true,
"reverses the specified string using an async call on the server and calls a progress event before",
[{name: "s", type: "string"}],
[{name: "reversedString", type: "string"}]
);
}

exports.init = init;
Expand Down
36 changes: 36 additions & 0 deletions test/spec/NodeConnection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,42 @@ define(function (require, exports, module) {
});
});

it("should receive progress events from asynchronous commands", function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zaggino I ran the Live preview test for Node connection and the test is timing out at should receive progress events from asynchronous commands [win 8.1]. Any idea why?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abose Have you taken shell changes also? adobe/brackets-shell#509

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh! i didn't that explains. Did you verify this change?

var connection = createConnection();
var commandDeferred = null;
var result = null;
var progressMessage = null;
runConnectAndWait(connection, false);
runLoadDomainsAndWait(connection, ["TestCommandsTwo"], false);
runs(function () {
commandDeferred = connection.domains.test.reverseAsyncWithProgress("asdf");
commandDeferred.progress(function (message) {
progressMessage = message;
});
commandDeferred.done(function (response) {
result = response;
});
});
waitsFor(
function () {
return commandDeferred && progressMessage !== null;
},
CONNECTION_TIMEOUT
);
waitsFor(
function () {
return commandDeferred &&
commandDeferred.state() === "resolved" &&
result;
},
CONNECTION_TIMEOUT
);
runs(function () {
expect(progressMessage).toBe("progress");
expect(result).toBe("fdsa");
});
});

it("should receive events", function () {
var connection = createConnection();
var spy = jasmine.createSpy();
Expand Down