deferred class STREAMSUSPENSION [G]

inherit
	STREAM [G]

feature 

	item: G is
		do
			if itemcacheflag = false then
				itemcache := forceitem;
				itemcacheflag := true
			end;
			Result := itemcache
		end;

	tail: STREAM [G] is
		do
			if not tailisvalue then
				if tailcache /= void then
					if tailcache.isnotsuspended then
						tailcache := tailcache.tovalue;
						tailisvalue := true
					end
				elseif not last then
					!STREAMTAIL [G]! tailcache.make (Current)
				end
			end;
			Result := tailcache
		end;

	last: BOOLEAN is
		deferred
		end;
	
feature {STREAM} 

	isnotsuspended: BOOLEAN;

	tovalue: STREAMVAL [G] is
		do
			if valuecache = void then
				!STREAMVAL [G]! valuecache.make (item, tail)
			end;
			Result := valuecache
		end;
	
feature {STREAMTAIL} 

	forcedtail: STREAM [G] is
		do
			if not isnotsuspended then
				tailcache := forcetail;
				isnotsuspended := true
			end;
			Result := tailcache
		end;
	
feature {NONE} 

	itemcache: G;

	itemcacheflag: BOOLEAN;

	tailcache: STREAM [G];

	valuecache: STREAMVAL [G];

	tailisvalue: BOOLEAN;

	forceitem: G is
		deferred
		end;

	forcetail: STREAM [G] is
		deferred
		end;
	
end -- class STREAMSUSPENSION