summaryrefslogtreecommitdiffstats
path: root/dom/streams/test/xpcshell/dom_stream_prototype_test.js
blob: e3c59c675f722a73b032878b43192dbc385f9942 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"use strict";

var log = [];
const stream = new ReadableStream({
  start() {
    log.push("started");
  },
  pull(controller) {
    log.push("pulled");
    controller.enqueue("hi from pull");
  },
  cancel() {
    log.push("cancelled");
  },
});

print(log); // Currently prints "started"!

add_task(async function helper() {
  var reader = stream.getReader();
  var readPromise = reader.read();
  readPromise.then(x => print(`Printing promise result ${x}, log ${log}`));
  print(log);

  var x = await readPromise;
  print(`Promise result ${x} ${x.value}`);
  Assert.equal(x.value, "hi from pull");
  Assert.ok(true);
});