@@ -801,6 +801,29 @@ VM* idris_checkMessagesFrom(VM* vm, VM* sender) {
801801 return 0;
802802}
803803
804+VM* idris_checkMessagesTimeout(VM* vm, int delay) {
805+ VM* sender = idris_checkMessagesFrom(vm, NULL);
806+ if (sender != NULL) {
807+ return sender;
808+ }
809+
810+ struct timespec timeout;
811+ int status;
812+
813+ // Wait either for a timeout or until we get a signal that a message
814+ // has arrived.
815+ pthread_mutex_lock(&vm->inbox_block);
816+ timeout.tv_sec = time (NULL) + delay;
817+ timeout.tv_nsec = 0;
818+ status = pthread_cond_timedwait(&vm->inbox_waiting, &vm->inbox_block,
819+ &timeout);
820+ (void)(status); //don't emit 'unused' warning
821+ pthread_mutex_unlock(&vm->inbox_block);
822+
823+ return idris_checkMessagesFrom(vm, NULL);
824+}
825+
826+
804827Msg* idris_getMessageFrom(VM* vm, VM* sender) {
805828 Msg* msg;
806829