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

@fangxq/async-context

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fangxq/async-context - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

3

index.d.ts

@@ -8,4 +8,5 @@ export const asyncContext: {

clearAll(): void
use<T>(token: string, fn: () => Promise<T>): Promise<T>
useAsync<T>(token: string, fn: () => Promise<T>): Promise<T>
useSync<T>(token: string, fn: () => T): T
getCurrentContext(): string
}

@@ -37,3 +37,3 @@ const cloneDeep = require('lodash').cloneDeep

function getPrivateValues() {
const token = store.getStore()
const token = store.getStore() ?? syncToken
if (!self.privateValues[token]) {

@@ -59,5 +59,7 @@ self.privateValues[token] = cloneDeep(self.defaultPrivateValues)

let syncToken = ''
module.exports.asyncContext = {
definePrivate(path, proName, defaultValue) {
if(!dataContext[path]) dataContext[path] = new contextObject()
if (!dataContext[path]) dataContext[path] = new contextObject()

@@ -67,3 +69,3 @@ dataContext[path].definePrivateValue(proName, defaultValue)

definePublic(path, proName, defaultValue) {
if(!dataContext[path]) dataContext[path] = new contextObject()
if (!dataContext[path]) dataContext[path] = new contextObject()

@@ -88,3 +90,3 @@ dataContext[path].definePublicValue(proName, defaultValue)

},
use(token, fn) {
useAsync(token, fn) {
return new Promise((resolve, reject) => {

@@ -100,5 +102,13 @@ store.run(token, async () => {

},
useSync(token, fn) {
try {
syncToken = token
return fn()
} finally {
syncToken = ''
}
},
getCurrentContext() {
return store.getStore()
return store.getStore() ?? syncToken
}
}
{
"name": "@fangxq/async-context",
"version": "0.0.4",
"version": "0.0.5",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

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