-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix #21 * Fix #29 * updated changelog * async main needs to return Future<void> Co-authored-by: István Soós <isoos@users.noreply.github.com>
- Loading branch information
1 parent
edb8bcb
commit fe95433
Showing
7 changed files
with
69 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
import 'package:cron/cron.dart'; | ||
|
||
Future<void> main() async { | ||
final cron = Cron() | ||
..schedule(Schedule.parse('*/6 * * * * *'), () { | ||
final cron = Cron(); | ||
|
||
try { | ||
cron.schedule(Schedule.parse('*/6 * * * * *'), () { | ||
print(DateTime.now()); | ||
}); | ||
await Future.delayed(Duration(seconds: 20)); | ||
await cron.close(); | ||
|
||
await Future.delayed(Duration(seconds: 20)); | ||
await cron.close(); | ||
} on ScheduleParseException { | ||
// "ScheduleParseException" is thrown if cron parsing is failed. | ||
await cron.close(); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) 2022, Agilord. All rights reserved. Use of this source code | ||
// is governed by a BSD-style license that can be found in the LICENSE file. | ||
|
||
/// Exception thrown when a cron data does not have an expected | ||
/// format and cannot be parsed or processed. | ||
class ScheduleParseException extends FormatException { | ||
/// Creates a new `FormatException` with an optional error [message]. | ||
ScheduleParseException([String message = '']) : super(message); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:cron/src/schedule_parse_exception.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
test('Test throw without message', () { | ||
try { | ||
throw ScheduleParseException(); | ||
} catch (error) { | ||
expect(error is ScheduleParseException, isTrue); | ||
expect(error is FormatException, isTrue); | ||
expect(error is Exception, isTrue); | ||
} | ||
}); | ||
|
||
test('Test throw with message', () { | ||
try { | ||
throw ScheduleParseException('parse failed'); | ||
} catch (error) { | ||
expect(error.toString(), 'FormatException: parse failed'); | ||
expect(error is ScheduleParseException, isTrue); | ||
expect(error is FormatException, isTrue); | ||
expect(error is Exception, isTrue); | ||
} | ||
}); | ||
} |