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 -- [email protected]
To unsubscribe send an email to [email protected]
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/[email protected]

Reply via email to