-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't clear context.meta on finalize, production needs that
- Loading branch information
Showing
4 changed files
with
56 additions
and
54 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,65 @@ | ||
export default function streamsInit(ivm, dispatcher){ | ||
import { logger } from '../logger' | ||
|
||
export default function streamsInit(ivm, dispatcher) { | ||
return { | ||
refToStream(ref){ | ||
refToStream(ref) { | ||
let closed = false | ||
let resumed = false | ||
const r = new ReadableStream({ | ||
start(controller) { | ||
dispatcher.dispatch("subscribeProxyStream", | ||
ref, | ||
new ivm.Reference((name, ...args) => { | ||
new ivm.Reference(function (name, ...args) { | ||
logger.debug("GOT EVENT:", name) | ||
if (name === "close" || name === "end") { | ||
if (!closed) { | ||
closed = true | ||
controller.close() | ||
} | ||
} else if (name === "error") { | ||
controller.error(new Error(args[0])) | ||
/*} else if (name === "data") { | ||
controller.enqueue(args[0]) | ||
if(controller.desiredSize <= 0 && resumed){ | ||
resumed = false | ||
dispatcher.dispatch("controlProxyStream", "pause", ref) | ||
}//*/ //not using events, calling read manually with pull for now | ||
/*} else if (name === "data") { | ||
controller.enqueue(args[0]) | ||
if(controller.desiredSize <= 0 && resumed){ | ||
resumed = false | ||
dispatcher.dispatch("controlProxyStream", "pause", ref) | ||
}//*/ //not using events, calling read manually with pull for now | ||
} else | ||
logger.debug("unhandled event", name) | ||
}) | ||
) | ||
}, | ||
pull(controller){ | ||
pull(controller) { | ||
//if(r.locked && !resumed){ | ||
if(closed){ | ||
return Promise.resolve(null) | ||
} | ||
return new Promise((resolve, reject) => { | ||
resumed = true | ||
dispatcher.dispatch("readProxyStream", ref, new ivm.Reference((err, data, tainted) => { | ||
if(err){ | ||
controller.error(new Error(err)) | ||
reject(err) | ||
return | ||
} | ||
// if data is blank the stream will keep pulling | ||
// readProxyStream tries a few times to minimize bridge calls | ||
controller.enqueue(data) | ||
if(data && r._ref && tainted){ | ||
// once underlying ref is tainted, we can't pass it around anymore | ||
// but we can still use it internally | ||
r._ref = undefined | ||
} | ||
resolve() | ||
})) | ||
if (closed) { | ||
return Promise.resolve(null) | ||
} | ||
return new Promise((resolve, reject) => { | ||
dispatcher.dispatch("readProxyStream", ref, new ivm.Reference((err, data, tainted) => { | ||
if (err) { | ||
controller.error(new Error(err)) | ||
reject(err) | ||
return | ||
} | ||
// if data is blank the stream will keep pulling | ||
// readProxyStream tries a few times to minimize bridge calls | ||
controller.enqueue(data) | ||
if (data && r._ref && tainted) { | ||
// once underlying ref is tainted, we can't pass it around anymore | ||
// but we can still use it internally | ||
r._ref = undefined | ||
} | ||
resolve() | ||
})) | ||
|
||
}) | ||
}) | ||
//} | ||
}, | ||
cancel() { | ||
logger.debug("readable stream was cancelled") | ||
} | ||
}) | ||
r._ref = ref | ||
return r | ||
return r | ||
} | ||
} | ||
} |