From f3f0c5d4b34921a35a502010b6acc91c56a04b94 Mon Sep 17 00:00:00 2001 From: Rafa Mel Date: Wed, 17 Feb 2021 13:57:43 +0100 Subject: [PATCH] feat(tasks): adds raises task --- src/tasks/create/index.ts | 1 + src/tasks/create/raises.ts | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 src/tasks/create/raises.ts diff --git a/src/tasks/create/index.ts b/src/tasks/create/index.ts index 9afb1c4..49939b9 100644 --- a/src/tasks/create/index.ts +++ b/src/tasks/create/index.ts @@ -2,4 +2,5 @@ export * from './clear'; export * from './exec'; export * from './log'; export * from './print'; +export * from './raises'; export * from './sleep'; diff --git a/src/tasks/create/raises.ts b/src/tasks/create/raises.ts new file mode 100644 index 0000000..31f2b96 --- /dev/null +++ b/src/tasks/create/raises.ts @@ -0,0 +1,8 @@ +import { Task, Context } from '../../definitions'; +import { UnaryFn } from 'type-core'; + +export function raises(error: Error | UnaryFn): Task.Sync { + return (ctx: Context): void => { + throw typeof error === 'function' ? error(ctx) : error; + }; +}