Created
January 29, 2021 11:44
-
-
Save LironHazan/d58192051b3dfe01cdc1de847e371cfc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
async function fetchTables<E>(auth: any): Promise<Either<void, Promise<void>>> { | |
const sheets = google.sheets({ version: 'v4', auth }); | |
const authorised: Task<string> = async () => readFromFile('src/private/table_meta.json', 'utf-8'); | |
const authErr = () => console.log('error reading private/table_meta.json'); | |
const fetchTables = async (data: string) => { | |
const { tables, id } = JSON.parse(data); | |
const ft: (t: string) => Task<Promise<Either<Error, unknown>>> = (t: string) => task.of(fetchTable(sheets, t, id)); | |
const tasks: Task<string>[] = tables.map(ft); | |
const parallel = array.sequence(task.task)(tasks)(); | |
const _: any = await parallel; | |
pipe( | |
_, | |
either.fold( | |
(err) => console.log(err), | |
() => console.log('done!') | |
) | |
); | |
}; | |
return await pipe(tryCatch(authorised, authErr), map(fetchTables))(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment