-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c543715
commit 34e2403
Showing
16 changed files
with
125 additions
and
37 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Signal } from '@preact/signals-core'; | ||
import { injectable } from 'inversify'; | ||
import { ITask, ITaskManager, ITaskStatus } from 'ipmc-interfaces'; | ||
import { uuid } from '../util'; | ||
|
||
@injectable() | ||
export class TaskManager implements ITaskManager { | ||
public status: Signal<ITaskStatus[]> = new Signal<ITaskStatus[]>([]); | ||
|
||
public runTask(task: ITask): void { | ||
const status: ITaskStatus = { | ||
id: uuid(), | ||
title: task.title, | ||
}; | ||
this.status.value = [...this.status.value, status]; | ||
task.task() | ||
.finally(() => { | ||
this.status.value = this.status.value.filter(s => s.id !== status.id); | ||
}); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
<<<<<<< HEAD | ||
export { createFilter } from './createFilter'; | ||
======= | ||
export { createRemoteIpfs } from './createRemoteIpfs'; | ||
>>>>>>> b91302fed0641a56d3300fbe3e23c06e5913baf1 | ||
export { uuid } from './uuid'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function uuid() { | ||
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c => | ||
(+c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16) | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* A long running task. | ||
*/ | ||
export interface ITask { | ||
title: string; | ||
|
||
/** | ||
* The task to run. | ||
*/ | ||
task: () => Promise<void>; | ||
|
||
/** | ||
* Start event handler. | ||
*/ | ||
onStart?: () => void | Promise<void>; | ||
|
||
/** | ||
* End event handler. | ||
*/ | ||
onEnd?: () => void | Promise<void>; | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/interfaces/src/Services/ITaskManager/ITaskManager.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ITask } from './ITask'; | ||
import { ITaskStatus } from './ITaskStatus'; | ||
import { Signal } from '@preact/signals-core'; | ||
|
||
export const ITaskManagerSymbol = Symbol.for('ITaskManager'); | ||
|
||
/** | ||
* A Manager for long running {@link ITask}'s. | ||
*/ | ||
export interface ITaskManager { | ||
/** | ||
* Instantly runs a long running {@link ITask}. | ||
* @param task Task to execute. | ||
*/ | ||
runTask(task: ITask): void; | ||
|
||
/** | ||
* Current status of running {@link ITask}'s. | ||
*/ | ||
status: Signal<ITaskStatus[]>; | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/interfaces/src/Services/ITaskManager/ITaskStatus.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Represents the status of an {@link ITask} | ||
*/ | ||
export interface ITaskStatus { | ||
/** | ||
* Progress of the {@link ITask} (if available). | ||
*/ | ||
progress?: number; | ||
|
||
/** | ||
* Title of the {@link ITask}. | ||
*/ | ||
title: string; | ||
|
||
/** | ||
* Id of the {@link ITask}. | ||
*/ | ||
id: string; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { type ITask } from './ITask'; | ||
export { type ITaskManager, ITaskManagerSymbol } from './ITaskManager'; | ||
export { type ITaskStatus } from './ITaskStatus'; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export * from './MetaData'; | ||
export * from './Profile'; | ||
export * from './Services'; | ||
export type { ITask } from './ITask'; |
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
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
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
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