forked from erictik/midjourney-api
-
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.
Eric
committed
Apr 28, 2023
1 parent
75329de
commit 7c260ac
Showing
11 changed files
with
516 additions
and
75 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,2 +1,3 @@ | ||
export * from "./midjourney"; | ||
export * from "./midjourney.message"; | ||
export * from "./interfaces/index"; |
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 @@ | ||
export * from "./message"; |
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,27 @@ | ||
import async from "async"; | ||
type TaskFunction<T> = () => Promise<T>; | ||
export interface QueueTask<T> { | ||
task: TaskFunction<T>; | ||
callback?: (result: T) => void; | ||
} | ||
// const queue = async.queue(async ({ task, callback }: QueueTask<any>) => { | ||
// const result = await task(); | ||
// callback(result); | ||
// }, 10); | ||
|
||
// const task1: TaskFunction<number> = async () => { | ||
// // do some async work | ||
// return 42; | ||
// }; | ||
// queue.push({ | ||
// task: task1, | ||
// callback: (result: number) => { | ||
// console.log(result); // output: 42 | ||
// }, | ||
// }); | ||
export function CreateQueue<T>(concurrency: number) { | ||
return async.queue(async ({ task, callback }: QueueTask<any>) => { | ||
const result = await task(); | ||
callback && callback(result); | ||
}, concurrency); | ||
} |
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 const sleep = async (ms: number): Promise<void> => | ||
await new Promise((resolve) => setTimeout(resolve, ms)); | ||
|
||
export const random = (min: number, max: number): number => | ||
Math.floor(Math.random() * (max - min) + min); |
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,44 @@ | ||
type TaskFunction<T> = () => Promise<T>; | ||
|
||
interface QueueTask<T> { | ||
task: TaskFunction<T>; | ||
callback: (result: T) => void; | ||
} | ||
import async from "async"; | ||
|
||
const queue = async.queue(async ({ task, callback }: QueueTask<any>) => { | ||
const result = await task(); | ||
callback(result); | ||
}, 10); | ||
|
||
const task1: TaskFunction<number> = async () => { | ||
// do some async work | ||
return 42; | ||
}; | ||
|
||
queue.push({ | ||
task: task1, | ||
callback: (result: number) => { | ||
console.log(result); // output: 42 | ||
}, | ||
}); | ||
queue.push({ | ||
task: task1, | ||
callback: (result: number) => { | ||
console.log(result); // output: 42 | ||
}, | ||
}); | ||
|
||
queue.push({ | ||
task: task1, | ||
callback: (result: number) => { | ||
console.log(result); // output: 42 | ||
}, | ||
}); | ||
|
||
queue.push({ | ||
task: task1, | ||
callback: (result: number) => { | ||
console.log(result); // output: 42 | ||
}, | ||
}); |
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