-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
124 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
namespace $ { | ||
export class $mol_service_channel extends $mol_object { | ||
protected channel = new MessageChannel() | ||
|
||
timeout() { return 20000 } | ||
|
||
out() { return this.channel.port2 } | ||
|
||
result() { return $mol_wire_sync(this).result_async() } | ||
|
||
result_async() { | ||
return new Promise<unknown>((resolve, reject) => { | ||
const channel = this.channel | ||
|
||
const handler = setTimeout( | ||
() => reject(new Error('Channel timeout', { cause: channel })), | ||
this.timeout() | ||
) | ||
|
||
this.destructor = () => { | ||
clearTimeout(handler) | ||
reject(new Error('Channel cancelled')) | ||
} | ||
|
||
channel.port1.onmessage = event => { | ||
clearTimeout(handler) | ||
const data = event.data | ||
const message = data?.error ?? (data?.result ? null : 'empty data') | ||
if (message) return reject(new Error(message, { cause: event })) | ||
|
||
resolve(event.data.result) | ||
} | ||
|
||
channel.port1.onmessageerror = event => { | ||
clearTimeout(handler) | ||
reject(new Error('Can\'t be deserialized: ' + event.data, { cause: event })) | ||
} | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
namespace $ { | ||
export class $mol_service_plugin extends $mol_object { | ||
export namespace $mol_service_plugin { | ||
let _ | ||
} | ||
|
||
export class $mol_service_plugin_base extends $mol_object { | ||
static install() { return null as unknown } | ||
static activate() { return null as unknown } | ||
static message_data(data: {}) { return null as unknown } | ||
|
||
static service() { return this.$.$mol_service_worker } | ||
static data(data: {}) { return null as unknown } | ||
} | ||
|
||
export class $mol_service_plugin_cache extends $mol_service_plugin { | ||
export class $mol_service_plugin_cache extends $mol_service_plugin_base { | ||
static blocked(request: Request) { return false } | ||
static modify(request: Request, waitUntil: (promise: Promise<unknown>) => void) { | ||
return null as null | Response | ||
} | ||
static modify(request: Request) { return null as null | Response } | ||
} | ||
|
||
export class $mol_service_plugin_notify extends $mol_service_plugin { | ||
export class $mol_service_plugin_notify extends $mol_service_plugin_base { | ||
static notification(e: unknown) { return null as unknown } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,31 @@ | ||
namespace $.$mol_service { | ||
let _ | ||
namespace $ { | ||
export class $mol_service extends $mol_object { | ||
static path() { return 'web.js' } | ||
|
||
static send_timeout() { return 20000 } | ||
|
||
@ $mol_action | ||
static send(data: {}) { return null as unknown } | ||
|
||
@ $mol_mem | ||
static prepare(next?: $mol_service_prepare_event) { | ||
return next ? next : null | ||
} | ||
|
||
@ $mol_mem | ||
static prepare_choise() { return $mol_wire_sync(this).choise_promise()?.outcome ?? null } | ||
|
||
static choise_promise() { return this.prepare()?.userChoise } | ||
|
||
static blocked_response() { | ||
return new Response( | ||
null, | ||
{ | ||
status: 418, | ||
statusText: 'Blocked' | ||
}, | ||
) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.