-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Connecting DTD and DTD_impl together.
This change adds the happy path for DTD_impl and DTD being able to: - register streams - register serviceMethods - postEvents to streams - call serviceMethods Change-Id: I73865071745ef19a4493f86714e0855930243dd5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341700 Reviewed-by: Ben Konyi <[email protected]> Reviewed-by: Kenzie Davisson <[email protected]> Commit-Queue: Dan Chevalier <[email protected]>
- Loading branch information
Dan Chevalier
authored and
Commit Queue
committed
Dec 19, 2023
1 parent
08e3d3e
commit e58efcb
Showing
17 changed files
with
821 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ linter: | |
rules: | ||
- avoid_void_async | ||
- unawaited_futures | ||
- require_trailing_commas |
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,68 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:dtd/dtd.dart'; | ||
|
||
//Extension side | ||
class Bar extends DTDResponse { | ||
late String baz; | ||
late int bazCount; | ||
late String bazDescription; | ||
|
||
// ignore: use_super_parameters | ||
Bar.fromDTDResponse(DTDResponse response) : super.fromDTDResponse(response) { | ||
baz = result['baz'] as String; | ||
bazCount = result['bazCount'] as int; | ||
bazDescription = result['bazDescription'] as String; | ||
} | ||
|
||
@override | ||
String toString() { | ||
return 'Bar(baz:$baz, bazCount:$bazCount, bazDescription:$bazDescription)'; | ||
} | ||
} | ||
|
||
extension FooServiceExtension on DTDConnection { | ||
Future<Bar> barExtension() async { | ||
final result = await call( | ||
'Foo', | ||
'bar', | ||
params: { | ||
'baz': 'the baz', | ||
'bazCount': 1, | ||
'bazDescription': 'there is one baz', | ||
}, | ||
); | ||
return Bar.fromDTDResponse(result); | ||
} | ||
} | ||
|
||
void main(List<String> args) async { | ||
final url = args[0]; // pass the url as a param to the example | ||
final fooService = await DartToolingDaemon.connect(Uri.parse('ws://$url')); | ||
final client = await DartToolingDaemon.connect(Uri.parse('ws://$url')); | ||
|
||
await fooService.registerService( | ||
'Foo', | ||
'bar', | ||
(params) async { | ||
final baz = params['baz'].value; | ||
final bazCount = params['bazCount'].value; | ||
final bazDescription = params['bazDescription'].value; | ||
final result = { | ||
'type': 'Bar', | ||
'baz': baz, | ||
'bazCount': bazCount, | ||
'bazDescription': bazDescription, | ||
}; | ||
return result; | ||
}, | ||
); | ||
final response = await client.barExtension(); | ||
final bar = Bar.fromDTDResponse(response); | ||
|
||
print('Got a bar response: $bar'); | ||
} |
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,28 @@ | ||
import 'package:dtd/dtd.dart'; | ||
|
||
void main(List<String> args) async { | ||
final url = args[0]; // pass the url as a param to the example | ||
final clientA = await DartToolingDaemon.connect(Uri.parse('ws://$url')); | ||
final clientB = await DartToolingDaemon.connect(Uri.parse('ws://$url')); | ||
|
||
clientA.onEvent('Foo').listen((event) { | ||
print('A Received $event from Foo Stream'); | ||
}); | ||
clientB.onEvent('Foo').listen((event) { | ||
print('B Received $event from Foo Stream'); | ||
}); | ||
|
||
await clientA.streamListen('Foo'); | ||
await clientB.streamListen('Foo'); | ||
|
||
clientA.postEvent('Foo', 'kind1', {'event': 1}); | ||
|
||
clientB.postEvent('Foo', 'kind2', {'event': 2}); | ||
|
||
// delayed so the Daemon connection is still up by the time the events come | ||
// back. | ||
await Future<void>.delayed(const Duration(seconds: 10)); | ||
|
||
await clientA.close(); | ||
await clientB.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
Oops, something went wrong.