flightplan icon indicating copy to clipboard operation
flightplan copied to clipboard

replace fibers with async/await

Open LeoDT opened this issue 3 years ago • 3 comments

what's done:

  1. upgrade node requirement to 12
  2. upgrade dependencies
  3. replace fibers with async/await
  4. replace util.inherits with class for the transports(removed some related tests)
  5. removed unable to load module error handler from bin.js, it is no longer thrown when requiring a ts file
  6. use nyc instead of istanbul
  7. tests seem OK
  8. small real-world tests seem OK

what's not done:

  • [x] use class in errors.js and transport/index.js
  • [x] more real-world tests(with private projects)
  • [x] docs

after this change, the old API will not work, we need to add await before every exec related function when defining the tasks, but this makes the flightplan.js file more like a normal js file, users can use async/await in the task defines which they can not do in the fibers version.

const plan = require('flightplan');

async function fetchSomthing() {
  return` Promise.resolve('remote hello');
}

plan.target('default', {
//...
});

plan.local(async (local) => {
  await local.echo('hello');
  await local.transfer('fileA', '~/');
});

plan.remote(async (remote) => {
  remote.log('log');

  await remote.with('cd ~/', async () => {
    await remote.mv('./fileA ./fileB');
  });

  const foo = await fetchSomething();
  await remote.echo(foo);
});

I'm not sure if this is good for everyone, but I'll submit this first and see what will come up.

LeoDT avatar Jan 13 '22 01:01 LeoDT

Thanks a lot for this effort! This looks really good so far. Would you be interested in keeping this project alive and well maintained after your rewrite?

pstadler avatar Jan 13 '22 07:01 pstadler

I don't have much experience in maintaining open source projects, if this is OK for you, maybe I can give it a try.

LeoDT avatar Jan 14 '22 00:01 LeoDT

@LeoDT thanks for updating this, we've been struggling with not being able to update to a recent Node.JS version.

For those that want to use it before merge:

npm install --save-dev "git://github.com/pstadler/flightplan.git#571fca5a465d4f7cd11ee258bb59d3cb594b0782"

Zwimber avatar May 08 '22 23:05 Zwimber