File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,6 +33,18 @@ fn main() -> Result<(), Error> {
3333 .catch(e => reject(e));
3434 });
3535 }
36+
37+ export async function event_source_example() {
38+ return new Promise((accept, reject) => {
39+ var source = new EventSource('https://www.w3schools.com/html/demo_sse.php');
40+ source.addEventListener('message', (e) => {
41+ accept(e.data);
42+ });
43+ source.addEventListener('error', (e) => {
44+ reject(e)
45+ });
46+ });
47+ }
3648 " ,
3749 ) ;
3850
@@ -52,5 +64,11 @@ fn main() -> Result<(), Error> {
5264 let data: rustyscript:: serde_json:: Value =
5365 runtime. call_function ( Some ( & module_handle) , "fetch_example" , json_args ! ( ) ) ?;
5466 println ! ( "Got {:?} bytes" , data. to_string( ) . len( ) ) ;
67+
68+ // EventSource example
69+ let data: rustyscript:: serde_json:: Value =
70+ runtime. call_function ( Some ( & module_handle) , "event_source_example" , json_args ! ( ) ) ?;
71+ println ! ( "Got event: {}" , data) ;
72+
5573 Ok ( ( ) )
5674}
Original file line number Diff line number Diff line change @@ -7,11 +7,13 @@ import * as eventSource from "ext:deno_fetch/27_eventsource.js";
77
88Deno . core . setWasmStreamingCallback ( fetch . handleWasmStreaming ) ;
99
10- import { applyToGlobal , writeable , nonEnumerable } from 'ext:rustyscript/rustyscript.js' ;
10+ import { applyToGlobal , writeable , nonEnumerable } from 'ext:rustyscript/rustyscript.js' ;
11+
1112applyToGlobal ( {
1213 fetch : writeable ( fetch . fetch ) ,
1314 Request : nonEnumerable ( request . Request ) ,
1415 Response : nonEnumerable ( response . Response ) ,
1516 Headers : nonEnumerable ( headers . Headers ) ,
1617 FormData : nonEnumerable ( formData . FormData ) ,
18+ EventSource : nonEnumerable ( eventSource . EventSource )
1719} ) ;
You can’t perform that action at this time.
0 commit comments