Created
May 6, 2020 15:22
-
-
Save majo44/a230565e5e06736317e05cde7c521f11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 request = { | |
correlationId: new CorrelationId('x') | |
} | |
m2(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