socket.io-client-dart icon indicating copy to clipboard operation
socket.io-client-dart copied to clipboard

Can't emit from isolate function

Open BEARlogin opened this issue 5 years ago • 1 comments

Hi! I tried to send message from isolate function. But it's not work. Is it possible? Test code:

import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:socket_io_client/socket_io_client.dart' as IO;

final IO.Socket socket = IO.io('http://192.168.0.68:3000', <String, dynamic>{
  'transports': ['websocket']
});

void readFileIsolate(String filePath) async {
  print('isolate!');
  socket.emit('test', {'test': "1133"});
}

class TestSocket extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    compute(readFileIsolate, '');
    socket.on('repeat', (data) {
      print('repeat');
      print(data);
    });
    return Container();
  }
}

BEARlogin avatar May 25 '20 13:05 BEARlogin

i think i have the same issue, when i send big data over my websocket it hangs my entire app... it should still allow other actions to occur :( I'm trying an isolation method which seems to be similar to your demo here. I just wrap the emit function in a top-level function then provide that function to the isolate thingy.

I am using this to do that for me https://pub.dev/packages/isolate_handler

moeiscool avatar Jul 04 '20 18:07 moeiscool