Skip to content

Implement native_synchronization within dcli/dcli/lib/src/process/process#234

Merged
bsutton merged 2 commits intoonepub-dev:masterfrom
open-runtime:master
Mar 20, 2024
Merged

Implement native_synchronization within dcli/dcli/lib/src/process/process#234
bsutton merged 2 commits intoonepub-dev:masterfrom
open-runtime:master

Conversation

@tsavo-at-pieces
Copy link
Contributor

  • Added native_synchronization package
  • Deprecated internal mailboxes.dart
  • Updated everything related to Mailboxes in the process directory within the internal dcli package
  • Tested ./dcli/test/src/process/process/synchronous_test.dart on MacOS (Intel & Apple Silicon), Windows, and Linux (Ubuntu)

tsavo-at-pieces and others added 2 commits March 20, 2024 15:55
Implement native_synchronization within dcli/dcli/lib/src/process/process
Copy link
Contributor Author

@tsavo-at-pieces tsavo-at-pieces left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gave things a double check and added permalink references to the relevant native_synchronization code ✅

import 'package:dcli_core/dcli_core.dart';

import 'process/process_sync.dart';
// import 'process/process_sync.dart';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seemed like an used import so I commented it out for now.

// we can handly binary data.
final List<List<int>> stdoutLines = <List<int>>[];
final List<List<int>> stderrLines = <List<int>>[];
int get sendAddress => send.rawAddress;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are no longer necessary.

/// check the data has been sent to the spawned process
/// before we return
final response = send.takeOneMessage();
final response = send.take();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// Starts an isolate that spawns the command.
void _startIsolate(ProcessSettings processSettings, ProcessChannel channel) {
unawaited(Isolate.spawn((mailboxAddrs) async {
unawaited(Isolate.spawn<List<Sendable<Mailbox>>>((mailboxes) async {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// This code runs in the isolate.
final sendMailbox = Mailbox.fromAddress(mailboxAddrs[0]);
final responseMailbox = Mailbox.fromAddress(mailboxAddrs[1]);
final sendMailbox = mailboxes.first.materialize();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// The tell the sender that we got their data and
/// sent it to stdin
sendMailbox.respond(Uint8List.fromList([ProcessChannel.RECEIVED]));
sendMailbox.put(Uint8List.fromList([ProcessChannel.RECEIVED]));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

channel.sendAddress,
channel.responseAddress,
]));
List<Sendable<Mailbox>>.from([
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

channel.send.asSendable,
channel.response.asSendable,
]),
debugName: 'ProcessInIsolate'));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can likely remove.

void listenStdout(void Function(List<int>) callback) {
_channel.listenStdout((data) {
print('processSync recieved data from channel');
// print('processSync recieved data from channel');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can comment back in if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants