We welcome your contributions to this project.
It could be:
- a bug report in a GitHub issue
- a feature request in a GitHub issue
- a fix to documentation
- a code contribution to address an existing bug or feature request
| const magik = magikcraft.io; | |
| /* | |
| Fonts are bitmaps. | |
| Each number is the decimal equivalent of the binary | |
| bitmap of the line, for example: 00011000 = 24 | |
| Here is a bitmapped 'A': | |
| 00011000 = 24 | |
| 00111100 = 60 | |
| 00100100 = 36 |
| import { dispatch, spawn, query, Ref, start } from "nact"; | |
| type Result = { success: boolean }; | |
| type DoLoadMessage = { | |
| type: "LOAD"; | |
| filename: string; | |
| sender: Ref<Result>; | |
| }; |
| interface QueuedTask<T> { | |
| task: () => T; | |
| promise: { | |
| resolve: (res: any) => void; | |
| reject: (err: any) => void; | |
| }; | |
| } | |
| interface RateLimitedTask<T> { | |
| task: () => T; |
| interface QueuedTask<T> { | |
| task: () => T; | |
| promise: { | |
| resolve: (res: any) => void; | |
| reject: (err: any) => void; | |
| }; | |
| } | |
| interface RateLimitedTask<T> { | |
| task: () => T; |
We welcome your contributions to this project.
It could be:
.env file| async function executeAsyncTasks(tasks: AsyncTask<any>[]) { | |
| const success = async res => ({ success: await res }) // Promise<{success: res}> | |
| const error = async err => ({ error: await err }) // Promise<{error: e}> | |
| const runWithResult = task => task.run() | |
| .then(result => { | |
| success(result) | |
| task._success(result) | |
| }) | |
| .catch(e => { |
| class AsyncTask<T> { | |
| _run: () => Promise<T>; | |
| _success: (result: T) => void; | |
| _error: (e: Error) => void; | |
| constructor({ | |
| error, | |
| run, | |
| success | |
| }: { |
| // Takes an array of async tasks that may throw of shape {run: () => Promise<result>} | |
| // Returns Promise<{error: error[], success: result[]}> | |
| async function executeAsyncTasks(arrayOfAsyncTasks) { | |
| const success = async res => ({ success: await res }) // Promise<{success: res}> | |
| const error = async err => ({ error: await err }) // Promise<{error: e}> | |
| const runWithResult = task => task.run().then(success).catch(error) | |
| const outcomes = await Promise.all(arrayOfAsyncTasks.map(runWithResult)) |
| const { error, success } = outcomes.reduce((acc, o) => o.error ? | |
| { error: [...acc.error, o.error], success: acc.success } : | |
| { error: acc.error, success: [...acc.success, o.success] }, | |
| { error: [], success: [] }) |