Skip to content

Instantly share code, notes, and snippets.

@LironHazan
Created January 29, 2021 11:44
Show Gist options
  • Save LironHazan/d58192051b3dfe01cdc1de847e371cfc to your computer and use it in GitHub Desktop.
Save LironHazan/d58192051b3dfe01cdc1de847e371cfc to your computer and use it in GitHub Desktop.
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