Skip to content

Send special message if we live sync javascript file and the liveEdit option is on #1977

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

Merged
merged 1 commit into from
Aug 5, 2016

Conversation

KristinaKoeva
Copy link
Contributor

@KristinaKoeva KristinaKoeva commented Aug 3, 2016

@enchev
Copy link
Contributor

enchev commented Aug 4, 2016

👍

@KristinaKoeva KristinaKoeva force-pushed the KristinaKoeva/LiveEditJavaScript branch from ac770af to add840f Compare August 4, 2016 15:31
private liveEdit(localToDevicePaths: Mobile.ILocalToDevicePathData[]) {
return (() => {
_.each(localToDevicePaths, localToDevicePath => {
let content = this.$fs.readFile(localToDevicePath.getLocalPath()).wait().toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use this.$fs.readText instead of readFile and skip .toString().

@rosen-vladimirov
Copy link
Contributor

I would advise you to change the sendMessage of IOSLiveSyncService to return future, which is resolved when all the data is written:

private sendMessage(message: string): IFuture<void> {
    return (() => {
        let socketWriteFuture = new Future<void>();
        try {
            let length = Buffer.byteLength(message, "utf16le");
            let payload = new Buffer(length + 4);
            payload.writeInt32BE(length, 0);
            payload.write(message, 4, length, "utf16le");

            // Have to check how to add the handler only for current sending. In case error is not raised, the socket will remain alive and next message will add a new error handler. This will be a problem in a long living process
            this.socket.once("error", err => {
                this.$logger.trace("Error while sending message: ", err);

                this.destroySocket();

                socketWriteFuture.throw(err);
            });

            this.socket.write(payload, "utf16le", () => {
                socketWriteFuture.return();
            });

        } catch(err) {
            this.$logger.trace("Error while sending page reload:", err);
            this.destroySocket();
        }

        socketWriteFuture.wait();
    }).future<void>()();
}

My idea is to make sure the message is sent. According to Node.js documentation The optional callback parameter will be executed when the data is finally written out - this may not be immediately.

@tzraikov
Copy link
Contributor

tzraikov commented Aug 5, 2016

👍

@KristinaKoeva KristinaKoeva force-pushed the KristinaKoeva/LiveEditJavaScript branch 2 times, most recently from 0425686 to 43c3ebb Compare August 5, 2016 12:56
@KristinaKoeva KristinaKoeva force-pushed the KristinaKoeva/LiveEditJavaScript branch from 43c3ebb to 9b3b3a6 Compare August 5, 2016 13:15
@rosen-vladimirov
Copy link
Contributor

👍 after green build

@KristinaKoeva KristinaKoeva merged commit 517aef4 into master Aug 5, 2016
@KristinaKoeva KristinaKoeva deleted the KristinaKoeva/LiveEditJavaScript branch August 5, 2016 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants