Skip to content

Commit

Permalink
release version 1.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
felixblaschke committed Feb 23, 2024
1 parent 88f3f0e commit 1c3b2b4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.8.0

- `shelfRun()` lifecycle hooks `onWillClose` and `onClosed` supports asynchronous execution
- Fixed: server does not stop, when hotreload is set to false

## 1.7.0

- Added `onWillClose` to `shelfRun()` lifecycle hook.
Expand Down
13 changes: 7 additions & 6 deletions lib/src/shelf_run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ typedef OnStarted = void Function(Object address, int port);
/// The type [e] represents the error or exception that occurred.
typedef OnStartFailed = void Function(Object e);

typedef OnWillClose = void Function();
typedef OnClosed = void Function();
typedef OnWillClose = FutureOr<void> Function();
typedef OnClosed = FutureOr<void> Function();

/// Mechanism to quickly run a shelf app.
///
Expand Down Expand Up @@ -69,14 +69,15 @@ Future<ShelfRunContext> shelfRun(
});
} else {
try {
await _createServer(
final server = await _createServer(
init,
defaultBindPort: defaultBindPort,
defaultBindAddress: defaultBindAddress,
defaultShared: defaultShared,
securityContext: securityContext,
onStarted: onStarted,
);
context._server = server;
} catch (e) {
catchDelegate(e);
}
Expand Down Expand Up @@ -121,9 +122,9 @@ class ShelfRunContext {

/// Stops the shelfRun
Future<void> close() async {
onWillClose?.call();
await _server?.close();
onClosed?.call();
await onWillClose?.call();
await _server?.close(force: true);
await onClosed?.call();
}

ShelfRunContext({this.onWillClose, this.onClosed});
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: shelf_plus
description: Shelf Plus is a quality of life addon for your server-side development within the Shelf platform.
version: 1.7.0
version: 1.8.0
repository: https://github.com/felixblaschke/shelf_plus

environment:
sdk: ">=2.17.0 <3.0.0"
sdk: ">=2.17.0 <4.0.0"

dependencies:
shelf: ^1.4.0
Expand Down
20 changes: 20 additions & 0 deletions test/shelf_run_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,26 @@ void main() {
await ctx.close();
}
});

test('Server stops when hotreload is disabled', () async {
init() => (Request request) => Response.ok('ok');

var context1 = await shelfRun(
init,
defaultBindAddress: '0.0.0.0',
defaultBindPort: 8085,
defaultEnableHotReload: false,
);
await context1.close();

var context2 = await shelfRun(
init,
defaultBindAddress: '0.0.0.0',
defaultBindPort: 8085,
defaultEnableHotReload: false,
);
await context2.close();
});
}

Handler isolateInit() =>
Expand Down

0 comments on commit 1c3b2b4

Please sign in to comment.