What's the difference between run(...) & then(...)?
matthewmueller opened this issue · 1 comments
I'm a little bit confused about the examples:
run(func1, func2).then(func3, func4).thenChain(func5, func6).thenRun(func7);
Isn't this just:
run(func1, func2).run(func3, func4).run(func5).run(func6).run(func7);
Are these methods just semantic sugar or do they have significant differences?
Hey Matthew, as the README says:
then()
is an alias for the previous method in the chain- all methods have their own then alias - e.g.
run() === thenRun()
chain()
is shorter way of writingrun().then().then()
All of these are purely sugar and have a negligible overhead. When I made load.js, I thought the then() was more readable - just a matter of personal preference!
So yes, at the moment, the only 2 real unique methods are run()
and defer()
although I toyed with the idea of adding two more methods:
first(func1, func2, func3)
- progress along the chain once any function completes
all(func1, func2, func3)
- progress immediately after calling each function
I figured I'd let people make their own methods based on their needs.