From 5c384cab27113e74c998811d85f65700c0827060 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Mon, 16 May 2022 07:05:17 +0000 Subject: Implement timeouts for receive --- operators.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'operators.c') diff --git a/operators.c b/operators.c index 7e2520c..36dcd6a 100644 --- a/operators.c +++ b/operators.c @@ -157,12 +157,20 @@ opReceive(Datum *lefto, Array *left, Array *right) { if(lefto->tag != FunctionTag) throwerror(nil, ESyntax); - if(GetType(right) != AtypeInt) + if(GetType(right) != AtypeInt && GetType(right) != AtypeFloat) throwerror(nil, EDomain); - if(GetSize(right) != 1) + if(GetSize(right) != 1 && GetSize(right) != 0) throwerror(nil, ELength); USED(left); - return messagerecv(lefto->func, right->intdata[0]); + + int timeout = 0; + if(GetSize(right) == 0) + timeout = -1; + else if(GetType(right) == AtypeInt) + timeout = right->intdata[0]*1000; + else if(GetType(right) == AtypeFloat) + timeout = right->floatdata[0]*1000; + return messagerecv(lefto->func, timeout); } /* Dyadic operators */ -- cgit v1.2.3