Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Converted runner.ts to use Promises #2438

Closed
wants to merge 2 commits into from
Closed

Converted runner.ts to use Promises #2438

wants to merge 2 commits into from

Conversation

JoshuaKGoldberg
Copy link
Contributor

Moves all of run's logic to a runAsPromise that uses async/await.

This uses the mz package. I'm curious on your opinions on this: should TSLint do work to wrap the fs APIs in Promises, or take on the package as a dependency?

Starts on #2328.

Josh Goldberg added 2 commits March 29, 2017 15:50
Moves all of `run`'s logic to a `runAsync` that uses async/await.

This uses the `mz` package. I'm curious on your opinions on this: should
TSLint do work to wrap the `fs` APIs in Promises, or take on the package
as a dependency?

Starts on #2328.
@andy-hanson
Copy link
Contributor

andy-hanson commented Mar 31, 2017

  • A class with a single method invoked immediately after construction is a code smell. I don't think Runner is meant to be public (What's public? #2446). You could just use a function run returning a Promise.
  • status could be a const enum.

@ajafff
Copy link
Contributor

ajafff commented Apr 4, 2017

I don't think Runner is meant to be public

IIRC @JoshuaKGoldberg was the one who exported it, hence I guess it is used in the wild.

I don't really see a benefit in just using Promises but then awaiting them all of the time. As it is now there will only be overhead with nothing gained.
IMO it would make more sense to run async fs functions in parallel no matter if callback style or promisified.

@JoshuaKGoldberg
Copy link
Contributor Author

code smell

Interesting. How would you prefer the runner logic be written?

public
2446

The idea behind separating out Runner from the cli logic was that external users might want to be able to use it instead of spinning up a whole Node sub-process. I specifically wanted to experiment with https://github.com/automutate/autotslint. I don't think anybody else uses it, so if it's not (yet/ever) part of the public contract I'm fine with changing run.

status could be a const enum.

Agreed! #2182 - since nobody's responded, I think I can send a quick separate PR for this soon.

overhead

Even as a prerequisite for #2328?

@andy-hanson
Copy link
Contributor

How would you prefer the runner logic be written?

I wasn't commenting on the way it was implemented but on the way it is exposed. You wouldn't do e.g. new Adder(1, 2).add(), so why have new Runner().run()?
In terms of implementation, just unindent everything, move the constructor parameters to run, and replace public with export function and private with function (adding explicit parameters for the members of this that were used there).

@JoshuaKGoldberg
Copy link
Contributor Author

I'm not sure I agree with the idea of using plain functions over a class for the runner logic. Right now it has two objects that are used, options and outputStream, which would have to be passed to (nearly) every function. That itself feels like code smell. What do we do when there are other hooks added, such as performance tracking or a file I/O interface? I see three roads there:

  1. Pass a whole bunch of objects around to each function
  2. Create a "dependencies" object and pass it to each function
  3. Use a class

Is option 1 maintainable? Option 2 is made simpler by using 3 instead.

@andy-hanson
Copy link
Contributor

andy-hanson commented Apr 14, 2017

If you find that everything in your program needs to have access to everything else, the solution isn't to put it all in one class! It can be broken down into simple components that don't all need to access each other. See #2572.

@JoshuaKGoldberg
Copy link
Contributor Author

Sure. I'd love to discuss this further but your PR looks better :)

@andy-hanson
Copy link
Contributor

Thanks!
But, mine doesn't use Promises, so you might want to leave this open...

@JoshuaKGoldberg
Copy link
Contributor Author

I'll send a new PR when yours is in.

@JoshuaKGoldberg JoshuaKGoldberg deleted the async-runner branch April 14, 2017 02:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants