Skip to content

Commit 5e297fc

Browse files
committed
TestIsolate
1 parent 0a880ed commit 5e297fc

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

pkgs/cupertino_http/lib/src/cupertino_web_socket.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'dart:async';
66
import 'dart:convert';
7+
import 'dart:isolate';
78
import 'dart:typed_data';
89

910
import 'package:objective_c/objective_c.dart' as objc;
@@ -277,7 +278,7 @@ class CupertinoWebSocket implements WebSocket {
277278
print('${DateTime.now().millisecondsSinceEpoch / 1000.0} '
278279
'cancelWithCloseCode($code, $reason) '
279280
'${_task.state} ${_task.error}');
280-
_task.cancelWithCloseCode(code, utf8.encode(reason).toNSData());
281+
await _cancel(_task, code, utf8.encode(reason!).toNSData());
281282
await Future<void>.delayed(const Duration(seconds: 5));
282283
// Delay is 10 seconds!
283284
print('${DateTime.now().millisecondsSinceEpoch / 1000.0} Task: $_task');
@@ -293,3 +294,7 @@ class CupertinoWebSocket implements WebSocket {
293294
@override
294295
String get protocol => _protocol;
295296
}
297+
298+
Future<void> _cancel(
299+
URLSessionWebSocketTask task, int code, objc.NSData reason) =>
300+
Isolate.run(() => task.cancelWithCloseCode(code, reason));

pkgs/web_socket_conformance_tests/lib/src/close_local_tests.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'dart:isolate';
65
import 'dart:typed_data';
76

87
import 'package:async/async.dart';
@@ -136,7 +135,7 @@ void testCloseLocal(
136135
..sendText('Hello World')
137136
..sendText('Hello World 2')
138137
..sendText('Hello World 3');
139-
await Isolate.run(() => channel.close(3000, 'Client initiated closure'));
138+
await channel.close(3000, 'Client initiated closure');
140139
final closeCode = await httpServerQueue.next as int?;
141140
final closeReason = await httpServerQueue.next as String?;
142141

0 commit comments

Comments
 (0)