1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-30 16:40:57 -05:00
denoland-deno/testdata/009_pub_sub.ts

19 lines
446 B
TypeScript
Raw Normal View History

2018-05-23 16:45:01 -04:00
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()");