2.0.0 • Published 7 years ago

task-run v2.0.0

Weekly downloads
4
License
MIT
Repository
-
Last release
7 years ago

task-run

Task runner, written in typescript. Task implements the task-api

Install

npm install task-run

Amd and systemjs bundles included.

Usage

You can check the test file for all the examples.

let task = Tasks.run(() => { return 3; });
assert.equal(await task, 3);
let task = Tasks.run(() => { return "Hi"; });
await task.end;

assert.equal(task.status, Status.Succeded);
let task = Tasks.run<number>(() => { throw "Some error"; });

assert.throws(async () => await task);
let task = Tasks.run(() => { throw "Some error"; });
await task.end;

assert.equal(task.status, Status.Failed);
let source = new CancelTokenSource();
source.cancel();

let task = Tasks.runCancelable((token) => { token.throwIfCancelRequested(); }, source.token);
await task.end;

assert.equal(task.status, Status.Cancelled);
let task = Tasks.succeded(4);
assert.equal(await task, 4);
let task = Tasks.failed("The reason is you.");
assert.throws(async () => await task, "The reason is you.");
let task = Tasks.cancelled();
assert.throws(async () => await task);
assert.equal(task.status, Status.Cancelled);
let controller = Tasks.createController<string>();
controller.setSucceded("Hi");

assert.equal(await controller.task, "Hi");
let controller = Tasks.createController<number>();
controller.setFailed("some reason");

assert.throws(async () => await controller.task, "some reason");
let controller = Tasks.createController<number>();
controller.setCancelled();

assert.equal(controller.task.status, Status.Cancelled);
2.0.0

7 years ago

1.4.6

8 years ago

1.4.5

8 years ago

1.4.4

8 years ago

1.4.3

8 years ago

1.4.2

8 years ago

1.4.1

8 years ago

1.4.0

8 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.6

8 years ago

1.2.5

8 years ago

1.2.4

8 years ago

1.2.3

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago