Created
May 6, 2020 15:22
-
-
Save majo44/9428b297a192dbfa27e91b7580dbea1f 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 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