Skip to content

Commit 9df8c72

Browse files
author
文左武右
committed
Compatible with API 10 and above versions
1 parent 3dbab15 commit 9df8c72

84 files changed

Lines changed: 6893 additions & 6024 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎LangChain/Output.ts‎

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
1-
class Tested {
2-
3-
public static getCorrectIndentLevel(lines: string[], lineIndex: number): string {
4-
if (lineIndex < 0 || lineIndex >= lines.length) {
5-
return "";
6-
}
7-
const currentLine = lines[lineIndex];
8-
if (lineIndex === 0) {
9-
return "";
10-
}
11-
const previousLine = lines[lineIndex - 1];
12-
if (!previousLine.isEmpty() && !previousLine.trim().endsWith(",")) {
13-
return this.getIndentation(previousLine);
14-
}
15-
if (previousLine.trim().startsWith("class ") || previousLine.trim().startsWith("def ") || previousLine.endsWith(":")) {
16-
return this.getIndentation(previousLine) + " ";
17-
}
18-
for (const line of lines) {
19-
if (line.length >= 8 && line.substring(0, 8).trim().isEmpty()) {
20-
return this.getIndentation(line);
21-
}
22-
}
23-
return "";
24-
}
1+
class WrongCounterDemo {
2+
private static readonly INC_COUNT = 100000000;
3+
private counter = 0;
254

26-
private static getIndentation(line: string): string {
27-
let index = 0;
28-
while (index < line.length && /\s/.test(line.charAt(index))) {
29-
index++;
30-
}
31-
return line.substring(0, index);
5+
public static async main() {
6+
const demo = new WrongCounterDemo();
7+
console.log("Start task thread!");
8+
const thread1 = new Promise<void>((resolve) => {
9+
const task = demo.getConcurrencyCheckTask();
10+
task().then(resolve);
11+
});
12+
const thread2 = new Promise<void>((resolve) => {
13+
const task = demo.getConcurrencyCheckTask();
14+
task().then(resolve);
15+
});
16+
await Promise.all([thread1, thread2]);
17+
const actualCounter = demo.counter;
18+
const expectedCount = WrongCounterDemo.INC_COUNT * 2;
19+
if (actualCounter !== expectedCount) {
20+
console.error(`Error! Got wrong count!! actual ${actualCounter}, expected: ${expectedCount}.`);
21+
} else {
22+
console.log("Wow... Got right count!");
3223
}
24+
}
25+
26+
getConcurrencyCheckTask() {
27+
return async () => {
28+
for (let i = 0; i < WrongCounterDemo.INC_COUNT; ++i) {
29+
++this.counter;
30+
}
31+
};
32+
}
33+
}
34+
35+
WrongCounterDemo.main();
36+
37+
if (isMainThread()) {
38+
// You can put the entry of your code here to test.
3339
}

0 commit comments

Comments
 (0)