Created
November 27, 2018 16:43
-
-
Save weskerfoot/9121c2e1cc2c1d5aaff65fd6e082bbf3 to your computer and use it in GitHub Desktop.
This file contains 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
#! /usr/bin/env racket | |
#lang racket | |
(define (read-avail from-port callback) | |
(define ready | |
(sync | |
(read-bytes-evt 1 from-port))) | |
(if (not (eof-object? ready)) | |
(begin | |
(callback ready) | |
(read-avail from-port callback)) | |
(callback #f))) | |
(define (execute-async to-port) | |
(define command (thread-receive)) | |
(displayln command to-port) | |
(flush-output to-port) | |
(execute-async to-port)) | |
;; you tell it the remote, and pass it a callback | |
;; the callback gets hooked into another thread that waits for output | |
;; the callback executes on any output | |
;; the output might be parsed into a standard format | |
(define (make-executor host callback) | |
(match-define (list from-remote | |
to-remote | |
pid | |
error-from-remote | |
control-remote) | |
(process (format "ssh -tt ~a" host))) | |
(thread | |
(lambda () (read-avail from-remote callback))) | |
(define | |
executor | |
(thread (lambda () (execute-async to-remote)))) | |
(lambda (command) | |
(thread-send executor command))) | |
(define exec | |
(make-executor | |
"linode" | |
(lambda (result) | |
(displayln "result for linode!") | |
(displayln result)))) | |
(exec "whoami") | |
(read) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment