Hello, First of all: thank you very much for maintaining this great project!
I'm C programmer learning now Cockpit. My problem is as follows: for some of the operation I must use external helper and I must wait for it output. The cockpit.spawn() function returns the promise, which is non-blocking operation (as expected). How can I make it work as blocking one? Which mean: the rest of the code in the function should be done after receiving full output of the cockpit.spawn (done() or fail())
best regards, Magik
You are looking for `await`, if you use starter kit you have it already configured. With it you can "wait" for a promisse to complete,
Take a look here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements...
Em qua, 9 de jan de 2019 às 18:52, . magicznykrag@gmail.com escreveu:
Hello, First of all: thank you very much for maintaining this great project!
I'm C programmer learning now Cockpit. My problem is as follows: for some of the operation I must use external helper and I must wait for it output. The cockpit.spawn() function returns the promise, which is non-blocking operation (as expected). How can I make it work as blocking one? Which mean: the rest of the code in the function should be done after receiving full output of the cockpit.spawn (done() or fail())
best regards, Magik
cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste...
Daniel,
Thank you very much for the answer! I was not using starter-pack, I've just started with creating direct on the server the manifest, html, css and js files. I'm not using npm at all. Is is required for Cockpit functionality? Of course I'll give starter-pack a try at once.
Magik
śr., 9 sty 2019 o 21:55 Daniel. danielhilst@gmail.com napisał(a):
You are looking for `await`, if you use starter kit you have it already configured. With it you can "wait" for a promisse to complete,
Take a look here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements...
Em qua, 9 de jan de 2019 às 18:52, . magicznykrag@gmail.com escreveu:
Hello, First of all: thank you very much for maintaining this great project!
I'm C programmer learning now Cockpit. My problem is as follows: for some of the operation I must use external helper and I must wait for it output. The cockpit.spawn() function returns the promise, which is non-blocking operation (as expected). How can I make it work as blocking one? Which mean: the rest of the code in the function should be done after receiving full output of the cockpit.spawn (done() or fail())
best regards, Magik
cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste...
-- “If you're going to try, go all the way. Otherwise, don't even start. ..." Charles Bukowski _______________________________________________ cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste...
It's not required but is a big shortcut.. The newer browsers support async, you can try it without Babel, it's up to you
Em qua, 9 de jan de 2019 7:04 PM, . <magicznykrag@gmail.com escreveu:
Daniel,
Thank you very much for the answer! I was not using starter-pack, I've just started with creating direct on the server the manifest, html, css and js files. I'm not using npm at all. Is is required for Cockpit functionality? Of course I'll give starter-pack a try at once.
Magik
śr., 9 sty 2019 o 21:55 Daniel. danielhilst@gmail.com napisał(a):
You are looking for `await`, if you use starter kit you have it already configured. With it you can "wait" for a promisse to complete,
Take a look here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements...
Em qua, 9 de jan de 2019 às 18:52, . magicznykrag@gmail.com escreveu:
Hello, First of all: thank you very much for maintaining this great project!
I'm C programmer learning now Cockpit. My problem is as follows: for some of the operation I must use external helper and I must wait for it output. The cockpit.spawn() function returns the promise, which is non-blocking operation (as expected). How can I make it work as blocking one? Which mean: the rest of the code in the function should be done after receiving full output of the cockpit.spawn (done() or fail())
best regards, Magik
cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste...
-- “If you're going to try, go all the way. Otherwise, don't even start. ..." Charles Bukowski _______________________________________________ cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste...
cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste...
Daniel,
Thank you for your answer. Could you please provide me with the really short (few lines) example of practical use of cockpit.spawn() in blocking-like mode?
śr., 9 sty 2019 o 22:57 Daniel. danielhilst@gmail.com napisał(a):
It's not required but is a big shortcut.. The newer browsers support async, you can try it without Babel, it's up to you
Em qua, 9 de jan de 2019 7:04 PM, . <magicznykrag@gmail.com escreveu:
Daniel,
Thank you very much for the answer! I was not using starter-pack, I've just started with creating direct on the server the manifest, html, css and js files. I'm not using npm at all. Is is required for Cockpit functionality? Of course I'll give starter-pack a try at once.
Magik
śr., 9 sty 2019 o 21:55 Daniel. danielhilst@gmail.com napisał(a):
You are looking for `await`, if you use starter kit you have it already configured. With it you can "wait" for a promisse to complete,
Take a look here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements...
Em qua, 9 de jan de 2019 às 18:52, . magicznykrag@gmail.com escreveu:
Hello, First of all: thank you very much for maintaining this great project!
I'm C programmer learning now Cockpit. My problem is as follows: for some of the operation I must use external helper and I must wait for it output. The cockpit.spawn() function returns the promise, which is non-blocking operation (as expected). How can I make it work as blocking one? Which mean: the rest of the code in the function should be done after receiving full output of the cockpit.spawn (done() or fail())
best regards, Magik
cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste...
-- “If you're going to try, go all the way. Otherwise, don't even start. ..." Charles Bukowski _______________________________________________ cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste...
cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste...
cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste...
Note that for using it you need to enable it support on babel, welcome to modern javascript, these are the pieces of software that I recommend you to get familiar with it: Webpack and Babel.
Webpack will bundle all your javascript (css and other stuff) in a single bundle. Babel will let you to develop on newer versions of javascript that would not be available on old browsers, and it will transpile to old javascript
Em qua, 9 de jan de 2019 às 18:52, . magicznykrag@gmail.com escreveu:
Hello, First of all: thank you very much for maintaining this great project!
I'm C programmer learning now Cockpit. My problem is as follows: for some of the operation I must use external helper and I must wait for it output. The cockpit.spawn() function returns the promise, which is non-blocking operation (as expected). How can I make it work as blocking one? Which mean: the rest of the code in the function should be done after receiving full output of the cockpit.spawn (done() or fail())
best regards, Magik
cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste...
Daniel,
I see. Could you please provide me with the small code example for await?
Magik
śr., 9 sty 2019 o 22:00 Daniel. danielhilst@gmail.com napisał(a):
Note that for using it you need to enable it support on babel, welcome to modern javascript, these are the pieces of software that I recommend you to get familiar with it: Webpack and Babel.
Webpack will bundle all your javascript (css and other stuff) in a single bundle. Babel will let you to develop on newer versions of javascript that would not be available on old browsers, and it will transpile to old javascript
Em qua, 9 de jan de 2019 às 18:52, . magicznykrag@gmail.com escreveu:
Hello, First of all: thank you very much for maintaining this great project!
I'm C programmer learning now Cockpit. My problem is as follows: for some of the operation I must use external helper and I must wait for it output. The cockpit.spawn() function returns the promise, which is non-blocking operation (as expected). How can I make it work as blocking one? Which mean: the rest of the code in the function should be done after receiving full output of the cockpit.spawn (done() or fail())
best regards, Magik
cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste...
-- “If you're going to try, go all the way. Otherwise, don't even start. ..." Charles Bukowski _______________________________________________ cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste...
Hello Magik,
. [2019-01-09 21:51 +0100]:
I'm C programmer learning now Cockpit. My problem is as follows: for some of the operation I must use external helper and I must wait for it output. The cockpit.spawn() function returns the promise, which is non-blocking operation (as expected). How can I make it work as blocking one? Which mean: the rest of the code in the function should be done after receiving full output of the cockpit.spawn (done() or fail())
This is a common pitfal when coming from the world of synchronous programming languages (such as C or Python) and starting with asynchronous JavaScript. Daniel's await proposal can certainly help to make async code look like it was written in a sync style; but honestly, it's really best to let go of this pattern when writing JS.
So instead of
output = cockpit.spawn(..).make_this_magically_sync(); followup_action(output);
actually use JavaScript promises as they are intended:
cockpit.spawn(..) .then(output => { followup_action(output); }) .catch(err => { console.error(err); });
i. e. organize the stuff that depends on the result into promise handlers.
Martin
Martin,
Thank you very much for the answer! Unfortunately I'm still stuck :-( Please take a look at the following code and tell me why it's still asynchronous. It display properly messages: "testFunct" and then "end of testFunct", but it never reach the .then or .done. Thank you in advance!
function testFunc() { alert("testFunc"); lic = cockpit.spawn([ "/usr/share/cockpit/testSoftware/connectExternalSystem"], { directory: "/usr/share/cockpit/testSoftware", err: "message" }) .then(function() { alert("in .then of testFunc. Error: "+message); }) .done(function() { alert("in .done of testFunc. Error: "+message); }); alert("end of testFunc"); }
czw., 10 sty 2019 o 09:02 Martin Pitt martin@piware.de napisał(a):
Hello Magik,
. [2019-01-09 21:51 +0100]:
I'm C programmer learning now Cockpit. My problem is as follows: for some of the operation I must use external helper and I must wait for it
output.
The cockpit.spawn() function returns the promise, which is non-blocking operation (as expected). How can I make it work as blocking one? Which mean: the rest of the code in the function should be done after receiving full output of the cockpit.spawn (done() or fail())
This is a common pitfal when coming from the world of synchronous programming languages (such as C or Python) and starting with asynchronous JavaScript. Daniel's await proposal can certainly help to make async code look like it was written in a sync style; but honestly, it's really best to let go of this pattern when writing JS.
So instead of
output = cockpit.spawn(..).make_this_magically_sync(); followup_action(output);
actually use JavaScript promises as they are intended:
cockpit.spawn(..) .then(output => { followup_action(output); }) .catch(err => { console.error(err); });
i. e. organize the stuff that depends on the result into promise handlers.
Martin _______________________________________________ cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste...
What interesting: if I define .then just as: .then(alert("in .then")); then it works fine. But if i use the function() inside or the notation you've provided: .then(output => { alert(output); });
then system never reaches the .then. What I'm doing wrong?
pt., 11 sty 2019 o 20:44 . magicznykrag@gmail.com napisał(a):
Martin,
Thank you very much for the answer! Unfortunately I'm still stuck :-( Please take a look at the following code and tell me why it's still asynchronous. It display properly messages: "testFunct" and then "end of testFunct", but it never reach the .then or .done. Thank you in advance!
function testFunc() { alert("testFunc"); lic = cockpit.spawn([
"/usr/share/cockpit/testSoftware/connectExternalSystem"], { directory: "/usr/share/cockpit/testSoftware", err: "message" }) .then(function() { alert("in .then of testFunc. Error: "+message); }) .done(function() { alert("in .done of testFunc. Error: "+message); }); alert("end of testFunc"); }
czw., 10 sty 2019 o 09:02 Martin Pitt martin@piware.de napisał(a):
Hello Magik,
. [2019-01-09 21:51 +0100]:
I'm C programmer learning now Cockpit. My problem is as follows: for
some
of the operation I must use external helper and I must wait for it
output.
The cockpit.spawn() function returns the promise, which is non-blocking operation (as expected). How can I make it work as blocking one? Which mean: the rest of the code in the function should be done after
receiving
full output of the cockpit.spawn (done() or fail())
This is a common pitfal when coming from the world of synchronous programming languages (such as C or Python) and starting with asynchronous JavaScript. Daniel's await proposal can certainly help to make async code look like it was written in a sync style; but honestly, it's really best to let go of this pattern when writing JS.
So instead of
output = cockpit.spawn(..).make_this_magically_sync(); followup_action(output);
actually use JavaScript promises as they are intended:
cockpit.spawn(..) .then(output => { followup_action(output); }) .catch(err => { console.error(err); });
i. e. organize the stuff that depends on the result into promise handlers.
Martin _______________________________________________ cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste...
OK, problem solved.
pt., 11 sty 2019 o 21:18 . magicznykrag@gmail.com napisał(a):
What interesting: if I define .then just as: .then(alert("in .then")); then it works fine. But if i use the function() inside or the notation you've provided: .then(output => { alert(output); });
then system never reaches the .then. What I'm doing wrong?
pt., 11 sty 2019 o 20:44 . magicznykrag@gmail.com napisał(a):
Martin,
Thank you very much for the answer! Unfortunately I'm still stuck :-( Please take a look at the following code and tell me why it's still asynchronous. It display properly messages: "testFunct" and then "end of testFunct", but it never reach the .then or .done. Thank you in advance!
function testFunc() { alert("testFunc"); lic = cockpit.spawn([
"/usr/share/cockpit/testSoftware/connectExternalSystem"], { directory: "/usr/share/cockpit/testSoftware", err: "message" }) .then(function() { alert("in .then of testFunc. Error: "+message); }) .done(function() { alert("in .done of testFunc. Error: "+message); }); alert("end of testFunc"); }
czw., 10 sty 2019 o 09:02 Martin Pitt martin@piware.de napisał(a):
Hello Magik,
. [2019-01-09 21:51 +0100]:
I'm C programmer learning now Cockpit. My problem is as follows: for
some
of the operation I must use external helper and I must wait for it
output.
The cockpit.spawn() function returns the promise, which is non-blocking operation (as expected). How can I make it work as blocking one? Which mean: the rest of the code in the function should be done after
receiving
full output of the cockpit.spawn (done() or fail())
This is a common pitfal when coming from the world of synchronous programming languages (such as C or Python) and starting with asynchronous JavaScript. Daniel's await proposal can certainly help to make async code look like it was written in a sync style; but honestly, it's really best to let go of this pattern when writing JS.
So instead of
output = cockpit.spawn(..).make_this_magically_sync(); followup_action(output);
actually use JavaScript promises as they are intended:
cockpit.spawn(..) .then(output => { followup_action(output); }) .catch(err => { console.error(err); });
i. e. organize the stuff that depends on the result into promise handlers.
Martin _______________________________________________ cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste...
Hello Magic,
. [2019-01-11 20:44 +0100]:
Thank you very much for the answer! Unfortunately I'm still stuck :-( Please take a look at the following code and tell me why it's still asynchronous. It display properly messages: "testFunct" and then "end of testFunct", but it never reach the .then or .done.
Seems you eventually figured it out on your own, but FTR:
function testFunc() { alert("testFunc"); lic = cockpit.spawn([
"/usr/share/cockpit/testSoftware/connectExternalSystem"], { directory: "/usr/share/cockpit/testSoftware", err: "message" }) .then(function() { alert("in .then of testFunc. Error: "+message); })
Note that this only gets called if connectExternalSystem succeeds -- *message* is not defined here, so this can't work. What you want is
.then(output => alert("finished, output:", output)) .catch(error => alert("failed, error:", error);
.done(function() { alert("in .done of testFunc. Error: "+message); });
And this makes no ssense at all -- alert doesn't return a promise, to calling .done() on alert()'s result also doesn't work.
Martin
Martin, It was easier to me to take a look at sources of JS compiler and find in the implementation differences between "function()" and "function" - now everything is clear for me :-) Anyway - thank you for all explanations!
sob., 12 sty 2019 o 17:36 Martin Pitt martin@piware.de napisał(a):
Hello Magic,
. [2019-01-11 20:44 +0100]:
Thank you very much for the answer! Unfortunately I'm still stuck :-( Please take a look at the following code and tell me why it's still asynchronous. It display properly messages: "testFunct" and then "end of testFunct", but it never reach the .then or .done.
Seems you eventually figured it out on your own, but FTR:
function testFunc() { alert("testFunc"); lic = cockpit.spawn([
"/usr/share/cockpit/testSoftware/connectExternalSystem"], { directory: "/usr/share/cockpit/testSoftware", err: "message" }) .then(function() { alert("in .then of testFunc. Error: "+message); })
Note that this only gets called if connectExternalSystem succeeds -- *message* is not defined here, so this can't work. What you want is
.then(output => alert("finished, output:", output)) .catch(error => alert("failed, error:", error);
.done(function() { alert("in .done of testFunc. Error: "+message); });
And this makes no ssense at all -- alert doesn't return a promise, to calling .done() on alert()'s result also doesn't work.
Martin _______________________________________________ cockpit-devel mailing list -- cockpit-devel@lists.fedorahosted.org To unsubscribe send an email to cockpit-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/cockpit-devel@lists.fedorahoste...
cockpit-devel@lists.fedorahosted.org