Skip to content

When should context.bind be used? #2736

Answered by vmarchaud
airhorns asked this question in Q&A
Discussion options

You must be logged in to vote

context.bind is similar to function.bind, it's used to manually set the opentelemetry context (where as the function.bind is used to set the this context) that will be used within the function that are you calling. It also handle binding to event emitters where the given context will be the one used for every .emit.
Also context.bind allows not to set a specific context in which case the current context will be manually set.
I would say that you generally don't need to do this because with newer nodejs version there is not much context loss left (which case the case before), async hooks/async local storage now generaly handle this for you.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by airhorns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants