Skip to content

Instantly share code, notes, and snippets.

@majo44
Created May 6, 2020 15:22
Show Gist options
  • Save majo44/9428b297a192dbfa27e91b7580dbea1f to your computer and use it in GitHub Desktop.
Save majo44/9428b297a192dbfa27e91b7580dbea1f to your computer and use it in GitHub Desktop.
export class CorrelationId {
private _nextChildId = 0;
constructor(public readonly origin: string) {}
nextLevel(): CorrelationId {
const next = this.clone(this.toString());
this._nextChildId++;
return next;
}
protected clone(newCorrelationId: string): CorrelationId {
return new CorrelationId(newCorrelationId);
}
toString(): string {
return this.origin + '.' + this._nextChildId
}
}
const getCId = (rq) => rq.correlationId;
const getNestedCId = (rq) => rq.correlationId.nextLevel();
const m1 = (cId, rq) => {
console.log(cId.toString());
}
const m2 = (cId, rq) => {
console.log(cId.toString());
m1(getNestedCId(rq), rq);
}
const m3 = (cId, rq) => {
console.log(cId.toString());
}
const m4 = (cId, rq) => {
console.log(cId.toString());
m2(getNestedCId(rq), rq);
}
const request = {
correlationId: new CorrelationId('x')
}
m4(getCId(request), request);
m3(getCId(request), request);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment