Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Alternative to #646
This PR adds a generic builder system:
The builder will read the setupprocs of the various input type, and try to create the string from it. In this case:
float
is required to createint
, andint
will output astring
float
&string
doesn't require anythingwith
). And finally, output the stringI really like this system, because the ordering is done automatically depending on the arguments of
setup
, and it's fully generic.Applied to the switch:
This is very similar to #646, except that we don't have to order the
with
s. Also, it can be used on any type (rng for instance)The setup is however quite different:
The most basic kind of setup (beside no-ops), we have a dependency on
PeerStore
, so we'll be setup once PeerStore is available. And we can then do whatever we want with itHere,
var
is used to signal that we will modifymuxers
, so anysetup
dependent onTable[string, MuxerProvider]
shouldn't be called before us.Lot of dependencies for the switch, but this should be straightforward to understand.
The builder system itself could be moved to another package, since it's completely standalone.
More details on how it works:
context
, which is a type -> value table, similar to how Peer store refacto #700 works. For instance,context[Switch] = Switch.new()
setupproc
will read the parameters, and build a structure from the parameters, example:will become
with
will collect everyBuildDep
. Whenbuild
is called, we try to build everything if the dependency graph is not cyclic.This is a rough PoC, please don't look too much at builder3.nim or your retina may burn
However, I find the API quite nice: if you have a dep, just take it as a parameter, and everything work automagically. This system can be improved upon in a few powerful way, for instance default values:
Multiple parameters to build:
And probably other fun stuff.
Also note that the
setup
procedure is usable without the entire system:And that you can build anything with the system, for instance in tests:
which will become even more powerful with default values (you could build anything without worrying about it's deps)