summaryrefslogtreecommitdiff
path: root/testdata/009_pub_sub.ts
blob: 3d33c820d265db4fd8f06979a30b037f87545dd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import * as deno from "deno";

deno.sub("echo", (ui8: Uint8Array) => {
  const str = String.fromCharCode.apply(null, ui8);
  console.log("Got message", str);
});

function str2ui8(str: string): Uint8Array {
  const ui8 = new Uint8Array(str.length);
  for (let i = 0; i < str.length; i++) {
    ui8[i] = str.charCodeAt(i);
  }
  return ui8;
}

console.log("Before deno.pub()");
deno.pub("echo", str2ui8("hello"));
console.log("After deno.pub()");