Namespace: SpawnDev.SpawnJS.JSObjects
Inherits: SpawnJSObject
Source: JSObjects/ReadableStreamDefaultController.cs
MDN Reference: ReadableStreamDefaultController on MDN
The ReadableStreamDefaultController interface of the Streams API represents a controller allowing control of a ReadableStream's state and internal queue. Default controllers are for streams that are not byte streams. https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultController
| Signature | Description |
|---|---|
ReadableStreamDefaultController(SpawnJSObjectReference _ref) |
Deserialization constructor |
| Method | Return Type | Description |
|---|---|---|
Close() |
void |
Closes the associated stream. |
Enqueue(object data) |
void |
Enqueues a given chunk in the associated stream. |
Error() |
void |
Causes any future interactions with the associated stream to error. |
Error(object error) |
void |
Causes any future interactions with the associated stream to error. |
SpawnDev.SpawnJS Mapping Note: The JavaScript examples below show the standard Web API usage. In SpawnDev.SpawnJS, the same API is available with C# conventions:
- Properties and methods use PascalCase (e.g.,
readyStatebecomesReadyState)- Events use ActionEvent with
+=/-=(e.g.,addEventListener("click", fn)becomesOnClick += handler)- Async methods return
Task<T>instead ofPromise<T>- Objects should be disposed with
usingstatements- Access via
JS.Get<ReadableStreamDefaultController>(...)or constructornew ReadableStreamDefaultController(...)
let interval;
const stream = new ReadableStream({
start(controller) {
interval = setInterval(() => {
let string = randomChars();
// Add the string to the stream
controller.enqueue(string);
// show it on the screen
let listItem = document.createElement("li");
listItem.textContent = string;
list1.appendChild(listItem);
}, 1000);
button.addEventListener("click", () => {
clearInterval(interval);
fetchStream();
controller.close();
});
},
pull(controller) {
// We don't really need a pull in this example
},
cancel() {
// This is called if the reader cancels,
// so we should stop generating strings
clearInterval(interval);
},
});