summaryrefslogtreecommitdiff
path: root/operators.c
diff options
context:
space:
mode:
authorPeter Mikkelsen <petermikkelsen10@gmail.com>2022-05-16 07:05:17 +0000
committerPeter Mikkelsen <petermikkelsen10@gmail.com>2022-05-16 07:05:17 +0000
commit5c384cab27113e74c998811d85f65700c0827060 (patch)
tree7d04516e7d09d4ffdbeb373874a08c5bf23619ba /operators.c
parentfd3f483368ec3c52e00260ae2941b6c0552473cf (diff)
Implement timeouts for receive
Diffstat (limited to 'operators.c')
-rw-r--r--operators.c14
1 files changed, 11 insertions, 3 deletions
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 */