yes
a dart package that constantly writes a string to an iosink
, simillarly to the unix yes
utility.
usage
// write to stdout for 5 seconds.
final controller = yes(stdout, message);
await future<void>.delayed(const duration(seconds: 5));
controller.cancel();
// write to a process's stdin for 5 seconds, and kill it.
// wait for the yes operation to complete (which occurs when stdin closes)
// before continuing.
final process = await process.start('cat', const []);
process.stdout.pipe(stdout);
final controller = yes(process.stdin);
future.delayed(const duration(seconds: 5))
.then((_) => process.kill(processsignal.sigint));
await controller.done;
print('done!');
a complete unix yes
utility download can be found in the example project.
performance notes
in order not to block the event loop, one write at most is performed each loop.
while this should be fine in most cases, output speed is severely bottlenecked.
this can be mitigated by repeating the given message several times:
yes(stdout, 'ynynyny');
additionally, by default, the given iosink
‘s flush
future is considered as possibly
synchronous, so an additional event loop loop is added to prevent the event loop from
blocking. if the flush
future is guaranteed to be asynchronous, then the additional
loop can be avoided.
yes(stdout, 'y', false);
license
mit license
copyright (c) 2021 hacker1024
permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "software"), to deal
in the software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the software, and to permit persons to whom the software is
furnished to do so, subject to the following conditions:
the above copyright notice and this permission notice shall be included in all
copies or substantial portions of the software.
the software is provided "as is", without warranty of any kind, express or
implied, including but not limited to the warranties of merchantability,
fitness for a particular purpose and noninfringement. in no event shall the
authors or copyright holders be liable for any claim, damages or other
liability, whether in an action of contract, tort or otherwise, arising from,
out of or in connection with the software or the use or other dealings in the
software.
Comments are closed.