Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Node#hierarchy method for flexible accounting. #55

Closed
wants to merge 2 commits into from

Conversation

havenwood
Copy link
Member

This PR adds a Node#hierarchy for more flexibility with outputting hierarchy. I switched over Node#print_hierarchy to use the new method internally.

My hope was to make Node hierarchy discoverable via a mechanism other than printing.

For an example, here's a typical #print_hierarchy output.

#<Async::Node:0x000118>
	#<Async::Node:0x000078>
		#<Async::Node:0x0000a0>
			#<Async::Node:0x0000c8>
	#<Async::Node:0x0000f0>

And the corresponding current #hierarchy return value.

[{:level=>0, :node=>#<Async::Node:0x000118>},
 {:level=>1, :node=>#<Async::Node:0x000078>},
 {:level=>2, :node=>#<Async::Node:0x0000a0>},
 {:level=>3, :node=>#<Async::Node:0x0000c8>},
 {:level=>1, :node=>#<Async::Node:0x0000f0>}]

@coveralls
Copy link

Coverage Status

Coverage increased (+3.8%) to 89.574% when pulling d1f534e on havenwood:hierarchy into ce8bc07 on socketry:master.

@ioquatix
Copy link
Member

ioquatix commented Jun 6, 2021

Do you mind explaining the expected use case? Because we have traverse which is very close to the implementation.

@havenwood
Copy link
Member Author

Do you mind explaining the expected use case? Because we have traverse which is very close to the implementation.

If I recall, I was using #traverse to return a collection of nodes, like .traverse.map { |node, value| would but got a LocalJumpError. In retrospect, I think I should have proposed an return enum_for(__method__) { size } unless block_given? form for #traverse rather than a new method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants