Created
          December 6, 2014 21:01 
        
      - 
      
- 
        Save StrykerKKD/286cf2d51e436a347608 to your computer and use it in GitHub Desktop. 
    Dart: Isolate example in a funny way
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | import 'dart:isolate'; | |
| //This is the worker | |
| void worker(SendPort request) { | |
| ReceivePort response = new ReceivePort(); | |
| request.send(response.sendPort); | |
| response.listen((message){ | |
| print("Boss: $message"); | |
| request.send("...."); | |
| response.close(); | |
| }); | |
| } | |
| //This is the boss | |
| main() { | |
| ReceivePort response = new ReceivePort(); | |
| SendPort request; | |
| Isolate.spawn(worker, response.sendPort); | |
| response.listen((message){ | |
| if(message is SendPort) { | |
| request = message; | |
| request.send("Ummmm Yeeeahh if you could get this TPS report done today. That'd be great."); | |
| } else { | |
| print("Worker: $message"); | |
| response.close(); | |
| } | |
| }); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment