We can have on thread sleep at a time
This commit is contained in:
parent
5e1c5679e5
commit
dae2740e65
@ -6,7 +6,14 @@ def echo(msg: bytes) -> bytes:
|
|||||||
def log_bytes(data: bytes) -> None:
|
def log_bytes(data: bytes) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@imported('prelude')
|
||||||
|
def sleep(seconds: u32) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
@exported
|
@exported
|
||||||
def on_module_loaded() -> None:
|
def on_module_loaded() -> None:
|
||||||
log_bytes(b'Echo client starting up, calling server')
|
log_bytes(b'Echo client starting up, calling server')
|
||||||
|
sleep(8)
|
||||||
log_bytes(echo(b'Hello, world!'))
|
log_bytes(echo(b'Hello, world!'))
|
||||||
|
sleep(8)
|
||||||
|
log_bytes(echo(b'Bye, world!'))
|
||||||
|
|||||||
@ -6,6 +6,7 @@ path = "examples/echoclient.wasm"
|
|||||||
hash = "sha256@84cb22d12dfdd6b05cb906f6db83d59f473c9df85a33822f696344af2b92b502"
|
hash = "sha256@84cb22d12dfdd6b05cb906f6db83d59f473c9df85a33822f696344af2b92b502"
|
||||||
|
|
||||||
imports = [
|
imports = [
|
||||||
|
{ service = "prelude", method = "sleep", arg_types = ["u32"], return_type = "none"},
|
||||||
{ service = "echoserver", method = "echo", arg_types = ["bytes"], return_type = "bytes"},
|
{ service = "echoserver", method = "echo", arg_types = ["bytes"], return_type = "bytes"},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@ from typing import Any, Union
|
|||||||
|
|
||||||
from .valuetype import ValueType, none
|
from .valuetype import ValueType, none
|
||||||
|
|
||||||
ValueData = Union[None, bytes]
|
ValueData = Union[None, int, float, bytes]
|
||||||
|
|
||||||
|
|
||||||
class Value:
|
class Value:
|
||||||
|
|||||||
@ -19,11 +19,14 @@ class ValueType:
|
|||||||
return f'valuetype.{self.name}'
|
return f'valuetype.{self.name}'
|
||||||
|
|
||||||
|
|
||||||
|
u32 = ValueType('u32')
|
||||||
|
|
||||||
bytes = ValueType('bytes')
|
bytes = ValueType('bytes')
|
||||||
|
|
||||||
none = ValueType('none')
|
none = ValueType('none')
|
||||||
|
|
||||||
LOOKUP_TABLE: Dict[str, ValueType] = {
|
LOOKUP_TABLE: Dict[str, ValueType] = {
|
||||||
|
u32.name: u32,
|
||||||
bytes.name: bytes,
|
bytes.name: bytes,
|
||||||
none.name: none,
|
none.name: none,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -201,9 +201,9 @@ class LocalhostMethodCallRouter(MethodCallRouterInterface):
|
|||||||
|
|
||||||
|
|
||||||
def make_prelude() -> Service:
|
def make_prelude() -> Service:
|
||||||
methods: List[Method] = []
|
methods: List[Method] = [
|
||||||
|
Method('sleep', [valuetype.u32], valuetype.none),
|
||||||
methods.append(Method('log_bytes', [valuetype.bytes], valuetype.none))
|
]
|
||||||
|
|
||||||
return Service('prelude', ContainerMatch('__prelude__'), methods)
|
return Service('prelude', ContainerMatch('__prelude__'), methods)
|
||||||
|
|
||||||
|
|||||||
@ -63,6 +63,10 @@ class BaseRunner(RunnerInterface):
|
|||||||
assert val is None # type hint
|
assert val is None # type hint
|
||||||
return Value(value_type, None)
|
return Value(value_type, None)
|
||||||
|
|
||||||
|
if value_type is valuetype.u32:
|
||||||
|
assert isinstance(val, int) # type hint
|
||||||
|
return Value(value_type, val)
|
||||||
|
|
||||||
if value_type is valuetype.bytes:
|
if value_type is valuetype.bytes:
|
||||||
assert isinstance(val, int) # type hint
|
assert isinstance(val, int) # type hint
|
||||||
return Value(value_type, self.read_bytes(val))
|
return Value(value_type, self.read_bytes(val))
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
from phasmplatform.common.methodcall import MethodCall, MethodCallError
|
from phasmplatform.common.methodcall import MethodCall, MethodCallError
|
||||||
from phasmplatform.common.value import Value, NoneValue
|
from phasmplatform.common.value import Value, NoneValue
|
||||||
|
|
||||||
@ -14,4 +16,12 @@ class PreludeRunner(BaseRunner):
|
|||||||
self.container_log[0]('PreludeRunner loaded')
|
self.container_log[0]('PreludeRunner loaded')
|
||||||
return NoneValue
|
return NoneValue
|
||||||
|
|
||||||
|
if call.method.name == 'sleep':
|
||||||
|
# This will block this thread
|
||||||
|
# Which is has to do until we can get the async really working
|
||||||
|
seconds = call.args[0].data
|
||||||
|
assert isinstance(seconds, int) # type hint
|
||||||
|
time.sleep(seconds)
|
||||||
|
return NoneValue
|
||||||
|
|
||||||
raise NotImplementedError(call)
|
raise NotImplementedError(call)
|
||||||
|
|||||||
@ -152,6 +152,9 @@ def build_func_type(method: Method) -> wasmtime.FuncType:
|
|||||||
|
|
||||||
|
|
||||||
def build_wasm_type(value_type: ValueType) -> wasmtime.ValType:
|
def build_wasm_type(value_type: ValueType) -> wasmtime.ValType:
|
||||||
|
if value_type is valuetype.u32:
|
||||||
|
return wasmtime.ValType.i32() # Signed-ness is in the operands
|
||||||
|
|
||||||
if value_type is valuetype.bytes:
|
if value_type is valuetype.bytes:
|
||||||
return wasmtime.ValType.i32() # Bytes are passed as pointer
|
return wasmtime.ValType.i32() # Bytes are passed as pointer
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user