Skip to content

Commit

Permalink
main
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpchen committed Feb 16, 2025
1 parent 1115dd9 commit 26f1447
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
4 changes: 2 additions & 2 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const vitepressConfig = defineConfig({
markdown: {
lineNumbers: true,
theme: {
light: await themeService.getTheme('Eva Light'),
light: await themeService.getTheme('JetBrains Rider New UI theme - Light'),
// dark: await themeService.getTheme('Eva Dark'),
dark: await themeService.getTheme('JetBrains Rider Dark Theme'),
dark: await themeService.getTheme('JetBrains Rider New UI theme - Dark'),
},
codeTransformers: [transformerTwoslash()],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,20 @@ To start a job there's multiple approaches to do the same:
_ = Task.Factory.StartNew(() => Console.WriteLine("hello"));
_ = Task.Run(() => Console.WriteLine("hello"));


fooAsync(); // started automatically
var fooAsync = async () =>
var fooAsync = async () =>
{
await Task.Run(() => Console.WriteLine("foo"));
}
};

fooAsync(); // started automatically
```

> [!NOTE]
> Continued tasks created by `ContinueWith` cannot `Start()`
### Create Task with Return

Generic tasks come into play when provided delegate would return a result.
Generic tasks come into play when provided with delegate would return a result.
The type parameter is exactly the type of return.

```cs
Expand All @@ -51,7 +50,8 @@ task.Start();

### Create with Argument

Both `TaskFactory` and `Task` supports an overload to accept **single argument** when the signature contains a parameter
Both `TaskFactory` and `Task` supports an overload to accept **single argument** when the signature contains a parameter.

Since only single value is supported, you may need an abstraction when to pass multiple values

```cs
Expand All @@ -67,6 +67,9 @@ task.Start();
> [!NOTE]
> `Task.Run` does not support overloads accept an argument
> [!TIP]
> One should prefer creating tasks supports arguments using `async` delegate unless you don't want it to begin immediately.
### Create from Async Delegate

`async` is a syntax sugar for creating task from a lambda or `async` method.
Expand Down Expand Up @@ -106,6 +109,7 @@ If one need to start a `async` delegate directly using `TaskFactory.StartNew`, `
That is because, `async` delegate is a factory for dedicated task, so the result for starting the delegate directly would be a task created from the delegate instead of the expected result.

```cs
// note: it's a wrapped task
Task<Task<int>> t = Task.Factory.StartNew(async () =>
{
await Task.Delay(1000);
Expand All @@ -129,8 +133,9 @@ Task<int> t2 = await Task.Factory.StartNew(async () =>
```

> [!TIP]
> `Task.Run` has a implicit auto-unwrap for some of its overloads
> `Task.Run` has a implicit auto-unwrap for some of its overloads, you may prefer this over `TaskFactory.StartNew` to start a simple task.
>```cs
>// The type is unwraped
>Task<int> t = Task.Run(async () =>
>{
> await Task.Delay(1000);
Expand Down
16 changes: 14 additions & 2 deletions docs/services/ThemeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ const themeInfos = {
path: 'themes/JetBrains Rider Dark Theme-color-theme.json',
branch: 'main',
},
'JetBrains Rider New UI theme - Dark': {
repo: 'digimezzo/vscode-jetbrains-rider-new-ui-theme',
path: 'themes/JetBrains Rider New UI-color-theme-dark.json',
brach: 'main',
},
'JetBrains Rider New UI theme - Light': {
repo: 'digimezzo/vscode-jetbrains-rider-new-ui-theme',
path: 'themes/JetBrains Rider New UI-color-theme-light.json',
brach: 'main',
},
} satisfies Record<string, RemoteThemeInfo>;

export type ThemeName = keyof typeof themeInfos;
Expand Down Expand Up @@ -73,9 +83,11 @@ class ThemeService implements IThemeService {
async initializeRegistration(): Promise<void> {
await Promise.all(
(Object.entries(themeInfos) as [ThemeName, RemoteThemeInfo][]).map(async x => {
const theme = await this.fetchThemeObject(x[1]);
const [themeName, info] = x;
const theme = await this.fetchThemeObject(info);
if (!theme.name) theme.name = themeName; // in case the theme does not have a name to indentify itself
await this.register(theme);
console.log(`Textmate theme: \`${x[0]}\` has loaded.`);
console.log(`Textmate theme: \`${themeName}\` has loaded.`);
}),
);
}
Expand Down

0 comments on commit 26f1447

Please sign in to comment.