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

About the lifecycle of dll in edge #680

Open
yaphone opened this issue May 13, 2019 · 3 comments
Open

About the lifecycle of dll in edge #680

yaphone opened this issue May 13, 2019 · 3 comments

Comments

@yaphone
Copy link

yaphone commented May 13, 2019

Hello, I am a newer of edge-js, I create a C# dll project, source code as bellow:

namespace NodeDemo
{
    public class Printer
    {
        private string name;

        public async Task<object> Init(string param)
        {
            this.name = param;
            return this.name;
        }

        public async Task<object> SayHello(string param)
        {
            return "Hello, " + name;
        }

        public async Task<object> SayGoodbye(string param)
        {
            return "Goodbye, " + name;
        }
    }
}

And I got the dll file, put it in my node project, then create an api.js like this:

var edge = require('edge')
var path = require('path')

var init = edge.func({
    assemblyFile: path.join(__dirname, '../dll/NodeDemo.dll'),
    typeName: 'NodeDemo.Printer',
    methodName: 'Init'
}) 


var sayHello = edge.func({
    assemblyFile: path.join(__dirname, '../dll/NodeDemo.dll'),
    typeName: 'NodeDemo.Printer',
    methodName: 'SayHello'
}) 

var sayGoodbye = edge.func({
    assemblyFile: path.join(__dirname, '../dll/NodeDemo.dll'),
    typeName: 'NodeDemo.Printer',
    methodName: 'SayGoodbye'
})

module.exports = {
    init,
    sayHello,
    sayGoodbye
}

Finally, I create an index.js like this:

var printer = require('./api/printer')

printer.init('yaphone', function(err, result) {
    if (err) throw err
    console.log(result)
})

printer.sayHello('', function(err, result) {
    if (err) throw err
    console.log(result)
})

printer.sayGoodbye('', function(err, result) {
    if (err) throw err
    console.log(result)
})

I try to run node index.js, and I got output in the console like this:

yaphone
Hello,
Goodbye,

But, my expect output is this:

yaphone
Hello, yaphone
Goodbye, yaphone

I suspect this is related to the life cycle of the dll, because I load the dll three times in node. So, how can I load once, and use the three methods in the dll?

Thx for any replies!

@bpetty-formfast
Copy link

I am looking at using Edge and wanted to see what kind of defects it has.
Looks like the project might be dead (not updated for 2 years).

I noticed your question, but it looks like you are expecting a bunch of async function to behave as if they were sync. What if you await for your init to complete?

@yaphone
Copy link
Author

yaphone commented Jul 19, 2019

I am looking at using Edge and wanted to see what kind of defects it has.
Looks like the project might be dead (not updated for 2 years).

I noticed your question, but it looks like you are expecting a bunch of async function to behave as if they were sync. What if you await for your init to complete?

THX for your reply. I was a fresher when I ask this question, and I use edge in a wrong way. I write a dll with C#, and I need to use in my electron program, so at last I use 'electron-edge-js'.

In my program, I need to init something like the ca cert and the environment, finally, I write two dlls, electron-edge-js call the first dll, and the first dll call the second to do the init function.

@prasanna4567
Copy link

Is there any other way of doing this without using intermediate dll?

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

3 participants