I am very confuse about dart editor, how it works. When i run this application
import 'dart:isolate';
import 'package:dbcrypt/dbcrypt.dart';
import 'dart:async';
main() {
//ReceivePort receivePort = new ReceivePort();
var receivePortPw = new ReceivePort();
receivePortPw.listen((msg) {
print(msg);
});
Future<Isolate> f = Isolate.spawn(ReturnHashedPassword, receivePortPw.sendPort);
f.then((Isolate i) {
print('Print1 -> ' + new DBCrypt().hashpw('Password', new DBCrypt().gensalt()));
print('Print2 -> ' + new DBCrypt().hashpw('Password', new DBCrypt().gensalt()));
});
}
void ReturnHashedPassword(SendPort sendPort)
{
print('ok');
ReceivePort receivePort = new ReceivePort();
sendPort.send('Isolate -> ' + new DBCrypt().hashpw('Password', new DBCrypt().gensalt()));
print('done');
}
the editor looks after, it is still running. Look at following printscreen, the terminate button(red square button) is not disable, it remember me, when i run a http server, this button is not gonna disable, until i manually do it.
Why the terminate button is not gonna disable here after output? It is only I/O application, it is not a webserver.
You are listening running isolate. You can close it's port or simply kill it:
import 'dart:isolate';
import 'package:dbcrypt/dbcrypt.dart';
import 'dart:async';
main() {
//ReceivePort receivePort = new ReceivePort();
var receivePortPw = new ReceivePort();
receivePortPw.listen((msg) {
print(msg);
receivePortPw.close();//stop listening.
});
Future<Isolate> f = Isolate.spawn(ReturnHashedPassword, receivePortPw.sendPort);
f.then((Isolate i) {
print('Print1 -> ' + new DBCrypt().hashpw('Password', new DBCrypt().gensalt()));
print('Print2 -> ' + new DBCrypt().hashpw('Password', new DBCrypt().gensalt()));
//i.kill(); // not nice...
});
}
void ReturnHashedPassword(SendPort sendPort)
{
print('ok');
ReceivePort receivePort = new ReceivePort();
sendPort.send('Isolate -> ' + new DBCrypt().hashpw('Password', new DBCrypt().gensalt()));
print('done');
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.