// Copyright (c) 1996-2002 Brian D. Carlstrom

package bdc.scheme.procedure;

import bdc.scheme.SchemeException;
import bdc.scheme.Stack;
import bdc.scheme.exception.ArgumentTypeException;
import bdc.scheme.exception.PrimitiveException;
import bdc.scheme.expression.Procedure1;
import bdc.util.Constants;

/**
    Primitive for Process.waitFor
*/
public class Wait extends Procedure1
{
    public Object apply1 (Stack stack) throws SchemeException
    {
        Object o1 = stack.array[stack.inUse-1];
        if (!(o1 instanceof Process)) {
            throw new ArgumentTypeException(this, "Process", o1);
        }
        try {
            return Constants.getInteger(((Process)o1).waitFor());
        }
        catch (InterruptedException e) {
            throw new PrimitiveException(e);
        }
    }
}
