skonves / express-http-context

Get and set request-scoped context anywhere
MIT License
300 stars 26 forks source link

QA: is there any special meaning for value of nsid? #27

Closed isayme closed 5 years ago

isayme commented 5 years ago
const nsid = 'a6a29a6f-6747-4b5f-b99f-07ee96e32f88';

If we want a unique name for namespace, I would prefer a Symbol.

skonves commented 5 years ago

nsid is just an random, opaque value used to create a namespace. The underlying library cls-hooked uses a string to create a namespace. I'm not sure what would happen if you passed a symbol. In any case, this library aims to abstract the internal cls-hooked machinery. If you need more control over namespace IDs and such, you might want to consider consuming cls-hooked directly.

Note that for other libraries that need access to the cls-hooked namespace, it is available by doing:

var httpContext = require('express-http-context');
var namespace = httpContext.ns;
isayme commented 5 years ago

@skonves Thanks for your reply~

cls-hooked internal use a object to keep the name, a Symbol as name is ok. And if we use Symbol, no one will overwrite the namespace nsid by accident.

However, the random, opaque value is safe enough.