为什么dart编辑器仍在运行 [英] Why dart editor is still running

查看:198
本文介绍了为什么dart编辑器仍在运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑dart编辑器,它如何工作。当我运行此应用程序

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');
}

编辑器注意,它仍在运行。看看下面的打印屏幕,终止按钮(红色方形按钮)没有禁用,它记住我,当我运行一个http服务器,这个按钮不会禁用,直到我手动做。

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.

推荐答案

你正在听运行隔离。这是唯一的I / O应用程序,它不是一个web服务器。您可以关闭它的端口或只是杀死它:

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');
}

这篇关于为什么dart编辑器仍在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆