properly detach listeners after each section

This commit is contained in:
Anton Dyudin 2018-03-09 14:36:26 -08:00
parent 42b3fe86c7
commit bf7bf86cb4
2 changed files with 11 additions and 7 deletions

View File

@ -1,4 +1,4 @@
require! <[ stream-snitch colors escape-string-regexp ]>
require! <[ stream stream-snitch colors escape-string-regexp ]>
pty = require \pty.js
export ERROR = /(ford: |\r\x1b\[K\/~)/
@ -12,6 +12,7 @@ export class Urbit
@last-output = Date.now()
@pty.on \data ~> @last-output = Date.now()
#
@reset-listeners!
process.on \exit ~> @pty.write '\04' # send EOF to gracefully checkpoint
#
note: (...args)-> console.log "\nnode:".blue, ...args
@ -24,12 +25,15 @@ export class Urbit
resolve @last-output
, 200
#
unpipe: ~> @pty.socket.unpipe!; @ # TODO separate "listeners" stream
reset-listeners: ~>
@pty.socket.unpipe @listeners
@pty.socket.pipe (@listeners = new stream.PassThrough)
@
every: (re, cb)~>
@pty.pipe (new stream-snitch re).on "match" cb
@listeners.pipe (new stream-snitch re).on "match" cb
expect: (re)~>
new Promise (resolve)~>
@pty.pipe (new stream-snitch re).once "match" resolve
@listeners.pipe (new stream-snitch re).once "match" resolve
expect-immediate: (re)->
Promise.race [
@expect re

View File

@ -11,7 +11,7 @@ Promise.resolve urbit
, do
<- urb.expect /dojo> / .then
<- urb.expect-echo "%dojo-booted" .then
urb.unpipe!
urb.reset-listeners!
]
.then (urb)->
urb.note "Testing compilation"
@ -28,7 +28,7 @@ Promise.resolve urbit
<- urb.expect-echo "%compilation-tested" .then
errs := Object.keys errs
if errs.length => throw Error "in #errs"
urb.unpipe!
urb.reset-listeners!
.then (urb)->
urb.note "Running /===/tests"
errs = "" #REVIEW stream reduce?
@ -38,7 +38,7 @@ Promise.resolve urbit
<- urb.line "+test, =defer |, =seed `@uvI`(shaz %reproducible)" .then
<- urb.expect-echo "%ran-tests" .then
if errs => throw Error errs
urb.unpipe!
urb.reset-listeners!
.then ->
urbit.exit 0
.catch (err)->