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

Async functionality not working -- everything runs sync #97

Closed
ash47 opened this issue Oct 1, 2020 · 4 comments
Closed

Async functionality not working -- everything runs sync #97

ash47 opened this issue Oct 1, 2020 · 4 comments

Comments

@ash47
Copy link
Contributor

ash47 commented Oct 1, 2020

The C# code is not run async, it is running sync.

Sample code:

const edge = require('electron-edge-js');

let someCommand = edge.func(`
    async (input) => { 
        while(true){}
        return ".NET Welcomes " + input.ToString(); 
    }
`)

console.log('a');
someCommand('javascript', function() {
    console.log('c');
});
console.log('b');

I see "a" in the console, and then the entire app freezes due to the infinite loop within the C# code. According to the documentation, the C# code is meant to run async, meaning that it can be as CPU intense as it likes, take as long as it likes, and the JavaScript v8 engine code will continue to run.

I have also tried specifying "sync: false" specifically and even "sync: true", this didn't help.

How do I make the C# code run async?

@togradywk
Copy link

I can't comment on whether or not sync is actually working, but I had to fork a process and run edge in the forked process to get it to be async. When I ran edge from the main electron process it locked up the app.

It would be nice to figure out if that is the expected standard procedure or if there is an issue with edge.

@agracio
Copy link
Owner

agracio commented Oct 2, 2020

This is not an issue with edge-js but rather with Electron when module is running on main Electron process. Take a look at related issue below, this comment explains the problem in depth paranext/paranext#9 (comment)

@ash47
Copy link
Contributor Author

ash47 commented Oct 3, 2020

Thanks for the pro tip @togradywk -- on my end, I've gone ahead and forked the process, and written logic to control edge.js via the fork <3

This should still really be fixed, but it no longer bothers me if it is or not

@UrielMaD
Copy link

As an example for someone facing this issue I'll show what worked for me:

In my case I was trying to open a pptx file asynchronously so, I used the module office-script which is based on edge-js,

So first I replaced edje-js to electron-edje-js in the module,

Next, to call my pptx file:

main.js:
const { fork } = require("child_process"); fork("../child.js", [], { env: {file: 'filename'}, })

child.js:
`
const path = require('path');
const powerpoint = require('office-script').powerpoint;
const filePath = '../../directory/';

powerpoint.open(path.join(${remotePath}${process.env.file}.pptx), function(err) {
if(err) throw err;
});
`
I hope this could help a little, this way I avoided the main process to freezeing the renderer process as well

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

No branches or pull requests

4 participants