Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wry/context

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wry/context

Manage contextual information needed by (a)synchronous tasks without explicitly passing objects around

  • 0.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.6M
decreased by-2.45%
Maintainers
1
Weekly downloads
 
Created

What is @wry/context?

The @wry/context npm package provides a mechanism for managing contextual information across asynchronous operations without relying on global state or directly passing context through function calls. It's particularly useful for tracking execution contexts across async boundaries, making it easier to implement features like request-scoped logging, performance monitoring, and more in a way that's transparent to the code that's being executed.

What are @wry/context's main functionalities?

Creating and using a context

This feature demonstrates how to create a new context and use it to store and retrieve values within a specific execution scope. The `withValue` method temporarily sets a value for a given key in the context, which can be accessed using the `get` method within the callback passed to `withValue`. Outside of this callback, the context does not hold the value, showcasing how @wry/context can manage context-specific data without leaking it outside of the intended scope.

const {Slot} = require('@wry/context');
let context = new Slot();
context.withValue('myKey', 'myValue', () => {
  // Within this function, context.get('myKey') will return 'myValue'.
  console.log(context.get('myKey')); // Outputs: 'myValue'
});
// Outside, context.get('myKey') returns undefined.
console.log(context.get('myKey')); // Outputs: undefined

Other packages similar to @wry/context

FAQs

Package last updated on 12 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc